[英]How to use the "excludeSpecPattern" in Cypress together with a plugin to exclude from the cypress run one specific test file
[英]How can I exclude script tag from Cypress run?
我有一個腳本標簽,它必須在生產中處於活動狀態,但在 Cypress 運行時無法調用。 當我們也針對我們的產品構建運行 Cypress 時,我無法使用process.env.NODE_ENV
來排除它。
有什么辦法可以在Cypress運行的時候排除一段代碼嗎?
只要你能准確識別腳本,你就可以在頁面源代碼加載之前修改它cy.intercept()
cy.intercept(url, (req) => {
req.continue((res) => {
const scriptToRemove = '<script something-that-defines-the-script></script>'
res.body = res.body.replace(scriptToRemove, '')
})
}).as('page')
cy.visit(url)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.