首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cypress更改URL会破坏应用程序

Cypress更改URL会破坏应用程序
EN

Stack Overflow用户
提问于 2020-05-24 03:15:15
回答 1查看 1.6K关注 0票数 1

我正在学习Cypress,为此我使用了这个网站:automationpractice.com

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

在此流程中,Cypress抛出以下错误:

代码语言:javascript
复制
  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就可以解决这个问题。但是,我在文档中找不到任何相关的东西。有人知道怎么解决这个问题吗?

代码语言:javascript
复制
// 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()
  })
})
EN

回答 1

Stack Overflow用户

发布于 2020-06-23 16:11:02

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

代码语言:javascript
复制
{
    "experimentalSourceRewriting": true
}

转到cypress.json

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61977401

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档