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

Expect assertions break using before/after methods #549

Closed munkyjunky closed 9 years ago

munkyjunky commented 9 years ago

Addition of the after method to my assertions causes an error to be thrown.

Code:

var homepage = browser.page.homepage();
var navigation = homepage.section.navigation;
/* *** snip *** */
homepage.expect.section('@navigation').to.be.visible.after(util.timeout);

Error:

An error occurred while running the tests:
TypeError: Cannot read property 'ELEMENT' of null
    at VisibleAssertion.executeCommand (C:\Workspace\Project\node_modules\nightwatch\lib\api\expect\visible.js:30:54)
    at VisibleAssertion.BaseAssertion.onPromiseResolved (C:\Workspace\Project\node_modules\nightwatch\lib\api\expect\_baseAssertion.js:104:8)
    at VisibleAssertion.retryCommand (C:\Workspace\Project\node_modules\nightwatch\lib\api\expect\visible.js:55:8)
    at Timer.listOnTimeout (timers.js:119:15)

Removing the after method prevents this error from occurring, however my test fails (as expected in that case, as the element is not visible). What I'm trying to achieve with my test:

Changing the section declaration for just an element causes the same error. I suspect this error is happening as I'm expecting a section of a page to become visible that at the initial time of assertion is not on the page. Switching to browser.waitForElementVisible allows me to complete the test, so I think this is an issue within the expect API.

Can't post the full test due to this being a work project.

beatfactor commented 9 years ago

Have you tried referencing the element by its css selector directly? Does that produce the same error?

munkyjunky commented 9 years ago

The following works: browser.waitForElementVisible('.list-container', util.timeout);

Keeping it within the expect / page api, however, still breaks it with the same error: homepage.expect.element('.list-container').to.be.visible.after(util.timeout);

sknopf commented 9 years ago

Thanks, I see the issue, will fix soon.

sknopf commented 9 years ago

Posted a fix here

munkyjunky commented 8 years ago

I'm seeing this issue occurring again. Running nightwatch v0.9.0.

This test fails:

login_modal.expect.element('@modal').to.not.be.visible.before(browser.globals.timeout);
header_login.expect.element('@login_button').to.not.be.present;
header_login.expect.element('@logout_button').to.be.visible;

with output: Expected element <.Login__modal> to not be visible in 10000ms - Expected "not visible" but got: "visible"

This test works:

browser.pause(browser.globals.timeout);
login_modal.expect.element('@modal').to.not.be.visible;
header_login.expect.element('@login_button').to.not.be.present;
header_login.expect.element('@logout_button').to.be.visible;

Trying CSS selectors instead of page objects makes no difference to this.

beatfactor commented 8 years ago

Are you sure it's the same issue? There have been no changes in the area and your test doesn't seem to be doing exactly the same thing.

munkyjunky commented 8 years ago

I previously raised this issue here #544, which was marked as a duplicate of this bug, so I thought it best to comment here. If you think it's a separate issue I can open a new issue instead?

Apologies, should have also referenced #544 in my previous comment.

beatfactor commented 8 years ago

Btw, you can avoid .before(browser.globals.timeout); by setting the global waitForConditionTimeout, as it is done here.

beatfactor commented 8 years ago

Have you changed anything in your setup? Like selenium or browser version?

On Thursday, 26 May 2016, Simon W notifications@github.com wrote:

I previously raised this issue here #544 https://github.com/nightwatchjs/nightwatch/issues/544, which was marked as a duplicate of this bug, so I thought it best to comment here. If you think it's a separate issue I can open a new issue instead?

Apologies, should have also referenced #544 https://github.com/nightwatchjs/nightwatch/issues/544 in my previous comment.

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/nightwatchjs/nightwatch/issues/549#issuecomment-221855673

munkyjunky commented 8 years ago

This is in a different project to my original issue, although I don't believe it was ever solved in that one either.

I'm running node v0.12.9, selenium server 2.53.0, and chrome webdriver from this package, v2.21.2. Also tested this under node 4.4.3, without change.

beatfactor commented 8 years ago

And in nightwatch 0.8.18 it works as expected?

beatfactor commented 8 years ago

Is it possible to see the verbose log output for the failing test in 0.9.0?

munkyjunky commented 8 years ago

No, doesn't work in nightwatch 0.8,18 either. Since raising the issue originally I can't definitively tell you it has worked - this is for a work project and I swapped teams for a while so dropped the work we're doing with Nightwatch. I don't think this is something that has been broken in a recent release.

I've had to blank a few values in the output as this is client work and I'd rather avoid posting up their URLs, and also removed my login info. Output here: https://gist.github.com/munkyjunky/70d3105f9d1a86db6e3e07c106d2cc57

beatfactor commented 8 years ago

Ok, from the output here is looks like the element is not visible so for some reason nightwatch is incorrectly reporting that it is. I'll look into it, can you open a separate issue please?

munkyjunky commented 8 years ago

Opened new issue #997