webdriverio: fix inconsistent isVisible behavior
The problem
isVisibleseems like a boolean returning method but is not. You can’t doif(isVisible('<selector>').- It returns an array if multiple elements are found, which to be fair is documented. But it’s like Array.length returning it’s return values in roman numerals if length is greater than 10. It’s behavior is not consistent.
- The array returned is also not consistent. It has
falsevalues, sometimes, meaning I can’t just check for length to be equal to 0 or just for it to return false. If no elements are visible, sometimes, it returns values like [false, false]. Which is bad because, it’s length is not zero (you’re expecting visible elements), and it’s not a falsey value so that’s not easy to use either.
Briefly describe the issue you are experiencing (or the feature you want to see added to WebdriverIO). Tell us what you were trying to do and what happened instead. Remember, this is not a place to ask questions. For that, join the Gitter chat room ()!
Environment
- WebdriverIO version: v4.6.2
- Node.js version: v6.10.2
- Standalone mode or wdio testrunner: wdio testrunner
- if wdio testrunner, running synchronous or asynchronous tests: synchronous
- Additional wdio packages used (if applicable): “wdio-mocha-framework”: “^0.5.9”, “wdio-spec-reporter”: “^0.1.0”,
Details
Describe in more detail the problem you have been experiencing, if necessary.
I’d like to use if(isVisible()) like syntax because that’s what it implies by the name, that it returns a boolean. I’d like to submit a PR to fix isVisible (which might be a breaking change), short of which, I’d like a new function which does this behavior.
Link to Selenium/WebdriverIO logs
not relevant I think, I think
Create a gist which is a paste of your full Selenium/WebdriverIO logs, and link them here. Do not paste your full Appium logs here, as it will make this issue very long and hard to read! If you are reporting a bug, always include Selenium/WebdriverIO logs!
Code To Reproduce Issue [ Good To Have ]
run isVisible in a loop, waiting for elements to disappear
Please remember that, with sample code; it’s easier to reproduce bug and much faster to fix it.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (4 by maintainers)
@mattc41190 thanks for taking the time to reply.
What we’ve done is created a function called isVisibleFixed and use that. This is very similar in concept to your suggestion of using addCommand.
I’ve figured this out, I’ve no further qualms. I thought it would benefit other developers if isVisible returned a boolean always, but that’s a suggestion and the maintainer can take the final call as I suppose he already has 🙂
I am happy to have a serious conversation about this API design but this is just a stupid argument. Sorry.