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.

Visiting a cross origin page with a `cy.origin` command with no cy commands may cause subsequent tests to hang.

See original GitHub issue

Current behavior

Since we no longer wait for stability before ending a test test we may now end up in a race condition where an unload event initiated in a previous test will occur in a subsequent test, setting stability to false. If that load event happens for a cross origin page the test will hang, forever since stability won’t be set back to true.

It was assumed that setting the iframes src to the about:blank page would cancel any current load events happening within the iframe, but the opposite appears to be true, if the iframe is currently loading

Desired behavior

The second test should not hang based on commands run in the first test.

I believe we have to options to fix this, one more extreme than the other.

  1. Wait for stability prior to loading the about blank page in sessions/index. To achieve stability here, we will have know which spec bridge to continue to listen too and persist that state between tests. Currently this is handled within tests by the latestActiveOriginPolicy state, but that is cleared between tests. See relevant event-manager lines

  2. Revert the change that allows us to proceed in the event manager regardless of stability and instead allow cy.visit to successfully load cross-origin pages. This requires more investigation, but would have the dual effects of making it less confusing to visit pages (you could visit a cross origin page prior to entering a cy.origin block and allow us to remove code around syncing stability as you could not exit the command queue without being stable. Any any commands run after a visit would have to run against the correct origin. The downside of this approach would be that again, we’d be waiting on stability before exiting mocha blocks (but we’ve seen what not waiting can do) and we’d have to error in cy.visits on load functions if someone attempts to run them against a cross origin url. On loads would also have to be setup prior to visiting.

Test code to reproduce

The following test can be used to reproduce this issue in the ‘driver’ package of the cypress repo. This is most easily reproduced on firefox, but has also been observed on chrome.

// The first test executes fast enough that the onunload event occurs at the beginning of the second test.
it.only('runs', () => {
  cy.visit('/fixtures/primary-origin.html')
  cy.get('a[data-cy="cross-origin-secondary-link"]').click()
  cy.origin('http://foobar.com:3500', () => {
    expect(true).to.equal(true)
  })
})

it.only('it hangs', () => {
  cy.log('you will not see me')
})

Cypress Version

9.6.0

Other

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mjhenkescommented, Sep 8, 2022

This will be fixed by #23297

0reactions
cypress-bot[bot]commented, Sep 27, 2022

Released in 10.9.0.

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

origin - Cypress Documentation
Visit multiple domains of different origin in a single test. In normal use, a single Cypress test may only run commands in a...
Read more >
Fixing Cypress cross-origin errors - Reflect.run
A step-by-step guide for avoiding cross-origin errors in Cypress tests via the cy.origin() and cy.session() commands introduced in Cypress ...
Read more >
Multi-Domain (Origin) Testing in Cypress - DEV Community ‍ ‍
Let's take a deep dive into how to use cy.origin in the real world. Let's create a test that visits our site locally...
Read more >
How to run Cypress test cases across multiple domains
Using cy.origin() command, you can easily switch between origins to seamlessly test syndicated authentication, cross-site CMS workflows, and much more.
Read more >
Cypress 9.6.0 introduces cy.origin for testing multi-domain ...
Before version 9.6.0, if we tried to access a different domain other than the root domain from UI, Cypress would throw “cross 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