nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

Test fails when isVisible is called on a non visible element #1098

Closed eladmoshe closed 8 years ago

eladmoshe commented 8 years ago

Consider the following code:

client.isVisible('.my-class', result => {
  if (result.value === true) {/*do something*/}
  else {/*do something else*/}
}

If the element is visible everything works great. However, if the element is not visible the test fails with an error: ERROR: Unable to locate element: ".my-class" using: css selector I believe that isVisible should just return the result and never fail the test.

[Nightwatch version 0.9.5; reproduced w/ Appium over iOS and Selenium over Chrome.]

eladmoshe commented 8 years ago

I found a workaround in the mailing list if anyone has this issue.

 browser.element('css selector', 'select', function(result){
            if (result.value && result.value.ELEMENT) {
                // Element is present, do the appropriate tests
            } else {
                // Element is not present.
            }
        });
senocular commented 8 years ago

FWIW, being based off of elementiddisplayed means it does have a dependency on the element existing on list. This is, I'm guessing, why you're getting an error. If a select element was present on the DOM and not visible, then you should get a false return value.

I'm not sure if isVisible is also meant (by design) to account for element present. Perhaps there's a missing isPresent command needed to determine if an element exists in the first place - not unlike the distinctions between waitForElementVisible and waitForElementPresent.

Edit: Should isVisible be changed to consider lack of presence as not-visible, then for consistency, waitForElementNotVisible should also be updated to pass on element not found. Currently it does not, failing on element expected to be present.

eladmoshe commented 8 years ago

I understand what you mean, makes sense. Indeed an isPresent command is what I was looking for. I believe that it is probably a common scenario and the browser.element option isn't documented, or at least I haven't found it.

senocular commented 8 years ago

@eladmoshe the element method is documented under the Selenium Protocol:

http://nightwatchjs.org/api#element

These are commands that are directly tied to the selenium api and not in Nightwatch wrappers like isVisible is.

eladmoshe commented 8 years ago

@senocular Thanks!