Skip to content

Cross-origin error happening on same domain after click event adds same page anchor #7402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
felipocorrea90 opened this issue May 18, 2020 · 8 comments · Fixed by #7418
Closed
Assignees

Comments

@felipocorrea90
Copy link

felipocorrea90 commented May 18, 2020

Current behavior:

Is not possible to continue with the test execution after getting error message:

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

This is happening when I click the create account button with a valid email (non-registered) in the email address field after visiting the site http://automationpractice.com/index.php?controller=authentication&back=my-account.

This event is not redirecting user to any new domain, actually it doesn't seem any redirection is made instead it looks like a page anchor from the same page is added to the url, loading new content in the same page and showing/hiding a few elements from the page layout.

If chromeWebSecurity: false is added to the the cypress.json file the issue continues. No error message is displayed but instead after the same event is triggered a blank page is loaded instead blocking the test entirely.

Desired behavior:

Cypress should be able to continue with the following step without showing the cross-origin error for this particular case.

Test code to reproduce

  1. Set up a new cypress project
  2. Add a new javascript file with any desired name to the integration folder, with the following code:
describe('Create Account', () => {
    it('Visit Store Website', () => {
        cy.visit('http://automationpractice.com/index.php?controller=authentication&back=my-account')
    })

    it('Add Email to create a new account', () => {
        cy.xpath('//input[@id="email_create"]').type('faketest_1@faketestexample.com')
        cy.xpath('//form[@id="create-account_form"]').submit()
    })

    it('Add personal information', () => {
        cy.get('.uniform-id_gender1').click()
        cy.get('.customer_firstname').type('First')
        cy.get('.customer_lastname').type('Last')
        cy.get('.passwd').type('whatever123')
        cy.get('.days').select('2')
        cy.get('.months').select('10')
        cy.get('.years').select('1985')
    })
})
  1. Run the test from the cypress UI runner npx cypress open
  2. Noticed the described issue

Versions

  • node version 12.16.3
  • npm version 6.14.4
"devDependencies": {
    "cypress": "^4.5.0",
    "cypress-xpath": "^1.4.0"
  }

Attachments

Screen Shot 2020-05-18 at 2 07 26 PM

@jennifer-shehane
Copy link
Member

I can recreate this with the code below. I tried the experimentalSourceRewriting config in our upcoming 4.6.0 release and that made no different to the result.

it('visit', () => {
  cy.visit('http://automationpractice.com/index.php?controller=authentication&back=my-account')
  cy.get('#email_create').type('faketest_1@faketestexample.com')
  cy.get('#create-account_form').submit()
  cy.get('.uniform-id_gender1').click()
})

Screen Shot 2020-05-19 at 5 35 44 PM

@cypress-bot cypress-bot bot added the stage: needs investigating Someone from Cypress needs to look at this label May 19, 2020
@jennifer-shehane
Copy link
Member

jennifer-shehane commented May 19, 2020

This is due to calling document.location = '#account-creation' on form submit. I can recreate this with the code below:

it('visit', () => {
  cy.visit('https://example.cypress.io')
  cy.document().then((doc) => {
    doc.location = '#account-creation'
  })
})

Added the hash specifically seems to render Cypress within itself.

Screen Shot 2020-05-19 at 8 42 19 PM

Setting a normal string to doc.location causes the route to reroute to _/ in the AUT

it('visit', () => {
  cy.visit('https://example.cypress.io')
  cy.document().then((doc) => {
    doc.location = 'account-creation'
  })
})

Screen Shot 2020-05-19 at 8 44 43 PM

@cypress-bot cypress-bot bot added stage: work in progress and removed stage: needs investigating Someone from Cypress needs to look at this labels May 19, 2020
@flotwig
Copy link
Contributor

flotwig commented May 19, 2020

Missed document.location in the original AST rewriting PR, have a PR open for it now: #7418

@jennifer-shehane however, #7418 won't fix the examples you've posted, as it doesn't rewrite test code, only AUT code

@flotwig flotwig self-assigned this May 19, 2020
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels May 19, 2020
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels May 19, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 19, 2020

The code for this is done in cypress-io/cypress#7418, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 20, 2020

Released in 4.6.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v4.6.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 20, 2020
@flotwig
Copy link
Contributor

flotwig commented May 20, 2020

This fix is available starting in 4.6.0 as an experiment which you can access by setting this config option in your cypress.json or elsewhere:

{
	"experimentalSourceRewriting": true
}

The fix is experimental, so there may be some situations where the this is not fixed.

If you're still this issue while setting the experimentalSourceRewriting to true in 4.6.0 - open a new issue with a reproducible example + screenshots, etc - filling out our issue template.

@cypress-io cypress-io unlocked this conversation May 20, 2020
@shevara84
Copy link

Can we set this config option in one spec file and how?

@jennifer-shehane
Copy link
Member

@shevara84 You can see any config option via Cypress.config()

it('test', () => {
  console.log(Cypress.config('experimentalSourceRewriting'))
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants