Cypress: Element visibility fixes

Created on 31 Jan 2018  路  2Comments  路  Source: cypress-io/cypress

There are multiple issues regarding elements being calculated as visible when they are hidden OR elements being calculated as hidden when they are visible. This issue is generally to be used to track the progress made for these fixes.

I think that it is interesting to note that jQuery ditched their visibility calculations in 3.0 and is likely worthwhile looking into why/how they made these decisions.

An element is considered now visible if it has a layout box returned from the DOM getClientRects() method, even if that box has a height and/or width of zero. This means that elements such as
or an empty element that don't have height are considered to be visible.
https://github.com/jquery/jquery/issues/2227
https://github.com/jquery/jquery/issues/2604

Issues

Not reproducible issues

Desired behavior:

  • Find a better way to more accurately determine visibility.
  • Always display reason why we determine something as visible or not visible.
  • Add tests for all failing cases above - get tests passing

Versions

Cypress: 3.3.1

鈹咺ssue is synchronized with this Jira Bug by Unito

Epic pkdriver work in progress visibility 馃憗 bug

Most helpful comment

I've made a flowchart of our current implementation for visibility checks. This applies when using cy.get('el').should('be.visible'), etc as well as some other checks we do before actions are taken: .check(), .click(), .type() and some instances of .trigger()

nC0TrUIVMOLJObyg-F2826

Some notes upon review of the diagram on changes we want to make:

  • What would be great is to not only have the flowcharts for use in the docs, but to also have examples of each one so that people understand the rules and situations in which its visible.
  • In Command Log where eyeball displays - need to refactor this logic as per https://github.com/cypress-io/cypress/issues/696#issue-261674444 (not in scope of this current issue)

Separate out the "loose" checks from "strict" checks for visibility. Today is all "loose" checks -- "strict" checks concerns whether the element is visible within the viewport and the necessity to scroll to an element first.

"Loose" visibility checks

  • Should prove the element is hidden, fall through to visible if not.
  • Checks tiny heuristics of element - is visibility: collapse, is within css-path, etc., etc. etc.
  • Used for 'is.visible' assertions. Meant to represent if the element can be seen by a person without disabilities and 20/20 vision.

"Strict" visibility checks

  • Should prove the element is visible, fall through to hidden if not.
  • Checks just clientRect + elFromPoint and edge cases.
  • Used for actionability checks - some things are not really visible to the eye, but the mouse will click it if the user is on the coordinates and clicks, for example.

Questions

  • Do we introduce a new assertion? pseudo-selector? flag?
  • Is there a better naming convention for loose vs strict??
  • Screenshots + flowcharts for docs to describe "loose" versus "strict".

All 2 comments

I've made a flowchart of our current implementation for visibility checks. This applies when using cy.get('el').should('be.visible'), etc as well as some other checks we do before actions are taken: .check(), .click(), .type() and some instances of .trigger()

nC0TrUIVMOLJObyg-F2826

Some notes upon review of the diagram on changes we want to make:

  • What would be great is to not only have the flowcharts for use in the docs, but to also have examples of each one so that people understand the rules and situations in which its visible.
  • In Command Log where eyeball displays - need to refactor this logic as per https://github.com/cypress-io/cypress/issues/696#issue-261674444 (not in scope of this current issue)

Separate out the "loose" checks from "strict" checks for visibility. Today is all "loose" checks -- "strict" checks concerns whether the element is visible within the viewport and the necessity to scroll to an element first.

"Loose" visibility checks

  • Should prove the element is hidden, fall through to visible if not.
  • Checks tiny heuristics of element - is visibility: collapse, is within css-path, etc., etc. etc.
  • Used for 'is.visible' assertions. Meant to represent if the element can be seen by a person without disabilities and 20/20 vision.

"Strict" visibility checks

  • Should prove the element is visible, fall through to hidden if not.
  • Checks just clientRect + elFromPoint and edge cases.
  • Used for actionability checks - some things are not really visible to the eye, but the mouse will click it if the user is on the coordinates and clicks, for example.

Questions

  • Do we introduce a new assertion? pseudo-selector? flag?
  • Is there a better naming convention for loose vs strict??
  • Screenshots + flowcharts for docs to describe "loose" versus "strict".

I'm going to close this issue for tracking - as there are only a couple of remaining issues that should be resolved when opacity: 0 is considered, which there is a PR for.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SecondFlight picture SecondFlight  路  3Comments

tahayk picture tahayk  路  3Comments

brian-mann picture brian-mann  路  3Comments

Francismb picture Francismb  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments