Nightwatch: `waitForElementVisible` fails even when `abortOnFailure` is false

Created on 20 Jun 2017  路  14Comments  路  Source: nightwatchjs/nightwatch

Issue:

No matter what I do waitForElementVisible won't let me pass through when the element is not there (which in my test, is a perfectly valid condition)

I'm using the embedded mocha runner, but I've also tried with the default one, with no variation in outcome.

  "test_runner" : {
    "type" : "mocha",
    "options" : {
      "ui" : "bdd",
      "reporter" : "spec"
    }
  },

Environment:

  • Node 6.10.0
  • Nightwatch 0.9.16
  • Selenium 3.4.0
  • geckodriver 0.17.0
  • OSX

Code snippet:

I've actually tried a few different flavors of the same code, just to see if there was something I was missing there...

  const defaultWait = 10000;

  it('inside the callback', client => {
    client.waitForElementVisible('.list', defaultWait, false, result => {
        if (result.value) {
          client.click('.list li:first-child');
        } else {
           client.waitForElementVisible('.tableContainer', defaultWait)
             .assert.elementPresent('.tableContainer')
             .end();
         }
      })
  });

  it('in the chain', client => {
    client.waitForElementVisible('.list', defaultWait, false, result => {
        if (result.value) {
          client.click('.list li:first-child');
        }
      })
      .waitForElementVisible('.tableContainer', 10000)
      .assert.elementPresent('.tableContainer')
      .end();
  });

  it('in the chain, separate client calls', client => {
    client.waitForElementVisible('.list', defaultWait, false, result => {
        if (result.value) {
          client.click('.list li:first-child');
        }
      })

    client.waitForElementVisible('.tableContainer', 10000)
      .assert.elementPresent('.tableContainer')
      .end();
  });

Error:

All these tests lead to the same failure error:

Timed out while waiting for element <.list> to be present for 10000 milliseconds. - Expected "visible" but got: "not found"


As I understand it, when abortOnFailure is set to false, I should still see the errors, but the tests should continue the execution and eventually fail or succeed, but that's not what's happening on my test cases, unfortunately.

Thanks in advance!

stale

Most helpful comment

This is an excellent workaround, @aamorozov

    .waitForElementNotPresent('input#email', defaultWait)
    .isVisible('.list', result => {
      if (result.value) {
        this.click('.list li:first-child');
      }
    });

This way I don't have to wait for the entire timeout, but just until the previous stuff has disappeared.
Thanks a lot for the input!

All 14 comments

@dmatteo Have you tried setting skip_testcases_on_fail: false in your configuration file => test settings => default ? Works for me within default test runner, haven't used mocha with nightwatch.

If that doesn't work, using combination of pause and verify should do the job, not as elegant, but works for me as well(failing the assertion with verify doesn't fail the test, while failing with assert does).

@aamorozov skip_testcases_on_fail won't help me, cause I actually want to test that something is on the screen after having moved on from .accountlist.

pause/verify doesn't work, because verify doesn't have a callback.
However, your input gave me another idea, and this actually works

    client
      .pause(defaultWait)
      .isVisible('.list', result => {
        if (result.value) {
          client.click('.list li:first-child');
        }
      })

There's an obvious drawback here though: we have to wait for the entire timeout before we can move on with the next command, which we could avoid by using waitForElementVisible.

@dmatteo Actually, have you tried the same but with waitForElementNotVisible in case when you know that the element should not appear ? The command accepts the same parameters as waitForElementVisible. The one that you've added is a pretty good solution

This is an excellent workaround, @aamorozov

    .waitForElementNotPresent('input#email', defaultWait)
    .isVisible('.list', result => {
      if (result.value) {
        this.click('.list li:first-child');
      }
    });

This way I don't have to wait for the entire timeout, but just until the previous stuff has disappeared.
Thanks a lot for the input!

Any update on this? Its cool to find an alternative, but this is still a bug.

Edit: never mind. I was looking for a solution where if the wait expires it doesn't log as a Failure, but that is not what abortOnFailure does.

This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contributions.

@rgeraldporter did you find a solution?

I'm looking for the same thing as @rgeraldporter mentioned, will be good to have.

@aamorozov skip_testcases_on_fail won't help me, cause I actually want to test that something is on the screen after having moved on from .accountlist.

pause/verify doesn't work, because verify doesn't have a callback.
However, your input gave me another idea, and this actually works

    client
      .pause(defaultWait)
      .isVisible('.list', result => {
        if (result.value) {
          client.click('.list li:first-child');
        }
      })

There's an obvious drawback here though: we have to wait for the entire timeout before we can move on with the next command, which we could avoid by using waitForElementVisible.

I tried the same, but the execution is stopped with the below error message

Given I open the home page

{ message: 'no such element: Unable to locate element: {"method":"css selector","selector":".ow-app1"}n (Session info: chrome=74.0.3729.131)n (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.16299 x86_64)' }
ERROR: Unable to locate element: ".ow-app1" using: css selector

Code snippet

return client
  .pause(5000)
  .isVisible('.ow-app1', result => {
    if (result.value) {
      console.log(result.value);
    }
  })

Test Settings

live_output: true,
disable_colors: false,
skip_testcases_on_fail: true,
abortOnFailure: false,
end_session_on_fail: true,

Having the same problem with waitForElementVisible not respecting abortOnFailure arg set to false and always fail the test.
Last working version was 1.1.0, this stopped working in 1.1.1.
It's perfectly legit use case as I need to check if some popup is displayed and close it if it is but continue if its not showing.
Now it always fails so I need to stick to old nightwatch missing all the fun and es6 :(

I am also experiencing not continuing on failure when abortOnAssertionFailure is false both globally and inside the .waitForElementVisible call.
NW ver 1.1.12

.... so an another bug not met to be fixed? I needed this flag but ain't working

For anyone ending up here, this is not a bug, it's intended behaviour. The failure should still be logged, even if the abort flag is set to false. If you need to check if an element is visible or not, use isVisible command. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidlinse picture davidlinse  路  4Comments

chaseconey picture chaseconey  路  4Comments

maxgalbu picture maxgalbu  路  3Comments

gary5 picture gary5  路  4Comments

aking1012 picture aking1012  路  4Comments