question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Print reasons why Cypress considers an element 'visible' in errors.

See original GitHub issue

Is this a Feature or Bug?

Feature

Current behavior:

When I assert that an element .should('not.be.visible'), but Cypress finds that it is visible, it doesn’t tell me why it considered the element visible.

Error: why does Cypress think it’s visible?? screen shot 2017-09-20 at 3 10 24 pm

Desired behavior:

Cypress should explicitly print the reasons for why Cypress considers an element ‘visible’ when it fails .should('not.be.visible') assertion (just as it does for when it fails .should('be.visible')).

My specific use case had to do with an element on my page having a style of {opacity: 0}. So, to me, the element seems to not be visible and I expected a .should('not.be.visible') assertion to pass.

After speaking with the Cypress team, the current behavior is correct however. Since the browser actually allows users to interact with elements that have {opacity:0} and Cypress uses this visibility algorithm to determine if elements are intractable, they do not intend to change this behavior.

The list of reasons for why Cypress considers something visible may have a specific message about opacity listed first?

How to reproduce:

cy.get('.el-with-opacity-zero').should('not.be.visible')

Reasons why an element is considered visible

Reasons why an element is considered not visible

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
crcatalacommented, Apr 18, 2018

Just ran into this issue. I agree that logging a specific reason (opacity) allows the user some context to why the the assertion failed. If such logging isn’t a priority, perhaps even a mention in documentation about this caveat could be useful?

6reactions
L0wrycommented, Sep 28, 2018

This will probably be a deciding factor if we use cypress as our go-to ui testing tool very very soon.

plz help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debug the Element Visibility Problems in Cypress
Cypress fails the test when the clearly visible "Cypress is amazing!" element is deemed NOT to be visible. The test is failing because...
Read more >
Error Messages | Cypress Documentation
Cypress errors because after a command, the subject becomes 'fixed' to a specific element - since it can't retry commands, if the element...
Read more >
Cypress basics: check if element exists - Filip Hric
This is because Cypress actually verifies that element is hidden via css property like display: none or visibility: hidden .
Read more >
Cypress should not.exist or not.be.visible - Stack Overflow
The tl;dr is that there isn't going to be a simple solution here -- Cypress' get command has assertions, so you can't easily...
Read more >
cy.type() failed because this element is not visible: - You.com
Current behavior: Cypress is failing a test because it claims that an element is disabled. · Desired behavior: Cypress should not say that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found