Nightwatch - Use chromedriver

chrismillah picture chrismillah · May 22, 2015 · Viewed 14.3k times · Source

So i saw a similar question on stack here but it did not have an accepted answer nor did it provide me with the information i needed..

I am trying to use 'chromedriver' because 'selenium-webdriver' requires a FF version <= 28.

What i've done so far.

  • nightwatch.js tests running fine in FF
  • downloaded chromedriver (npm install chromedriver -g) and also npm install chromedriver into my nightwatch project directory
  • went to nightwatch/bin/nightwatch.json and edited the following code

     "selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "/usr/local/bin/chromedriver", <= added this - is this the binary?
      "webdriver.ie.driver" : "",
      "webdriver.firefox.profile" : ""
    }},
    

also tried to update the settings for selenium to have a start_process=true and server_path

 "selenium" : {
    "start_process" : true,
    "server_path" : "../selenium-server-standalone-2.39.0.jar",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "/usr/local/bin/chromedriver",
      "webdriver.ie.driver" : "",
      "webdriver.firefox.profile" : ""
    }
  },

Not sure if im pointing to the proper chromedriver file/folder

also edited the test settings

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_host" : "127.0.0.1",
      "selenium_port" : 4444,
      "silent" : true,
      "disable_colors": false,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities" : {
        "browserName" : "chrome",   <= changed this from ff to chrome
        "javascriptEnabled" : true,
        "acceptSslCerts" : true
      }
    },

If i go to run the test (without a -e <browser>) e.g. nightwatch -g <group>, it launches fine in FF and runs..

If i try to specify the chrome browser (-e chrome) nightwatch -g <group> -e chrome i get the following error

ERROR There was an error while starting the test runner:


Error: Invalid testing environment specified: chrome
    at Object.CliRunner.parseTestSettings (/usr/local/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:354:15)
    at Object.CliRunner.init (/usr/local/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:31:8)
    at module.exports.runner.runner (/usr/local/lib/node_modules/nightwatch/lib/index.js:512:19)
    at /usr/local/lib/node_modules/nightwatch/bin/runner.js:9:16
    at module.exports.cli.cli (/usr/local/lib/node_modules/nightwatch/lib/index.js:504:7)
    at Object.<anonymous> (/usr/local/lib/node_modules/nightwatch/bin/runner.js:8:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

The questions i have are:

  1. How do i point to the binary file (not sure which it is)

  2. Are my settings in nightwatch.js correct? How is it running in FF if i changed the test_settings 'browserName = Chrome"?

  3. Am i missing something here?

Thanks in advance

Answer

Juhi Saxena picture Juhi Saxena · May 28, 2015

First you said

I am trying to use 'chromedriver' because 'selenium-webdriver' requires a FF version <= 28.

Its because you are using selenium-server-standalone-2.39.0.jar (Old jar) Please download new one from here selenium-server-standalone-2.45.0.jar Second Download chrome driver from here Chromedriver basis on your environment

Third update your nightwatch.json with below code

{
"src_folders": [
    "tests"
],
"selenium": {
    "start_process": false,
    "server_path": "bin/selenium-server-standalone-2.45.0.jar",
    "log_path": "",
    "host": "127.0.0.1",
    "port": 4444,
    "cli_args": {
        "webdriver.chrome.driver": "bin/chromedriver",
        "webdriver.ie.driver": ""
    }
},
"test_settings": {
    "default": {
        "launch_url": "http://127.0.0.1/",
        "selenium_port": 4444,
        "selenium_host": "localhost",
        "silent": true,
        "screenshots": {
            "enabled": false,
            "path": ""
        },
        "desiredCapabilities": {
            "browserName": "firefox",
            "javascriptEnabled": true,
            "acceptSslCerts": true
        }
    },
    "chrome": {
        "desiredCapabilities": {
            "browserName": "chrome",
            "javascriptEnabled": true,
            "acceptSslCerts": true
        }
    }
}

}

Fourth run your group with nightwatch -g -e chrome

Hope It will solve your problem.