nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

Extending nightwatch.json with npm config #763

Closed munkyjunky closed 8 years ago

munkyjunky commented 8 years ago

Is it possible to extend nightwatch.json properties with npm config values (or similar)?

I'm running nightwatch tests against browserstack, passing browserstack.user and browserstack.key in the desiredCapabilities of the environment. However, due to information security policies at my work I can't store the browserstack key in source control - ideally I need a way to pass this in at run time.

Is there any method which allows for passing of specific parameters in?

sknopf commented 8 years ago

You could pass the key as an environment variable: 'browserstack.key': '${BROWSERSTACK_KEY}'

johnboxall commented 8 years ago

Alternatively you can also supply a .js config file and construct your configuration JSON dynamically!

munkyjunky commented 8 years ago

Thanks guys!

@sknopf Didn't see that in the nightwatch docs - only found it after doing a search for ${. May be worth an update to the documentation to say that it can be used for any key.

@johnboxall Tried that, and it just opens the config file in my editor (I renamed nightwatch.json to nightwatch.js and added a module.exports). However, if I rename it to nightwatch.config.js and passed this in with the -c flag it all works!

Both of your suggestions have solved my issue, but I think the documentation could maybe expand on this a little more (unless I'm just a poor reader...). If I get chance, I'll make a pull request on the docs for this!

beatfactor commented 8 years ago

If you have a nightwatch.conf.js it will be loaded automatically, without having to specify the -c option.

On Thursday, December 3, 2015, Simon W notifications@github.com wrote:

Thanks guys!

@sknopf https://github.com/sknopf Didn't see that in the nightwatch docs - only found it after doing a search for ${. May be worth an update to the documentation to say that it can be used for any key.

@johnboxall https://github.com/johnboxall Tried that, and it just opens the config file in my editor (I renamed nightwatch.json to nightwatch.js and added a module.exports). However, if I rename it to nightwatch.config.js and passed this in with the -c flag it all works!

Both of your suggestions have solved my issue, but I think the documentation could maybe expand on this a little more (unless I'm just a poor reader...). If I get chance, I'll make a pull request on the docs for this!

— Reply to this email directly or view it on GitHub https://github.com/nightwatchjs/nightwatch/issues/763#issuecomment-161557882 .

quantuminformation commented 8 years ago

I have to be able to get Macs and windows computers to run these tests locally, is there a way to change the setting in the nightwatch.json so that the the correct driver will be loaded, or do I need to have 2 separate config files with the switching logic in the nightwatch.conf.js with a env variable passed in?

mac needs:

 "cli_args" : {
      "webdriver.chrome.driver" : "bin/chromedriver 2"

windows needs:

 "cli_args" : {
      "webdriver.chrome.driver" : "bin/chromedriver.exe"
sharadJay commented 8 years ago

use process.platform in nightwatch.conf.js to check which platform your test is running and then switch chromedriver path. Something like this:-

//Setting chromedriver path at runtime to run on different architectures
    if (process.platform === "darwin") {
        settings.selenium.cli_args["webdriver.chrome.driver"] = "Lib/chromedriver";
    }
    else if (process.platform === "win32" || process.platform === "win64") {
        settings.selenium.cli_args["webdriver.chrome.driver"] = "Lib/WindowsDrivers/chromedriver.exe";
    }
quantuminformation commented 8 years ago

Ah very nice, thanks!

beatfactor commented 8 years ago

Or overwrite cli_args per test_settings environment.