1

I can't run nightwatch to run tests on chrome.

Here is my modified nightwatch.json that I downloaded from the nightwatch example:

{
  "src_folders" : ["./examples/tests"],
  "output_folder" : "./examples/reports",
  "custom_commands_path" : "./examples/custom-commands",
  "custom_assertions_path" : "",
  "globals_path" : "./examples/globals.json",
  "live_output" : false,

  "selenium" : {
    "start_process" : false,
    "server_path" : "/lib/sel-serv.jar",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "/lib/chromedriver/chromedriver.exe",
      "webdriver.ie.driver" : "",
      "webdriver.firefox.profile" : ""
    }
  },

  "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" : ""
      },
      "chrome":{
      "desiredCapabilities" : {
        "browserName" : "chrome",
        "javascriptEnabled" : true,
        "acceptSslCerts" : true
      }
      }
    },


      "desiredCapabilities": {
        "name" : "test-example",
        "browserName": "chrome"
      },
      "globals" : {
        "myGlobal" : "some_sauce_global"
      },
      "selenium" : {
        "start_process" : false
      }
  }
}

And I get this error message:

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:448:15)
    at Object.CliRunner.init (/usr/local/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:49:8)
    at module.exports.runner.runner (/usr/local/lib/node_modules/nightwatch/lib/index.js:546:17)
    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:5)
    at Object.<anonymous> (/usr/local/lib/node_modules/nightwatch/bin/runner.js:8:14)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)

I also found a older post that says you have to create new file in root directory so give it a try and nothing happened

xkcd149
  • 842
  • 1
  • 11
  • 17
Andrew
  • 98
  • 1
  • 3
  • 13

6 Answers6

3

I think you need a dot before lib:

"webdriver.chrome.driver" : "./lib/chromedriver/chromedriver.exe",

also the selenium.jar:

"server_path" : "./lib/sel-serv.jar",
xkcd149
  • 842
  • 1
  • 11
  • 17
Bao Tran
  • 618
  • 4
  • 15
2

Selenium server jar path and chrome driver (.exe) path is not set correctly. Use dot(".") to represent your working directory before setting path. Or remove the forward slash("/") before chrome driver and selenium server jar file path.

You have to run Selenium server standalone jar file manually because you have not set "start_process" to "true". Check Selenium Configuration here : http://nightwatchjs.org/gettingstarted/

You have set start_process property to false two times. Remove the last element from json file. ("selenium" : { "start_process" : false })

Also check browser version and driver are compatible or not, before you start execution.(Check the readme file from where you have downloaded the driver. Top line in readMe file will have browser compatibility versions).

Niraj Tathe
  • 181
  • 2
  • 8
1

just check the configuration file and put the chrome object from out of the default object like,

     "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" : ""
  }
  },
    "chrome":{
  "desiredCapabilities" : {
    "browserName" : "chrome",
    "javascriptEnabled" : true,
    "acceptSslCerts" : true
  }
},

    like this....have a blast
Venu.p
  • 71
  • 7
0

If your chromedriver and selenium standalone jar are in the files you are pointing to, then I think you are only missing the config to start the server before tests run. See the line...

"start_process" : false,

You need to set that to true like so...

"start_process" : true,

Unless you plan to start the server manually before you run the tests. Once that is done, consider the paths as was mentioned above. Depending if running on Windows, Mac or Linux; this can require the . in front of the /.

Shane
  • 1,629
  • 3
  • 23
  • 50
0

Nightwatch configuration for chrome driver will be-

{
  "src_folders" : ["tests"],
  "output_folder" : "reports",
  "page_objects_path": "./pages",
  "selenium" : {
    "start_process" : true,
    "server_path" : "./bin/selenium-server-standalone-3.4.0.jar",
    "log_path" : "",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "./bin/chromedriver"
    }
  },
  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

Here, chrome has been made default broswer.

Priyaranjan
  • 187
  • 1
  • 1
  • 9
0
  "selenium": {
    "start_process": true,
    "server_path": "./lib/drivers/selenium-server-standalone-3.141.59.jar",
    "log_path": "",
    "host": "127.0.0.1",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "./lib/drivers/chromedriver.exe",
      "webdriver.gecko.driver": "",
      "webdriver.edge.driver": ""
    }
  },

You supposed to write in your nightwatch.json like that. Additionally make sure that your web-driver is in the same version like your chrome browser (if it will not be in the same version it will not run, and not give you any error message)

Steve.g
  • 448
  • 4
  • 5