nightwatch: Upgrading from 0.9.x to 1.0.8 throws an error on waitForElementVisible

My current scenario is that I am in the process of upgrading our test repository from 0.9 -> 1.0 however after following the wiki and getting the tests to start, some basic actions are performed correctly, such as navigating to the right page and providing feedback on that. However when the tests hit a waitForElementVisible the console reports the error Error while running .isElementDisplayed() protocol action: undefined.

The test steps are as follows:

var page = browser.page.testPage();

page.navigate();

page.waitForElementVisible('@testPanel');

Running the command with --verbose reports:

Running command: waitForElementVisible
   Request POST  /session/0d03be1f5a8319f7565664c337a0c881/elements
   { using: 'css selector', value: '#test-panel' }
   Response 200 POST /session/0d03be1f5a8319f7565664c337a0c881/elements (18ms)
   { sessionId: '0d03be1f5a8319f7565664c337a0c881',
     status: 0,
     value: [ { ELEMENT: '0.03954989682254517-1' } ] }
 Error while running .isElementDisplayed() protocol action: undefined

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 34 (12 by maintainers)

Commits related to this issue

Most upvoted comments

@beatfactor

Getting the same error through BrowserStack only.

Error while running .isElementDisplayed() protocol action: undefined

Here’s my config for Browserstack:

const selenium = {
  host: process.env.SELENIUM_HOST,
  port: process.env.SELENIUM_PORT
}

const nightwatchConfig = {
  src_folders: ['./test/e2e/tests'],
  output_folder: ['./test/e2e/reports'],
  selenium: {
    start_process: false,
    host: selenium.host,
    port: selenium.port
  },
  test_settings: {
    default: {
      desiredCapabilities: {
        'browserstack.user': process.env.BROWSERSTACK_USERNAME,
        'browserstack.key': process.env.BROWSERSTACK_ACCESS_KEY,
        'browserstack.local': true,
        'resolution': '1440x900',
        'os': 'Windows',
        'os_version': '10',
        'browserName': 'Chrome',
        'browser_version': '62.0',
        'browserstack.selenium_version': '3.11.0',
        'build': `${process.env.BROWSERSTACK_BUILD_NAME}`
      },
      skip_testcases_on_fail: false,
      screenshots: {
        enabled: true,
        path: './test/e2e/screenshots'
      }
    }
  }
}

// Code to copy seleniumhost/port into test settings
for (var i in nightwatchConfig.test_settings) {
  var config = nightwatchConfig.test_settings[i]
  config.webdriver = {
    webdriver_host: selenium.host,
    webdriver_port: selenium.port
  }
}

module.exports = nightwatchConfig

Browserstack settings:

browserName Chrome
acceptSslCerts true
resolution 1440x900
os Windows
os_version 10
browser_version 62.0
build 66108
name Global/Navbar
acceptSslCert true
browserstack.console errors
browserstack.appiumLogs false
browserstack.local true
browserstack.selenium_version 3.11.0

And this is my local config that I use before pushing. And in my local config, it works as expected.

nightwatch_config = {
  src_folders : ['./test/e2e/tests'],
  output_folder : ['./test/e2e/reports'],
  custom_commands_path : '',
  custom_assertions_path : '',
  page_objects_path : '',
  globals_path : '',

  selenium: {
    start_process : true,
    server_path : './test/e2e/bin/selenium-server-standalone-3.12.0.jar',
    log_path : '',
    port : 4444,
    cli_args : {
      'webdriver.chrome.driver': './test/e2e/bin/chromedriver',
      'webdriver.gecko.driver': './test/e2e/bin/geckodriver'
    }
  },
  test_settings : {
    default : {
      launch_url : 'http://.../offers',
      webdriver: {
        webdriver_host: 'localhost',
        webdriver_port: 4444
      },
      silent: true,
      screenshots : {
        enabled : true,
        path : './test/e2e/screenshots'
      },
      globals: {
        devServerURL: 'http://.../offers'
      },
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        elementScrollBehavior: 1
      }
    },

    chrome : {
      desiredCapabilities: {
        browserName: 'chrome',
        javascriptEnabled: true,
        acceptSslCerts: true,
        elementScrollBehavior: 1
      }
    },
    firefox: {
      desiredCapabilities: {
        browserName: 'firefox',
        javascriptEnabled: true,
        acceptSslCerts: true,
        marionnette: true,
        elementScrollBehavior: 1
      }
    }
  }
};

module.exports = nightwatch_config

@Everlag There will be a fix for edge posted this week.

@beatfactor The problem still exists on 1.0.11while using the Edge browser (using BrowserStack) BTW, Chrome and Firefox work fine on latest. Also, if revert to 0.9.x everything works including Edge

Connecting local
Connected. Now testing...

[Signon Owner Test] Test Suite
==============================
   Request POST http://hub-cloud.browserstack.com /wd/hub/session
   { desiredCapabilities:
      { browserName: 'Edge',
        acceptSslCerts: true,
        platform: 'ANY',
        'browserstack.user': 'khoyzvbigetkfxr1',
        'browserstack.key': 'unHo2zCaNHPVEXVyHUCx',
        'browserstack.local': true,
        'browserstack.debug': true,
        build: '1.1',
        name: 'Signon Owner Test' } }
   Response 200 POST http://hub-cloud.browserstack.com/wd/hub/session (4980ms)
   { state: null,
     sessionId: 'a495917005efc0660569a11a1d2f713969d426db',
     value:
      { applicationCacheEnabled: true,
        InPrivate: false,
        pageLoadStrategy: 'normal',
        platform: 'ANY',
        acceptSslCerts: true,
        'webdriver.remote.sessionid': 'a495917005efc0660569a11a1d2f713969d426db',
        browserVersion: '41.16299.15.0',
        platformVersion: '10',
        locationContextEnabled: true,
        webStorageEnabled: true,
        browserName: 'MicrosoftEdge',
        takesScreenshot: true,
        takesElementScreenshot: true,
        javascriptEnabled: true,
        platformName: 'windows',
        cssSelectorsEnabled: true },
     status: 0 }
 Received session with ID: a495917005efc0660569a11a1d2f713969d426db
...

 → Running command: waitForElementVisible
   Request POST http://hub-cloud.browserstack.com /wd/hub/session/c96c91ccacb1532041fbf7834703fb5a45d38d36/elements
   { using: 'css selector', value: 'body' }
   Response 200 POST http://hub-cloud.browserstack.com/wd/hub/session/c96c91ccacb1532041fbf7834703fb5a45d38d36/elements (431ms)
   { state: 'success',
     sessionId: 'c96c91ccacb1532041fbf7834703fb5a45d38d36',
     value: [ { ELEMENT: '0' } ],
     status: 0 }
 Error while running .isElementDisplayed() protocol action: TypeError: Error while trying to create HTTP request for "/wd/hub/session/c96c91ccacb1532041fbf7834703fb5a45d38d36/element/[object Object]/displayed": Request path contains unescaped characters
    at new ClientRequest (_http_client.js:127:13)
    at Object.request (http.js:38:10)

The probem seems to be on the URL, see the [object object]

/wd/hub/session/a495917005efc0660569a11a1d2f713969d426db/element/[object Object]/displayed

@gmcdev no problem. I should add browser as an alias as well, or at least show an error message.

@beatfactor same config as my previous post – thanks for looking into it!

We are coming across similar problems with waitForElementVisible() in Chrome environments. Everything was working fine until earlier this week.

We have scaled back to the sample Browserstack test, here: https://www.browserstack.com/automate/nightwatch#sample-test

Same problem in Chrome v60-69 (letting Browserstack pick Chromedriver).

Works fine in Firefox on Browserstack.

Works intermittently when running Selenium/Chromedriver/Chrome.app installed locally on OSX.

{  
   "selenium":{  
      "start_process":false,
      "host":"hub-cloud.browserstack.com",
      "port":80
   },
   "test_settings":{  
      "default":{  
         "selenium_host":"hub-cloud.browserstack.com",
         "selenium_port":80,
         "desiredCapabilities":{  
            "screenshots":{  
               "enabled":true,
               "on_failure":true,
               "on_error":true,
               "path":"./reports/screenshots"
            },
            "resolution":"1280x1024",
            "browserstack.user":"XXXX",
            "browserstack.key":"XXXX",
            "browserstack.local":true
         }
      },
      "osx_hs_chrome":{  
         "desiredCapabilities":{  
            "os":"OS X",
            "os_version":"High Sierra",
            "browser":"Chrome",
            "browser_version":"68.0",
            "chromeOptions":{  
               "args":[  
                  "auto-open-devtools-for-tabs"
               ]
            }
         }
      },
      "osx_hs_firefox":{  
         "desiredCapabilities":{  
            "os":"OS X",
            "os_version":"High Sierra",
            "browser":"Firefox",
            "browser_version":"61.0"
         }
      }
   }
}

And the result:

[Main Test] Test Suite
======================
Running:  Google's Search Functionality

 Error while running .isElementDisplayed() protocol action: undefined

 Error while running .isElementDisplayed() protocol action: undefined

 Error while running .isElementDisplayed() protocol action: undefined

✖ Timed out while waiting for element <body> to be visible for 1000 milliseconds. - expected "visible" but got: "not visible"
    at Object.Google's Search Functionality (/Users/greg.connell/Documents/_NETFLIX/da-testing-framework/tests/active/containers/raw-source/wc-netflix-text/main.test.js:5:8)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:118:7)

   An error occurred while running .setValue() command on <input[type=text]>: Error: First argument passed to .elementIdValue() should be a web element ID string. Received object.
      at Function.validateElementId (/Users/greg.connell/Documents/_NETFLIX/da-testing-framework/node_modules/nightwatch/lib/api/protocol.js:36:19)
      at ProtocolActions.elementIdValue (/Users/greg.connell/Documents/_NETFLIX/da-testing-framework/node_modules/nightwatch/lib/api/protocol.js:945:25)
      at transport.locateElement.then.result (/Users/greg.connell/Documents/_NETFLIX/da-testing-framework/node_modules/nightwatch/lib/api-loader/element-command.js:106:54)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:118:7)
       at <anonymous>
       at process._tickCallback (internal/process/next_tick.js:118:7)
       at <anonymous>
       at process._tickCallback (internal/process/next_tick.js:118:7)
✖ Testing if the page title equals "BrowserStack - Google Search". - expected "BrowserStack - Google Search" but got: "Google"
    at Object.Google's Search Functionality (/Users/greg.connell/Documents/_NETFLIX/da-testing-framework/tests/active/containers/raw-source/wc-netflix-text/main.test.js:8:15)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:118:7)


FAILED: 2 assertions failed and  1 errors (3.253s)
   Testing if the page title equals "BrowserStack - Google Search". - expected "BrowserStack - Google Search" but got: "Google"
       at <anonymous>
       at process._tickCallback (internal/process/next_tick.js:118:7)
_________________________________________________

TEST FAILURE: 1 error during execution 2 assertions failed, 0 passed. 24.233s

 ✖ main.test
 – Google's Search Functionality (3.253s)
   Timed out while waiting for element <body> to be visible for 1000 milliseconds. - expected "visible" but got: "not visible"
       at Object.Google's Search Functionality (/Users/greg.connell/Documents/_NETFLIX/da-testing-framework/tests/active/containers/raw-source/wc-netflix-text/main.test.js:5:8)
       at <anonymous>
       at process._tickCallback (internal/process/next_tick.js:118:7)
   Testing if the page title equals "BrowserStack - Google Search". - expected "BrowserStack - Google Search" but got: "Google"
       at Object.Google's Search Functionality (/Users/greg.connell/Documents/_NETFLIX/da-testing-framework/tests/active/containers/raw-source/wc-netflix-text/main.test.js:8:15)
       at <anonymous>
       at process._tickCallback (internal/process/next_tick.js:118:7)

  An error occurred while running .setValue() command on <input[type=text]>: Error: First argument passed to .elementIdValue() should be a web element ID string. Received object.
      at Function.validateElementId (/Users/greg.connell/Documents/_NETFLIX/da-testing-framework/node_modules/nightwatch/lib/api/protocol.js:36:19)
      at ProtocolActions.elementIdValue (/Users/greg.connell/Documents/_NETFLIX/da-testing-framework/node_modules/nightwatch/lib/api/protocol.js:945:25)
      at transport.locateElement.then.result (/Users/greg.connell/Documents/_NETFLIX/da-testing-framework/node_modules/nightwatch/lib/api-loader/element-command.js:106:54)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:118:7)
       at <anonymous>
       at process._tickCallback (internal/process/next_tick.js:118:7)
       at <anonymous>
       at process._tickCallback (internal/process/next_tick.js:118:7)

I’m not convinced this is a Nightwatch issue, so apologies for posting here, if it’s not. We’ll keep digging tomorrow.