看完 Cypress documentation关于网络安全以及何时禁用它,我决定我确实需要这样做。有没有办法只为一个特定的测试/测试套件禁用它?我正在使用 版本 3.4.1 并且这个配置被设置在 cypress.json
- 因此它对所有测试都是全局的。
有没有一种方法可以仅针对一次测试禁用网络安全?谢谢!
最佳答案
原答案:
这对你有用吗?
describe("test the config json", function () {
it("use web security false here", function () {
Cypress.config('chromeWebSecurity',false);
cy.visit("https://www.google.com");
console.log(Cypress.config('chromeWebSecurity'));
});
it("use web security true here", function () {
Cypress.config('chromeWebSecurity',true);
cy.visit("https://www.google.com");
console.log(Cypress.config('chromeWebSecurity'));
});
});
正如您从控制台日志中看到的那样,配置已更改。
在此处查看文档 https://docs.cypress.io/guides/references/configuration.html#Cypress-config
更新:
在我看到 DurkoMatKo 的 comment我设法找到了一个 URL 来测试这个“chromeWebSecurity”选项。它没有按预期工作。
我认为在运行相同的浏览器期间更改此配置可能不起作用,因为这更像是一种浏览器功能,它将确定何时启动。
在这种情况下,我能想到的只是运行具有不同配置的 Cypress。
柏树文档 here显示了执行此操作的明确步骤。
希望这可以帮助。
关于automated-tests - 在 Cypress 中禁用 Web 安全仅用于一项测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58048082/