Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waitForElementVisible produces an error while waitForElementPresent produces a failure when reaching timeout #2148

Closed
jauninb opened this issue Jul 4, 2019 · 15 comments

Comments

@jauninb
Copy link

commented Jul 4, 2019

With nightwatch version 1.1.3, a test using waitForElementVisible produces an error when the command reachs a timeout because the element is not there in the page.
An equivalent test but using waitForElementPresent produces an assertion failure.
This is not equivalent to what was define in previous version of nightwatch 0.9.X as the waitForElementXXX are producing an assertion failure when reaching timeout
As such, the browser.currentTest.result is not containing an assertion failure for the test that uses waitForElementVisible

Server version;

Nightwatch 1.1.13
Node 8.16
Chrome driver version : 2.46
Selenium : 3.141.59

@jauninb

This comment has been minimized.

Copy link
Author

commented Jul 4, 2019

This is also a concern as we are also in front of the abortOnFailure problem for waitForElementVisible that is not take in account - #2139

@jauninb

This comment has been minimized.

Copy link
Author

commented Jul 4, 2019

Sample test code

module.exports = {

    'Demo test Google': function (browser) {
      browser
        .url('http://google.com')   // visit the url
        .waitForElementVisible('body') // wait for the body to be rendered
        .assert.containsText('body', 'Google') // assert body contains text
        //.waitForElementPresent('non-existing-one', 2000) // produces an assertion failure 
        //.waitForElementNotPresent('body', 2000) // produces an assertion failure 
        .waitForElementVisible('non-existing-one', 2000) // produces an error in nightwatch 1.1.13
        //.waitForElementNotVisible('body-non-existing', 2000) // produces an error in nightwatch 1.1.13
        .end();
      }
}
@beatfactor

This comment has been minimized.

Copy link
Member

commented Jul 4, 2019

Can you provide a verbose log as well?

@beatfactor

This comment has been minimized.

Copy link
Member

commented Jul 4, 2019

@jauninb if you log client.currentTest.results.testcases you can see the lastError property for each testcase.

@jauninb

This comment has been minimized.

Copy link
Author

commented Jul 5, 2019

@beatfactor I agree that client.currentTest.results.testcases have a lastError property when waitForElementVisible's condition is not met (ie timeout) because the expected element is not present but this is different from others waitForElementXXX commands in Nightwatch 1.1.3:

  • when waitForElementPresent's condition is not met => assertion failure
  • when waitForElementNotPresent's condition is not met => assertion failure

Whereas here when using waitForElementVisible or waitForElementNotVisible with a non existing element, it produces an error.

In Nightwatch 0.9.X, it was like the documentation described:
If the element fails to be present and visible in the specified amount of time, the test fails

jauninb added a commit to jauninb/sample-nightwatch that referenced this issue Jul 5, 2019
@jauninb

This comment has been minimized.

Copy link
Author

commented Jul 5, 2019

@beatfactor here is the verbose log for the sample test case
nightwatch_google_test_verbose.log

In addition, the repo containing the test is there https://github.com/jauninb/sample-nightwatch

@beatfactor

This comment has been minimized.

Copy link
Member

commented Jul 5, 2019

We can take into account the abortOnFailure flag for element not found errors in the case of waitForElementVisible / waitForElementNotVisible commands. They will still be reporter as errors though.

@jauninb

This comment has been minimized.

Copy link
Author

commented Jul 5, 2019

While I do not understand this to be reported as an error - this is clearly a different behavior that in previous nightwatch version and it is not documented in this way in this user guide - hence our concern as we wrote a lot of tests using NW 0.9
In addition, this is not mentionned in the migration guide.

@amirGaouaou

This comment has been minimized.

Copy link

commented Jul 5, 2019

#2127

I see the same error with a Click too, instead of an assertion error, I see the same NoSuchElementError being thrown. I only see this on 1.1.X, I don't see the in previous version such as 1.0.19.

I updated the issue referenced with additional details

@beatfactor

This comment has been minimized.

Copy link
Member

commented Jul 8, 2019

@jauninb We will address the issue in the next version. Thanks for your patience.

@oldGreg5

This comment has been minimized.

Copy link

commented Jul 8, 2019

@beatfactor up to 1.1.0 abortOnFailure=false in waitForElementVisible was logging assertion fail but not errored and test was not aborted. We use it in many places where we expect possible popup. I don't really know how else to check if it is visible to be able to close it or just continue if it isn't.
Thanks in advance for undestanding

@beatfactor

This comment has been minimized.

Copy link
Member

commented Jul 8, 2019

@oldGreg5 you could use the isVisible command.

@beatfactor beatfactor closed this Jul 8, 2019
@beatfactor beatfactor reopened this Jul 8, 2019
@oldGreg5

This comment has been minimized.

Copy link

commented Jul 9, 2019

Thanks @beatfactor but thing is if popup element is not present then it still logs error, whether its .verify, .assert or .isVerify. Up to version 1.1.0 it did not result in error when abortOnFailure=false when element was not present in DOM at that time so thats a big change.

@beatfactor

This comment has been minimized.

Copy link
Member

commented Aug 5, 2019

Thanks @beatfactor but thing is if popup element is not present then it still logs error, whether its .verify, .assert or .isVerify. Up to version 1.1.0 it did not result in error when abortOnFailure=false when element was not present in DOM at that time so thats a big change.

For this case you should use the isVisible command, as it doesn't contain any assertion so the results of the test won't be affected.

If you will use waitForElementVisible with the abortOnFailure=false flag, the test execution will continue but the failure will still be logged and eventually your test will fail. The flag doesn't affect the outcome of the test, it will only allow you to run other assertions.

@beatfactor beatfactor self-assigned this Aug 12, 2019
@beatfactor

This comment has been minimized.

Copy link
Member

commented Aug 12, 2019

Fixed in 1.2.1.

@beatfactor beatfactor closed this Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.