fix: commands not chained off of cy.get()
or queries properly error when cy.origin()
is not used and the AUT has navigated away from the primary origin
#30858
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Additional details
While performing the Cypress 14 bug hunt, @jennifer-shehane ran into an issue where this test was failing:
This has to due with the AUT navigating away from
ca.yahoo.com
toca.news.yahoo.com
, which before worked OK since we would inject document domain and Cypress could still communicate with the subdomain of the navigated AUT, even though the frame is in a cross-origin (same site) context. Now that we do not inject document domain be default,scrollTo
was trying to be run in a cross-origin (same-site) context, which would fail. When Cypress attempts to access parts of the error, it is unable to due to the frame being in a cross-origin context, which throws theCan't set property message of which only has a getter
error.This is no unique to the
cy.scrollTo()
command. Thecy.window()
,cy.document()
,cy.title()
,cy.url()
,cy.location()
,cy.hash()
,cy.go()
, andcy.reload()
will throw a similar error in this situation, or return erroneous values as the commands cannot access the AUT. This commands are exceptions because they do not chain off a queryable to run, like.get()
, which checks to make sure the command is being run on the correct origin.To fix this test, the test needs to be:
However, the
Can't set property message of which only has a getter
should not occur in the first place and the user should be prompted on how to fix the issue. To fix this, Cypress should error when the above commands are run when the AUT has navigated away from the primary origin to prompt the user to fix where the command is being run. This gives the user context that they needcy.origin()
to run the command correctly.Steps to test
Either run the sample test with the published binary (only linux built on this PR so if testing on a different machine check out the code and run in global mode against a project with this test) or remove that added code and run the regression tests in
actions.cy.ts
to see the commands are allowed to run outside the origin context, which is incorrect.How has the user experience changed?
Now the
scrollTo
in our described test works correctly.Before
After
PR Tasks
cypress-documentation
?type definitions
?