javascript - 赛普拉斯更改 URL 并破坏应用程序
问题描述
我正在学习赛普拉斯,为此我正在使用这个网站: automationpractice.com。
场景:注册。在注册表单中,应用程序验证电子邮件 (1),然后将其重定向到另一个表单 (2)。
在此流程中,赛普拉斯抛出以下错误:
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.
我不知道为什么会出现这个错误,表单 2 不在 iframe 中,是相同的 url。有谁知道?
试图修复它,"chromeWebSecurity": false
已添加到 cypress.json。然后,单击“注册帐户”按钮后,第二个表单在 cypress 视口中加载,但 cypress 将 url 更改为http://automationpractice.com/__/#account-creation
,因此表单消失并且字段未定位。
我想避免那个柏树改变网址我可以解决这个问题。但是,我在文档中找不到任何相关内容。任何人都知道如何解决它?
// 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()
})
})
解决方案
解决方案在这里:https ://github.com/cypress-io/cypress/issues/7402 您必须将 cypress 升级到 4.6.0 版本并添加
{
"experimentalSourceRewriting": true
}
到 cypress.json
推荐阅读
- python - 如何在多处理池中正确保存字典
- python - subprocess.Popen 返回“shell-init:检索当前目录时出错”
- c# - 如何根据用户输入链接方法?
- sql - 将完全相同列上的两个查询连接到一个结果表中
- firebase - 为什么 RxJava Completable 发射器中的 Firebase 任务不执行?
- r - 从 for 循环打印到新的数据帧
- python - 堆叠 Sprite 时如何更改透视角度?
- python - 将登录页面后面的 url 中的 csv 加载到 pandas 数据框中
- amazon-web-services - 如何根据部署的存储库为特定 Lambda 添加设置?
- c - AT指令和设备厂商的C API有什么关系?