Dur*_*tko 8 automated-tests end-to-end browser-testing cypress
在阅读了有关 Web 安全的 Cypress文档以及何时禁用它之后,我决定我确实需要这样做。有没有办法只为一个特定的测试/测试套件禁用它?我使用的是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'));
});
});
Run Code Online (Sandbox Code Playgroud)
请参阅此处的文档https://docs.cypress.io/guides/references/configuration.html#Cypress-config
更新:
在看到 DurkoMatKo 的评论后,我设法找到一个 URL 来测试这个“chromeWebSecurity”选项。它没有按预期工作。我认为在运行同一浏览器期间更改此配置可能不起作用,因为这更像是一个浏览器功能,它将确定何时启动。在这种情况下,我能想到的只是以不同的配置运行 Cypress。
此处的cypress 文档显示了执行此操作的明确步骤。希望这可以帮助。