我正在学习Cypress,为此我使用了这个网站:automationpractice.com。
场景:注册。在sign up表单中,应用程序验证电子邮件(1),然后将其重定向到另一个表单(2)。


在此流程中,Cypress抛出以下错误:
CypressError: Cypress detected a cross origin error happened on page load:
> Blocked a frame with origin "http://automationpractice.com" from accessing a cross-origin frame.
Before the page load, you were bound to the origin policy:
> http://automationpractice.com
A cross origin error happens when your application navigates to a new URL which does not match the origin policy above.我不知道为什么会出现这个错误,form 2不在iframe中,是相同的url。有人知道吗?
为了解决这个问题,在cypress.json中添加了"chromeWebSecurity": false。然后,在单击“注册帐户”按钮后,第二个表单被加载到cypress视区中,但cypress将url更改为http://automationpractice.com/__/#account-creation,因此表单消失,字段也不存在。
我想避免柏树更改url就可以解决这个问题。但是,我在文档中找不到任何相关的东西。有人知道怎么解决这个问题吗?
// test.spec.js
context('Cypress Training', () => {
beforeEach(() => {
cy.visit('http://automationpractice.com/index.php?controller=authentication&back=my-account')
})
it('Register user', () => {
const email = 'test@test.test.test';
// form 1
cy.get('#email_create').type(email)
cy.get('#SubmitCreate').click();
// form 2
cy.wait(3000)
cy.get('#id_gender1').click()
})
})发布于 2020-06-23 16:11:02
解决方案在这里:https://github.com/cypress-io/cypress/issues/7402您必须将cypress升级到版本4.6.0并添加
{
"experimentalSourceRewriting": true
}转到cypress.json
https://stackoverflow.com/questions/61977401
复制相似问题