Closed boxfoot closed 7 years ago
That's not possible and I'm afraid it's not something we're going to add anytime soon.
Understood. For the benefit of other folks who find this thread, here's a workaround with scripting to accomplish this. (There's probably a more efficient way to do this but this gets the job done)
ALL_NW_ENVS=$(node -e 'var nw = require("./test/nightwatch-conf"); console.log(Object.keys(nw.test_settings).join(","));')
nightwatch -c test/nightwatch-conf.js -e $ALL_NW_ENVS
@boxfoot thanks!
Slightly more concisely,
ALL_NW_ENVS=$(node -p "Object.keys(require('./test/nightwatch-conf').test_settings).join(',')")
@boxfoot Can you please suggest the best practices of specifying environments/and their variables like url, login info, etc( for dev/stage/prod)? Should I use .json or globals.js for better flexibility? Having trouble with understanding this part.
@aamorozov it's really just javascript object manipulation, consensed to the command line.
You could decide what do so, but one option would be to add your environment flags to test settings and then check them:
// in nightwatch.conf
test_settings: {
chrome: {
env: ['prod'],
desiredCapabilities: {
browserName: "chrome",
platform: "Windows 10"
}
},
edge: {
env: ['prod', 'dev'],
desiredCapabilities: {
browserName: "MicrosoftEdge",
platform: "Windows 10"
}
},
firefox: {
env: ['dev'],
desiredCapabilities: {
browser: "firefox",
platform: "Windows 10"
}
},
So the JS to extract your desired tests for 'dev' would look like:
var nw = require("./test/nightwatch-conf")
var desired = Object.keys(nw.test_settings).filter( (test) => nw.test_settings[test].env.includes('dev') )
Which you could then condense to a one-liner:
ALL_NW_ENVS=$(node -p "var nw = require('./test/nightwatch-conf'); Object.keys(nw.test_settings).filter( (test) => nw.test_settings[test].env.includes('dev') ).join(',')")
@boxfoot Thank you for the detailed example, it worked like a charm!
Hello everyone, I am also trying to implement this in my project but didn't work for me. I want to run my tests in Chrome, Firefox, Safari and then based on the environment (which I was thinking to either pass as a parameter) pick the correct url and execute.
I tried: chrome: { env: ['prod'], desiredCapabilities: { browserName: 'chrome', javascriptEnabled: true, acceptSslCerts: true }, selenium: { cli_args: { 'webdriver.chrome.driver': chromedriver.path } } },
but then with this I will have to create 1 for ['dev'] env, and same 2 configs for ['firefox'] etc which is not ideal.
Please suggest me.
@boxfoot , @aamorozov Did the above worked with your project.
Is there a flag to run all test environments? I know that I can specify them by name with
-e env1,env2,env3
but that requires me to know all of the environments that are available...