首页 > 解决方案 > 赛普拉斯更改 URL 并破坏应用程序

问题描述

我正在学习赛普拉斯,为此我正在使用这个网站: automationpractice.com

场景:注册。在注册表单中,应用程序验证电子邮件 (1),然后将其重定向到另一个表单 (2)。

表格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()
  })
})

标签: javascriptautomationcypress

解决方案


解决方案在这里:https ://github.com/cypress-io/cypress/issues/7402 您必须将 cypress 升级到 4.6.0 版本并添加

{
    "experimentalSourceRewriting": true
}

到 cypress.json


推荐阅读