阅读了Cypress有关Web安全和何时禁用它的文档后,我决定确实需要这样做。是否有一种方法可以仅针对一个特定的测试/测试套件禁用此功能? 我正在使用版本3.4.1,并且此配置在
cypress.json
中设置-因此对于所有测试都是全局的。
是否有一种方法可以仅禁用一个测试的Web安全性?谢谢!
cypress.json
中设置-因此对于所有测试都是全局的。
是否有一种方法可以仅禁用一个测试的Web安全性?谢谢!
原始回答:
这对你有用吗?
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的评论后,我设法找到了一个测试“chromeWebSecurity”选项的URL。它没有像预期的那样工作。 我认为更改此配置可能无法在运行相同的浏览器时起作用,因为这更像是一种浏览器功能,将确定何时启动。 在这种情况下,我所能想到的就是使用不同的配置运行Cypress。
Cypress文档here 显示了清晰的步骤。 希望这有所帮助。
chromeWebSecurity
设置为false
。//cypress.json
{
"chromeWebSecurity": false
}
然后我所做的是在将其分配给Cypress.config
之前,使用true
//cypress/integration/testing.spec.js
context('DEMO-01', () => {
beforeEach(function () {
Cypress.config('chromeWebSecurity', true);
});
describe('CP001 - start dasboard', () => {
it('P01: open dashboard', () => {
cy.visit(URL);
});
});
});
cypress.json
禁用它,那么我就不会再收到错误了。 - DurkoMatkocypress.json
文件为{"chromeWebSecurity": false}
,这样在我的测试中才能使用Cypress.config('chromeWebSecurity',true);
将该设置更改为“true”。 - Jasp402