Nightwatch: Wrong error (allElements.shift not a function) showing in test summary

Created on 15 Aug 2016  Â·  5Comments  Â·  Source: nightwatchjs/nightwatch

We have many tests that make use of sections. Whenever one of these tests contains a call to verify an element within a section and the test fails, the correct error is reported, along with the allElements.shift is not a function error. Unfortunately, the final test summary at the end of the test run ONLY reports the allElements.shift error, instead of the correct, more helpful error that the element being sought was not available.

For example:

My test has the following line:
this.section.userMenu.expect.element('@logOff').to.be.visible

If the expectation fails when the test runs, I see:

 ✖ Expected element <Section[name=accountDropDown],Element[name=@signOut]> to be visible  - expected "visible" but got: "not visible"
    at Object.commands.assertLogoutButton (/app/e2e/pages/global.js:51:41)
    at Object.module.exports.before.Throws an error for an incorrect login.Logs in with a valid user (/app/e2e/tests/login/login.spec.js:19:16)

The test then automatically retries. When this happens, an earlier validation (which occurs inside an iframe), which passed on the first attempt, now fails on the second attempt:

this.api.frame('login_iframe').waitForElementPresent('main_page_content')

Then, when the suite completes, that failure reports as:

TEST FAILURE: 1 error during execution,  0 assertions failed, 6 passed. (42.602s)

 ✖ login/login.spec

   - Throws an error for an incorrect login (7.581s)

   Error while running waitForElementPresent command: allElements.shift is not a function
       at Object.setCredentialFields (/app/e2e/pages/login.js:63:8)
       at Object.commands.loginFlow (/app/e2e/pages/login.js:40:10)
       at Object.module.exports.before.Throws an error for an incorrect login (/app/e2e/tests/login/login.spec.js:13:15)

Summary:

  1. It would be helpful if the summary output would include the original error during the test's first attempt, rather than the second attempt.
  2. It would be helpful if the waitForElementPresent error were reported rather than the allElements.shift internal error when a waitForElementPresent check is executed.
bug

Most helpful comment

I'm seeing this error in the retries after a command failure. Does anyone know if this is already fixed?

Retrying (1/7):  Remembers the computer                                                                                                                      
 ✔ Testing if element <body> contains text: "cleared".                                                                                                       
 ✔ Element <#content> was visible after 2846 milliseconds.                                                                                                   
 ✔ Element <Section[name=loginForm],Element[name=@usernameField]> was visible after 489 milliseconds.                                                        
 ✖ Timed out while waiting for element <Section[name=twoFactorForm],Element[name=@tokenField]> to be present for 10000 milliseconds.  - expected "visible" but got: "not found"
    at Object.verify2fa (/home/tri/app/test/nightwatch/pageObjects/login.js:48:10)                              
    at Object.Remembers the computer (/home/tri/app/test/nightwatch/login.js:114:8)                             


Retrying (2/7):  Remembers the computer                                                                                                                      
Error while running getText command: allElements.shift is not a function                                                                                     
    at command (/home/tri/app/node_modules/nightwatch/lib/api/assertions/containsText.js:46:21)                 
    at module.exports.BaseAssertion._scheduleAssertion (/home/tri/app/node_modules/nightwatch/lib/core/assertion.js:87:17)

All 5 comments

see: https://github.com/nightwatchjs/nightwatch/issues/1100#issuecomment-235163142

We need to figure out where the locateStategy mixup is happening.

@magicclaw Do you have a complete example that demonstrates this issue?

I'm kind of hoping this problem just goes away after #1116 eventually gets in, since that implementation avoids the locate strategy set-then-reset steps with the callback wrapping in page objects.

I'm seeing this error in the retries after a command failure. Does anyone know if this is already fixed?

Retrying (1/7):  Remembers the computer                                                                                                                      
 ✔ Testing if element <body> contains text: "cleared".                                                                                                       
 ✔ Element <#content> was visible after 2846 milliseconds.                                                                                                   
 ✔ Element <Section[name=loginForm],Element[name=@usernameField]> was visible after 489 milliseconds.                                                        
 ✖ Timed out while waiting for element <Section[name=twoFactorForm],Element[name=@tokenField]> to be present for 10000 milliseconds.  - expected "visible" but got: "not found"
    at Object.verify2fa (/home/tri/app/test/nightwatch/pageObjects/login.js:48:10)                              
    at Object.Remembers the computer (/home/tri/app/test/nightwatch/login.js:114:8)                             


Retrying (2/7):  Remembers the computer                                                                                                                      
Error while running getText command: allElements.shift is not a function                                                                                     
    at command (/home/tri/app/node_modules/nightwatch/lib/api/assertions/containsText.js:46:21)                 
    at module.exports.BaseAssertion._scheduleAssertion (/home/tri/app/node_modules/nightwatch/lib/core/assertion.js:87:17)

Should be fixed in v1.0.4.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bushev picture bushev  Â·  4Comments

manjero picture manjero  Â·  4Comments

dakebl picture dakebl  Â·  4Comments

Pieras2 picture Pieras2  Â·  3Comments

maxgalbu picture maxgalbu  Â·  3Comments