[英]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.