仅在一次测试中禁用赛普拉斯的Web安全性 [英] Disable web security in Cypress just for one test
问题描述
阅读赛普拉斯的
在此处查看文档 https://docs.cypress.io/guides/references/configuration.html#Cypress-config
更新:
在我看到DurkoMatKo的评论之后,我设法找到一个URL来测试此"chromeWebSecurity"选项.它没有按预期工作.我认为在运行相同的浏览器期间更改此配置可能不起作用,因为这更像是一个浏览器功能,它将决定何时启动.在这种情况下,我想到的只是以不同的配置运行赛普拉斯.
赛普拉斯文档此处显示了明确的操作步骤这.希望这可以帮助.
After reading the Cypress documentation on web security and when to disable it, I've decided I indeed need to do it. Is there a way to disable this just for one particular test/test suite? I'm using version 3.4.1 and this config is being set in cypress.json
- therefore it's global for all tests.
Is there a way to disable web security just for one test? Thanks!
Original answer:
Does this work for you?
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'));
});
});
The config is changed as you can see from the console log.
See document here https://docs.cypress.io/guides/references/configuration.html#Cypress-config
Updates:
After I saw DurkoMatKo's comment I managed to find an URL to test this 'chromeWebSecurity' option. It did not work as expected. I think changing this config might not work during running the same browser as this is more like a browser feature which will determine when start. In this case what I can think of is only to run Cypress with different configurations.
The cypress doc here shows clear steps to do this. hope this helps.
这篇关于仅在一次测试中禁用赛普拉斯的Web安全性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!