Conflicting information on using .should('be.visible') before .click() #14889
-
Hello! Up until now my organization has been purposefully omitting checks on an element's visibility prior to clicking or otherwise interacting with that element because of Cypress' built-in check for "actionability" as described here. Having read this page, it seemed pretty clear that explicitly checking that an element However, today I came across this blog post and my understanding was no longer clear. This post seems to suggest that as an anti-flake measure, using In short, I guess my question is which of these should we be doing?
or
If someone could clear up the confusion here that would be greatly appreciated as I want to make sure that my organization is taking the right steps towards creating flake-free tests. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The repo is at https://github.com/bahmutov/next-js-example-may-2020 The test as written without an explicit visibility check shows the eye icon at the moment of the We want to remove non-deterministic behavior, and adding I also tried upgrading Cypress to 6.4.0 to see how it handles the race condition - the same thing. So my last word is to use an explicit |
Beta Was this translation helpful? Give feedback.
-
Curious, is it still relevant? |
Beta Was this translation helpful? Give feedback.
The repo is at https://github.com/bahmutov/next-js-example-may-2020
The test as written without an explicit visibility check shows the eye icon at the moment of the
cy.get
command, I believe. Thus if this is the first command, it is racing against the Next framework. Sometimescy.get
finds the element visible, and sometimes not yet. Thus if you reload the tests you will see different results, as this video below demonstratesWe want to remove non-deterministic behavior, and adding
cy.get('...').should('be.visible')
ensures the Next app is fully rendered before proceeding tocy.click
command. I really do not like the "invisible element" badge in the Command Log. Thus adding an assertion l…