question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
flotwigcommented, May 21, 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.

0reactions
jennifer-shehanecommented, Aug 18, 2020

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

it('test', () => {
  console.log(Cypress.config('experimentalSourceRewriting'))
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

CORS error on same domain? - Stack Overflow
As an addendum to this answer, note that 'Access-Control-Allow-Origin: https://example.com' is NOT equivalent to 'Access-Control-Allow-Origin: ...
Read more >
Same-origin policy - Web security | MDN
The same-origin policy is a critical security mechanism that restricts how a document or script loaded by one origin can interact with a ......
Read more >
Fixing Common Problems with CORS and JavaScript
Tutorial: This post walks through troubleshooting and fixing common problems associated with calling REST APIs from JavaScript.
Read more >
Enabling CORS for a REST API resource - Amazon API Gateway
This doesn't always work, and sometimes you need to manually modify the integration response to properly enable CORS. Usually this just means manually...
Read more >
origin - Cypress Documentation
Visit multiple domains of different origin in a single test. ... with a cross-origin page outside of the cy.origin block, due to 'same-origin'...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found