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

Error in beforeEach() in global settings does not cause the test to fail #1293

Closed
matthiasfeist opened this issue Nov 21, 2016 · 5 comments
Closed
Labels

Comments

@matthiasfeist
Copy link

I have the following code in my settings.js (a global settings file):

  beforeEach(browser, done) {
    browser
      .url(this.appUrl)
      .page.login().performLogin()  // this is a page object
      .waitForElementVisible('body', 10000)
      .assert.urlContains(this.appUrl)
      .waitForElementVisible('main', 10000)
  },

Which generates the following output:

[Capture] Test Suite
========================
✔ Element <body> was visible after 592 milliseconds.
✖ Timed out while waiting for element <input#username> to be present for 10000 milliseconds.  - expected "visible" but got: "not found" at Object.performLogin (/integration-tests/integration-tests/page-objects/login.js:6:8)
at Object.beforeEach (/integration-tests/integration-tests/globals/settings.js:42:21)

[...more stuff in between...]

TEST FAILURE:  0 assertions failed, 43 passed. (1m 3s)

✖ capture
 SKIPPED:
  - 2 successful partial captures

That means that if there is an element not found in the the pageObject command performLogin (which uses waitForElementVisible) the test is just skipped instead of failed.
I would want the test then to be marked as failed. Is there a way to achieve this?

@matthiasfeist
Copy link
Author

I played around a bit more with this and it seems like whenever an assert fails in a global before(), a global beforeEach() or a before() in a testsuite the test is not marked as failed and nightwatch exits with the exitcode 0.

But when an assert fails in a local beforeEach() nightwatch counts it as failed and therefore exits with exit status 1.

Version: The current 0.9.9

@matthiasfeist
Copy link
Author

OK please ignore this here. It seems like this error just occurs if there is a condition between a async before() function and the execution of the code. Because nightwatch works correctly when I call done() directly but not when I do something else (like perform a HTTP request to a service) first and then after that is done call done(). When there is something inbeween and done() gets called with a delay, nightwatch does not work as expected.

Because I can't reproduce this behaviour consistently, please ignore this issue until I can provide better input for you guys...

@senocular
Copy link
Contributor

Some of the inconsistent behavior you're seeing may be from #1276

@matthiasfeist
Copy link
Author

Yes that could be. But funnily enough, I nove moved stuff away from the global settings-hook into the hooks in the individual files and also removed the async hooks (so no done() anywhere) and now it's working fine...

@stale
Copy link

stale bot commented Nov 14, 2018

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 contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants