Implicit should 'exist' assertion is not being applied on cy.get() when other assertion.
See original GitHub issueUsing cy.get()
on an element should implicitly assert existence of the element. But in my examples below, you can see that I have no element foobarbaz
, the Command Log correctly logs 0
elements found, yet my explicitly written assertions (not.be.visible
and not.have.class
) chained off of the gotten element pass.
cy.get()
should always implicitly assert existence unless there is an explicit assertion down the chain on that element asserting that it should not.exist
.
Example Test Code
it("dom element doesn't have attributes", function() {
cy.get("foobarbaz").should("not.be.visible");
cy.get("foobarbaz").should("not.have.class", "foo");
});
Example Command Log
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:18 (10 by maintainers)
Top Results From Across the Web
Is the .should('exist') assertion redundant on Cypress?
For your usecase of asserting whether an element exists, they are indeed redundant. .contains() yields a DOM element and according to ...
Read more >Assertions | Cypress Documentation
Watch the short video "Multiple elements and should('be.visible') assertion" that shows how to correctly check the visibility of elements. Existence. // retry ...
Read more >What are Cypress Assertions and How to use ... - Tools QA
Assertions are the validation steps that determine whether the specified step of the automated test case succeeded or not.
Read more >Assertions | Cypress examples (v9.7.0) - Gleb Bahmutov
In most cases, you do not need to explicitly check if the element exists - if the cy.get , cy.contains , etc. command...
Read more >Cypress - Assertions - Tutorialspoint
If an assertion is applicable to the object obtained from the parent command in a chain, it is known as the implicit assertion....
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
I like to have
cy.get('@someAlias').should('not.exist')
to have the same behavior, because according to the docs an alias requeries the element.Currently for a non-existing selection my example returns
Timed out retrying: Expected to find element: ’someAlias', but never found it.
, while a regularshould('not.exist')
passes.Another use case from #6958 - notice I’m not even visiting a website and this passes because the checkbox doesn’t event exist.