Skip to content

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

Closed
@mjhenkes

Description

@mjhenkes

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

Metadata

Metadata

Assignees

Labels

topic: cy.originProblems or enhancements related to cy.origin commandtype: bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions