waitForInvisible produces incorrect/misleading failure messages in certain situations. semantics are unintuitive
See original GitHub issueI 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:
- Created 6 years ago
- Comments:9
Top GitHub Comments
@reubenmiller Great. Thanks for the clarifications. I will try to work on it this this weekend.
Fixed in v1.1.6