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.

waitForInvisible produces incorrect/misleading failure messages in certain situations. semantics are unintuitive

See original GitHub issue

I recently discovered that a number of my company’s tests were failing on account of an incomplete understanding of how waitForInvisible works.

My tester writing the tests quite reasonably assumed that waitForInvisible would wait until the page contained no visible elements matching the indicated selector.

After reading through the source code, I now realize that what it actually does is wait until there is at least one non-visible element matching the indicated selector.

This means that if the page contains no elements matching the selector (e.g. if they had been removed from the page or never been there in the first place), waitForInvisible eventually indicates a failure with a factually incorrect message:

I.waitForInvisible('#idonotexist');

The line above will wait and eventually fail with the message: element (#idonotexist) still visible after 5 sec. This is factually incorrect and misleading to someone reading the test results because #idonotexist is not “still visible”. It doesn’t exist at all!

Conversely, if the page contains a mixture of visible and non-visible elements matching a particular selector, waitForInvisible will succeed as long as at least one of them is non-visible.

<div class="myclass" style="display: none">I am not visible</div>
<div class="myclass">I am visible</div>
I.waitForInvisible('.myclass');   // succeeds

I realize that there is a waitForStalenessOf method which checks for the non-presence of elements in the DOM (at least this is true in the WebDriverIO helper; in the Protractor helper, it’s just an alias for waitForInvisible). However, I would think that from a testing perspective, it would be more common and generally better practice to simply test whether an element is visible in the page or not, and not get mired down in the implementation details of hidden vs. not present in the DOM. But Codecept doesn’t seem to provide any method for simply checking whether the page does or does not have a particular visible element.

So my questions are:

  • Is .waitForInvisible’s behavior, as described and demonstrated above, really intentional? It seems strange and counterintuitive to me.
  • If it is intentional, can the failure message at least be improved to more clearly convey what it’s checking for? E.g. no invisible element (#idonotexist) found after 5 sec

Details

  • CodeceptJS version: 1.1.4
  • NodeJS Version: 8.9.4
  • Operating System: Win10
  • WebDriverIO version: 4.10.2
  • Configuration file: unchanged from default

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
JLRishecommented, Feb 17, 2018

@reubenmiller Great. Thanks for the clarifications. I will try to work on it this this weekend.

0reactions
reubenmillercommented, Mar 1, 2018

Fixed in v1.1.6

Read more comments on GitHub >

github_iconTop Results From Across the Web

waitForInvisible produces incorrect/misleading failure ... - GitHub
waitForInvisible produces incorrect/misleading failure messages in certain situations. semantics are unintuitive #943.
Read more >
Situations in Natural Language Semantics
In situation semantics, linguistic expressions are evaluated with respect to partial, rather than complete, worlds.
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found