Cypress: Asserting something should('not.have.value') / should('not.be.visible') logs element as "undefined"

Created on 21 Nov 2019  路  10Comments  路  Source: cypress-io/cypress

Current behavior:

What I try to check in my test is that a given field should not have an empty value as the following code shows.

cy.get('[data-test=ext-referral-form-btn]').should('be.visible').click();
cy.get('[data-test=ext-referral-formSuccess-code]').should('not.have.value','');

Such assertion is set right after a click where I submit form data and wait for ext-referral-formSuccess-code in the next view (after loading) to have an empty value.

The test passes but in the log I see the following:

notempty

The assertion seems to go well but the cypress logger doesn't work as expected, logging the field names as undefined. Actually, if I wait some ms after the click just to give some time to Cypress to see the fields I see the following:

successfields

I also see the correct data logged if instead of asserting should('not.have.value','') I set should('have.value','whatever').

Desired behavior:

I expect to see the correct value of the field names I am asserting using should('not.have.value','') in a view that is onloading instead of undefined.
It seems that when Cypress logs the data it doesn't have the value at hand, and only explicitly waiting some time it is able to read it and log it properly.

Steps to reproduce: (app code and test code)

You can verify this behavior by setting an assertion like cy.get('yourThing').should('not.have.value','') right after submitting a form.

  • Fill up required data
  • submit the form
  • assert that an element in the next view should('not.have.value','')
  • See the Cypress log

Versions

Cypress 3.6.1
Ubuntu Linux 18.04.3 LTS
Electron 73
Also using Cucumber pre-processor 1.16.2

pkdriver regression v3.5.0

Most helpful comment

Perfect, thank you! I verified this was introduced in 3.5.0.

This only happens during the .should('not.be.visible') assertion specifically (and from original comment the .should('not.have.value'). Does not happen in .should('not.exist') for example.

All 10 comments

I found this issue as well after Cypress3.4.1.
May you try on Cypress3.4.1?
For my case, my element is not visible due to the caretDown is not expanded yet but Cypress return undefined.

If found element as "undefined" that I want to check it before "View Order Detail" is expanded or click
image

If it is expanded, then it will show element under "View Order Detail" as below:
image

We'll need a reproducible example provided - test code + html in order to investigate. Likely it has to do with something rerendering in the DOM at a strange time when we're trying to access the element.

We'll need a reproducible example provided - test code + html in order to investigate. Likely it has to do with something rerendering in the DOM at a strange time when we're trying to access the element.

This is the code

it('should found "xxx" element not to be visible', () => {
    cy.visit('https://docs.cypress.io/guides/overview/why-cypress.html')
    cy.get('xxx').should('not.be.visible')
  })

This is the result in Cypress3.4.1
image
This is the result in Cypress3.8.0
image

Perfect, thank you! I verified this was introduced in 3.5.0.

This only happens during the .should('not.be.visible') assertion specifically (and from original comment the .should('not.have.value'). Does not happen in .should('not.exist') for example.

Thanks for providing the example @frankind

Any news on this?

hey team, just noticed the same thing a month after upgrading to cypress version 4.0.2.
Any news on a fix?
I have lots of tests that are now giving false positives 馃槩

Just adding a smaller repro and confirming that this still occurs in 4.9.0.

<html>
<body>
</body>
</html>
it('should find "xxx" element not to be visible', () => {
  cy.visit('index.html')
  cy.get('xxx').should('not.be.visible')
})

3.4.1

Screen Shot 2020-07-09 at 12 42 53 PM

3.5.0+

Screen Shot 2020-07-09 at 12 39 52 PM

The code for this is done in cypress-io/cypress#8612, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

Released in 5.3.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.3.0, please open a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

verheyenkoen picture verheyenkoen  路  3Comments

rbung picture rbung  路  3Comments

zbigniewkalinowski picture zbigniewkalinowski  路  3Comments

brian-mann picture brian-mann  路  3Comments

szabyg picture szabyg  路  3Comments