Reputation: 3392
I am tasked with pushing out a nightwatch report to sharepoint. I have it all working I just need to get the test_settings name in the globals.js file's 'after' method so after the test completes and the report is generated I can name it by the date-env-user.
Background:
I am using a env.json
file for all the consistent environment variables between environments.
In my nightwatch.conf.js
file I have multiple 'test_settings' environments like 'local', 'qa', etc.
I want to get that value 'local' or 'qa' when I am in the globals.js
file's 'after()' method.
I tried process.env.environment, browser.globals.environment (but 'browser' is not available in globals.js
). I also tried some other variations from other articles I found, to no avail.
Here's my nightwatch.conf.js
pertinent test_Settings values:
"test_settings": {
"local": {
"launch_url":"http://example.local",
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": './reports/screenshots/local' // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome"
}
},
"qa": {
"launch_url": "https://qa.example.com",
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": './reports/screenshots/qa' // save screenshots here
},
"globals": {
"waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
},
"desiredCapabilities": { // use Chrome as the default browser for tests
"browserName": "chrome"
}
},
and this is a example command line I am calling tests with
node_modules/.bin/nightwatch --env local --config nightwatch.conf.BASIC.js --test test\e2e\search.js --reporter ./report s/reporter.js
I want to extract 'local' or 'qa' from inside the globals.js/after()
method.
again, but 'browser' is not available.
Thank you.
Upvotes: 0
Views: 355
Reputation: 142
I'm gonna share the way we do it in our project and hope this applies to you as well:
let activeEnvironment = require("minimist")(process.argv)["env"];
This way you can save the given environment variable. If that doesnt work in the 'after' method, you could write this to a temp file and read it in the 'after' mehtod.
Hope this helps.
Upvotes: 1