Cypress commands (e.g. cy.get) return undefined if previous test step fails
See original GitHub issueCurrent behavior:
Cypress test runner fails in after()
block with error:
CypressError: cy.first() failed because it requires a DOM element.
The subject received was:
> undefined
The previous command that ran was:
> cy.get()
Because this error occurred during a 'after all' hook we are skipping the remaining tests in the current suite:
This happens each time a test step fails. In this case, it happens when the following assertion fails
.get('div.header__dob').should('contain', `${patient.birth_date}`)
Desired behavior:
Cleanup step should execute with Cypress commands returning values instead of undefined
Steps to reproduce: (app code and test code)
- Write test with
before
,test
&after
steps - Have an assertion fail during testing
cy.get
should returnundefined
inafter
step
Versions
Cypress: 3.2.0 OS: MacOS 10.14.4 Browser: Electron59 & Chrome73
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Error Messages | Cypress Documentation
We found an error preparing your test file. This message means that Cypress encountered an error when compiling and/or bundling your test file....
Read more >Retry-ability - Cypress Documentation
If the assertion still fails, Cypress continues retrying until the cy.find() timeout is reached. Retry-ability allows the test to complete each query as...
Read more >then | Cypress Documentation
If the callback returns undefined or null (or there is no return value) and the callback does not call any Cypress commands, the...
Read more >Custom Commands - Cypress Documentation
js file, since it is loaded before any test files are evaluated via an import statement in the supportFile. Syntax. Cypress.Commands.add(name ...
Read more >Introduction to Cypress - Cypress Documentation
Cypress halts and fails the test. .get('#element-does-not-exist') // ...this ... If chained directly off of cy , or if the previous command yielded...
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
Hi ! I’m having the same issue when doing cy.visit() to a new url.
We have a custom command which we use to check if our loading dissappear.
When arriving to that URL I have a method which waits for our loading to dissappear (cy.get(loading).should(‘not.exist’)…
Before doing that, we check that the main element in our DOM exists…
The issue comes in that check when in this custom command, we do cy.get(‘mainElement’, { timeout: 10000 }).should(‘exist’); We only do that assertion and afterwards assert that the loading does not exists
I get the following: For some reasons, I cannot show you the ID we use. anyways tried with other ID’s / css selectors and same error so that’s not an issue
Is there any update on this issue? Having the same problem with undefined elements in after methods after test fail