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

Nightwatch + Cucumber.js, waitFor-type commands abort execution when failing inside a custom command #3540

Closed
asos-saveriocutrupi opened this issue Jan 3, 2023 · 4 comments · Fixed by #3570
Assignees
Labels
bug cucumber Issues related to Cucumber Test runner

Comments

@asos-saveriocutrupi
Copy link

asos-saveriocutrupi commented Jan 3, 2023

Description of the bug/issue

Cucumber 8.10.0, Chromedriver 108.0.0.

When browser.waitForElementVisible()/waitForElementPresent() fail inside a custom command, Nightwatch process aborts with an unhandledRejection error.

Steps to reproduce

  1. Init Nightwatch with cucumber.js and chromedriver
  2. define a custom command containing a .waitForElementVisible() step
  3. define a cucumber step that calls the custom command
  4. pass a non-existent selector
  5. Nightwatch returns a unhandledRejection error, the process terminates and the browser stays open

Sample test

// features/test.feature
Feature: load wiki
  Scenario: Check the homepage
    Given I navigate to the homepage
    Then an element on the homepage is visible



// customCommands/customWait.js
module.exports = class customWait {
  async command(selector) {
    await browser.waitForElementVisible(selector)
  }
}



// stepDefinitions/nightwatch.js
const { Given, Then } = require('@cucumber/cucumber')

Given(/^I navigate to the homepage$/, async function () {
  await browser.navigateTo(
    'https://en.wikipedia.org/wiki/Main_Page'
  )
})

Then(/^an element on the homepage is visible$/, async function () {
  await browser.customWait('#mp-tfa-h2_ERROR') // non-existent selector
})

Command to run

npx nightwatch --verbose

Verbose Output

⠋ Starting ChromeDriver on port 9515...
 Starting ChromeDriver with server_path=C:\Users\Public\nightwatch\node_modules\chromedriver\lib\chromedriver\chromedriver.exe...
   Request POST /session  
   {
     capabilities: {
       firstMatch: [ {} ],
       alwaysMatch: { browserName: 'chrome', 'goog:chromeOptions': {} }
     }
⠼ Starting ChromeDriver on port 9515...

⠇ Starting ChromeDriver on port 9515...
   Response 200 POST /session (782ms)
   {
     value: {
       capabilities: {
         acceptInsecureCerts: false,
         browserName: 'chrome',
         browserVersion: '108.0.5359.125',
         chrome: {
           chromedriverVersion: '108.0.5359.71 (1e0e3868ee06e91ad636a874420e3ca3ae3756ac-refs/branch-heads/5359@{#1016})',
           userDataDir: 'C:\\Users\\SAVERI~1.CUT\\AppData\\Local\\Temp\\scoped_dir1016_1541866121'
         },
         'goog:chromeOptions': { debuggerAddress: 'localhost:53913' },
         networkConnectionEnabled: false,
         pageLoadStrategy: 'normal',
         platformName: 'windows',
         proxy: {},
         setWindowRect: true,
         strictFileInteractability: false,
         timeouts: { implicit: 0, pageLoad: 300000, script: 30000 },
         unhandledPromptBehavior: 'dismiss and notify',
         'webauthn:extension:credBlob': true,
         'webauthn:extension:largeBlob': true,
         'webauthn:virtualAuthenticators': true
       },
       sessionId: '42b25824715f3e4c43c318c4f93d4bc6'
     }
ℹ Connected to ChromeDriver on port 9515 (888ms).
  Using: chrome (108.0.5359.125) on WINDOWS.

 Received session with ID: 42b25824715f3e4c43c318c4f93d4bc6

. 
 → Running command: navigateTo ('https://en.wikipedia.org/wiki/Main_Page')
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/url  
   { url: 'https://en.wikipedia.org/wiki/Main_Page' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/url (1011ms)
   { value: null }
  → Completed command: navigateTo ('https://en.wikipedia.org/wiki/Main_Page') (1015ms)
. 
 → Running command: customWait ('#mp-tfa-h2_ERROR')

 → Running command: waitForElementVisible ('#mp-tfa-h2_ERROR')
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements  
   { using: 'css selector', value: '#mp-tfa-h2_ERROR' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements (29ms)
   { value: [] }
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements  
   { using: 'css selector', value: '#mp-tfa-h2_ERROR' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements (6ms)
   { value: [] }
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements  
   { using: 'css selector', value: '#mp-tfa-h2_ERROR' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements (9ms)
   { value: [] }
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements  
   { using: 'css selector', value: '#mp-tfa-h2_ERROR' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements (9ms)
   { value: [] }
[8708:9960:0103/112055.797:ERROR:device_event_log_impl.cc(215)] [11:20:55.796] USB: usb_device_handle_win.cc:1045 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[8708:9960:0103/112055.797:ERROR:device_event_log_impl.cc(215)] [11:20:55.797] USB: usb_device_handle_win.cc:1045 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements  
   { using: 'css selector', value: '#mp-tfa-h2_ERROR' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements (9ms)
   { value: [] }
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements  
   { using: 'css selector', value: '#mp-tfa-h2_ERROR' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements (7ms)
   { value: [] }
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements  
   { using: 'css selector', value: '#mp-tfa-h2_ERROR' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements (8ms)
   { value: [] }
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements  
   { using: 'css selector', value: '#mp-tfa-h2_ERROR' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements (8ms)
   { value: [] }
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements  
   { using: 'css selector', value: '#mp-tfa-h2_ERROR' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements (8ms)
   { value: [] }
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements  
   { using: 'css selector', value: '#mp-tfa-h2_ERROR' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements (9ms)
   { value: [] }
   Request POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements  
   { using: 'css selector', value: '#mp-tfa-h2_ERROR' }
   Response 200 POST /session/42b25824715f3e4c43c318c4f93d4bc6/elements (10ms)
   { value: [] }
  ✖ NightwatchAssertError
   Timed out while waiting for element <#mp-tfa-h2_ERROR> to be present for 5000 milliseconds. - expected "visible" but got: "not found" (5210ms)

    Error location:
    C:\Users\Public\nightwatch\customCommands\customWait.js:
    –––––––––––––––––––––––––––––––––––––––––––––––––––––––––
     1 | module.exports = class customWait {
     2 |   async command(selector) {
     3 |     await browser.waitForElementVisible(selector) 
     4 |   }
     5 | }
    –––––––––––––––––––––––––––––––––––––––––––––––––––––––––

  → Completed command: waitForElementVisible ('#mp-tfa-h2_ERROR') (5217ms)
  → Completed command: customWait ('#mp-tfa-h2_ERROR') (5222ms)
  Error
   unhandledRejection: Timed out while waiting for element <#mp-tfa-h2_ERROR> to be present for 5000 milliseconds. - expected "visible" but got: "not found" (5210ms)
    at World.<anonymous> (C:\Users\Public\nightwatch\stepDefinitions\nightwatch.js:8:17)
    at Object.run (C:\Users\Public\nightwatch\node_modules\@cucumber\cucumber\lib\user_code_runner.js:24:27)
    at Object.run (C:\Users\Public\nightwatch\node_modules\@cucumber\cucumber\lib\runtime\step_runner.js:52:59)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async TestCaseRunner.invokeStep (C:\Users\Public\nightwatch\node_modules\@cucumber\cucumber\lib\runtime\test_case_runner.js:94:16)
    at async TestCaseRunner.runStep (C:\Users\Public\nightwatch\node_modules\@cucumber\cucumber\lib\runtime\test_case_runner.js:243:26)
    at async C:\Users\Public\nightwatch\node_modules\@cucumber\cucumber\lib\runtime\test_case_runner.js:174:44
    at async TestCaseRunner.aroundTestStep (C:\Users\Public\nightwatch\node_modules\@cucumber\cucumber\lib\runtime\test_case_runner.js:119:32)
    at async TestCaseRunner.runAttempt (C:\Users\Public\nightwatch\node_modules\@cucumber\cucumber\lib\runtime\test_case_runner.js:157:13)
    at async TestCaseRunner.run (C:\Users\Public\nightwatch\node_modules\@cucumber\cucumber\lib\runtime\test_case_runner.js:135:35)   

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  ️TEST FAILURE (8.218s):
   - 1 error during execution;
   - 0 tests failed;
   - 0/NA tests passed

Nightwatch Configuration

module.exports = {
  src_folders: ['stepDefinitions'],

  custom_commands_path: ['customCommands'],

  test_settings: {
    default: {
      disable_error_log: false,
      launch_url: 'https://en.wikipedia.org/',

      desiredCapabilities: {
        browserName: 'chrome'
      },

      webdriver: { start_process: true },

      test_runner: {
        type: 'cucumber',

        options: {
          feature_path: 'features'
        }
      }
    },

    chrome: {
      desiredCapabilities: {
        'browserName': 'chrome',
        'goog:chromeOptions': { w3c: true }
      },

      webdriver: { start_process: true }
    }
  }
}

Nightwatch.js Version

2.6.4

Node Version

18.4.0

Browser

Chrome Version 108.0.5359.125

Operating System

Windows 10 Enterprise

Additional Information

No response

@asos-saveriocutrupi
Copy link
Author

@memihai This is the issue we encountered, I thought you might be interested.

@asos-saveriocutrupi asos-saveriocutrupi changed the title Nightwatch + Cucumber.js, waitFor-type commands fail when executed inside a custom command Nightwatch + Cucumber.js, waitFor-type commands abort execution when failing inside a custom command Jan 3, 2023
@memihai
Copy link

memihai commented Jan 11, 2023

This error is still a blocker for us too and reproduces in the last Nightwatch version (2.6.8). It's blocking our migration from 0.9 to 2.6 in an extensive framework.

I was able to reproduce it using waitForElementVisible nested in custom commands or chai expect (browser.expect.element(xpath).to.be.visible) type of statements which I presume use waitForElementVisible underneath anyway.

@gravityvi gravityvi self-assigned this Jan 12, 2023
@gravityvi gravityvi added bug cucumber Issues related to Cucumber Test runner labels Jan 12, 2023
@memihai
Copy link

memihai commented Jan 13, 2023

@gravityvi I applied the fix from your commit on my local instance and the problem seems to have gone away. Thanks!
I have other problems now with my migration, but the problem described here seems to be behind us :).

@gravityvi
Copy link
Member

Hey @memihai, You can also join our discord server in case you are facing issues migrating to the updated version of nightwatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cucumber Issues related to Cucumber Test runner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants