So I'm trying to run the nightwatch mocha sample test, and I get the following error:
└─[$] nightwatch -c nightwatch.js -g test/e2e --env default ◈ (ruby-2.2.1) ⧂ (go1.4) ⬡ (node-5.3.0) [16:07:56]
ERROR SyntaxError: Unexpected token :
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object.CliRunner.readSettings (/Users/therebelrobot/.nvm/versions/node/v5.3.0/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:89:23)
at Object.CliRunner.setup (/Users/therebelrobot/.nvm/versions/node/v5.3.0/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:49:8)
at Object.exports.runner (/Users/therebelrobot/.nvm/versions/node/v5.3.0/lib/node_modules/nightwatch/lib/index.js:540:17)
ERROR There was an error while starting the test runner:
Error: No testing environment specified.
at Object.CliRunner.parseTestSettings (/Users/therebelrobot/.nvm/versions/node/v5.3.0/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:441:13)
at Object.CliRunner.setup (/Users/therebelrobot/.nvm/versions/node/v5.3.0/lib/node_modules/nightwatch/lib/runner/cli/clirunner.js:51:8)
at Object.exports.runner (/Users/therebelrobot/.nvm/versions/node/v5.3.0/lib/node_modules/nightwatch/lib/index.js:540:17)
at /Users/therebelrobot/.nvm/versions/node/v5.3.0/lib/node_modules/nightwatch/bin/runner.js:9:16
at Object.exports.cli (/Users/therebelrobot/.nvm/versions/node/v5.3.0/lib/node_modules/nightwatch/lib/index.js:534:5)
at Object.<anonymous> (/Users/therebelrobot/.nvm/versions/node/v5.3.0/lib/node_modules/nightwatch/bin/runner.js:8:14)
at Module._compile (module.js:398:26)
at Object.Module._extensions..js (module.js:405:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
Here is my nightwatch.js:
{
"src_folders" : ["test/e2e"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"test_runner" : {
"type" : "mocha",
"options" : {
"ui" : "bdd",
"reporter" : "list"
}
},
"selenium" : {
"start_process" : false,
"server_path" : "",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "",
"webdriver.ie.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : true,
"path" : "reports/error-screenshots"
},
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome" : {
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
and the only test, test/e2e/tester.js:
describe('Google demo test for Mocha', function () {
describe('with Nightwatch', function () {
before(function (client, done) {
done()
})
after(function (client, done) {
client.end(function () {
done()
})
})
afterEach(function (client, done) {
done()
})
beforeEach(function (client, done) {
done()
})
it('uses TDD to run the Google simple test', function (client) {
client
.url('http://google.com')
.expect.element('body').to.be.present.before(1000)
client.setValue('input[type=text]', ['nightwatch', client.Keys.ENTER])
.pause(1000)
.assert.containsText('#main', 'Night Watch')
})
})
})
I'm not sure if I missing something? I've got nightwatch installed globally, and made sure my selenium server is running while I do this. Here are my environment details:
omg. I'm moronic. It was a problem with the nightwatch.js file, it's supposed to be a json file. changed the extension, working like a charm.
Thanks @therebelrobot. I made the same error and your comment saved me from additional headbanging.
Most helpful comment
omg. I'm moronic. It was a problem with the
nightwatch.jsfile, it's supposed to be ajsonfile. changed the extension, working like a charm.