I'm writing tests for Browserstack using nightwatchJS.
My nightwatch.json looks like that:
{
"src_folders": [
"..."
],
"tests_output": "test/tests_output/",
"detailed_output": true,
"selenium": {
"start_process": false,
"host": "hub.browserstack.com",
"port": 80
},
"test_workers": {
"enabled": true,
"workers": 2
},
"test_settings": {
"ie7": {
"selenium_port": 80,
"selenium_host": "hub.browserstack.com",
"silent": true,
"desiredCapabilities": {
"os": "Windows",
"os_version": "XP",
"browserName": "IE",
"version": "7",
"resolution": "1024x768",
"javascriptEnabled": true,
"acceptSslCerts": true,
"browserstack.local": "true",
"browserstack.video": "true",
"browserstack.debug": "true",
"browserstack.localIdentifier": "<localIdentifier>",
"browserstack.user": "<userName>",
"browserstack.key": "<userkey>"
}
},
"ie8": {
"selenium_port": 80,
"selenium_host": "hub.browserstack.com",
"silent": true,
"desiredCapabilities": {
"os": "Windows",
"os_version": "7",
"browserName": "IE",
"version": "8",
"resolution": "1024x768",
"javascriptEnabled": true,
"acceptSslCerts": true,
"browserstack.local": "true",
"browserstack.video": "true",
"browserstack.debug": "true",
"browserstack.localIdentifier": "<localIdentifier>",
"browserstack.user": "<userName>",
"browserstack.key": "<userkey>"
}
},
"chrome": {
"selenium_port": 80,
"selenium_host": "hub.browserstack.com",
"silent": true,
"desiredCapabilities": {
"os": "Windows",
"os_version": "10",
"browserName": "chrome",
"resolution": "1024x768",
"javascriptEnabled": true,
"acceptSslCerts": true,
"browserstack.local": "true",
"browserstack.video": "true",
"browserstack.debug": "true",
"browserstack.localIdentifier": "<localIdentifier>",
"browserstack.user": "<userName>",
"browserstack.key": "<userkey>"
}
},
//Similar blocks for other platforms
}
}
It's the classic way to define a configuration file. As you can remark there are a lot of redundant information in each platform: localIdentifier, userName, userkey...etc
My question: Is there a way to optimize the configuration file? So when I want for example to change my userKey or browserstack.debug, I change it only in one place and avoid mistakes?
Thanks to the comment of @Mukesh-Tiwari I was able to optimize my nightwatch.json file. I'm sharing the idea:
In the example above, I'm defining
selenium_host
,selenium_port
at 1 place so if I need to change them I just touch only 1 line of code.Thanks again for Mukesh-Tiwari.
Imprtant
To make it works, you need to change your configuration file from
nightwatch.json
tonightwatch.js
because we are using a JS code.