Waiting for request with cy.wait when alias name matches tag name breakes cy.get command (interception becomes subject)
See original GitHub issueCurrent behavior
I created repository with reproduction https://github.com/shwarcu/cypress-alias-bug-repro
When few conditions are met, cy.get
command is returning wrong subject (intercepted request instead of DOM element).
It behaves like cy.get('@aliasname')
instead looking for an actual element. Here are conditions:
- alias has the same name as element we lookup (in reproduction I used
video
alias name and element) - request is intercepted
- request is awaited with
cy.wait
Example test that fails
it('fails when using get command after previously waiting for alias with the same name', () => {
cy.intercept(DEFAULT_VIDEO_URL, (request) => {
request.redirect(OTHER_VIDEO_URL);
}).as('video');
cy.visit('');
cy.wait('@video');
cy.get('video').should('have.attr', 'src'); // here subject is not video element, but interception object
});
Desired behavior
cy.get('video')
should not behave like cy.get('@video')
. It should yield video element.
Test code to reproduce
https://github.com/shwarcu/cypress-alias-bug-repro
Cypress Version
11.1.0
Node version
v16.13.0
Operating System
MacOS 13.0.1 / Manjaro GNOME 43.1
Debug Logs
No response
Other
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
wait - Cypress Documentation
When used with an alias, cy.wait() goes through two separate "waiting" periods. The first period waits for a matching request to leave the...
Read more >Waiting for request with cy.wait when alias name matches tag ...
Waiting for request with cy.wait when alias name matches tag name breakes cy.get command (interception becomes subject) #1491. Sign in to view logs....
Read more >Cypress cy.intercept Problems - Gleb Bahmutov
The command cy.intercept can match requests using a substring, ... In that case the first cy.wait(alias) "uses up" the intercept's response.
Read more >How to wait for a request to finish before moving on with Cypress
In the first line inside of the beforeEach function callback, I use cy.intercept() to intercept an HTTP request of type GET for a...
Read more >Cypress - The Blue Book - GitHub Pages
Cypress automatically waits for commands and assertions before moving on. ... the subject yielded from the cy.get() command, which will be a DOM...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Interesting, and very unusual - thank you for the repro!
This appears to be fixed in Cypress 12.0.0, which should be coming out later this week. You can try it out with the pre-release binaries if you like (https://github.com/cypress-io/cypress/commit/2552bdda9c8d8a30fa4c570f561f619ccb1cb8b3 is the latest as of this writing).
There appears to be some additional conditions to trigger the bug. This test:
passes in Cy 11.1.0 -
.get('div')
is working as expected. I’m not going to dive too deep into it, since the issue seems to be resolved in Cy12 already.I’m going to close this, but please feel free to ping me or comment here again if you’re still seeing issues in Cy12. I’m the one that rewrote our aliasing logic recently, so if there are problems I always want to hear about them!
Apologies @shwarcu. I think I completely skipped over your link to your reproduction and consequently was trying to set up something myself. I can confirm that your reproduction at https://github.com/shwarcu/cypress-alias-bug-repro/blob/main/cypress/e2e/example.spec.cy.ts reproduces this issue and I will route this to the e2e team for prioritization.