[英]How can I exclude script tag from Cypress run?
I have a script tag that has to be active in production but can't be called when Cypress is running.我有一个脚本标签,它必须在生产中处于活动状态,但在 Cypress 运行时无法调用。 As we run Cypress against our prod build as well, I can't use process.env.NODE_ENV
to exclude it.当我们也针对我们的产品构建运行 Cypress 时,我无法使用process.env.NODE_ENV
来排除它。
Is there any way to exclude a piece of code when Cypress is running?有什么办法可以在Cypress运行的时候排除一段代码吗?
As long as you can identify the the script exactly, you can modify the page source before it loads with cy.intercept()
只要你能准确识别脚本,你就可以在页面源代码加载之前修改它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.