On BrowserStack, you can run multiple Nightwatch tests at the same time across various browser, device and OS combinations. This is called Parallel Testing. Parallel Testing gives you the same benefits as running a multi-threaded application.
With Parallel Testing, you can run the same test on different browser/device combinations i.e. cross-browser testing, or run different tests on the same or different browser/device combinations. Parallel Testing will help you reduce the run time of your test suite, resulting in faster build times and faster releases.
git clone https://github.com/browserstack/nightwatch-browserstack.git
cd nightwatch-browserstack
npm install
nightwatch-browserstack/conf/parallel.conf.js
file as shown below:nightwatch_config = {
src_folders : [ "tests/single" ], // This test script will run across the multiple browser combinations given below
// Configuring to use BrowserStack hub as the Selenium Hub
selenium : {
"start_process" : false,
"host" : "hub-cloud.browserstack.com",
"port" : 443,
"proxy": "http://PROXY_USERNAME:PROXY_PASSWORD@proxy-host:proxy-port" // If you are behind a proxy
},
// These common capabilities will be same across all the environments where the test would run
common_capabilities: {
'build': 'nightwatch-browserstack',
'browserstack.user': 'YOUR_USERNAME',
'browserstack.key': 'YOUR_ACCESS_KEY',
'browserstack.debug': true
},
// The following are the environments where your test would run.
// You can configure additional capabilities specific to the environment using https://www.browserstack.com/automate/capabilities
test_settings: {
default: {},
chrome: {
desiredCapabilities: {
browser: "chrome"
}
},
firefox: {
desiredCapabilities: {
browser: "firefox"
}
},
safari: {
desiredCapabilities: {
browser: "safari"
}
},
ie: {
desiredCapabilities: {
browser: "internet explorer"
}
}
}
};
// Code to support common capabilities
for(var i in nightwatch_config.test_settings){
var config = nightwatch_config.test_settings[i];
config['selenium_host'] = nightwatch_config.selenium.host;
config['selenium_port'] = nightwatch_config.selenium.port;
config['desiredCapabilities'] = config['desiredCapabilities'] || {};
for(var j in nightwatch_config.common_capabilities){
config['desiredCapabilities'][j] = config['desiredCapabilities'][j] || nightwatch_config.common_capabilities[j];
}
}
module.exports = nightwatch_config;
./node_modules/.bin/nightwatch -c conf/parallel.conf.js -e chrome,firefox,safari,ie
test_settings
variable as shown below:test_settings: {
default: {},
chrome: {
desiredCapabilities: {
"browserName": "chrome",
"browser_version": "latest",
"os": "Windows",
"os_version": "10"
}
},
iPhone: {
desiredCapabilities: {
"device": "iPhone 12 Pro",
"browserName": "iPhone",
"os_version": "14"
}
},
safari: {
desiredCapabilities: {
"browser": "safari",
"browser_version": "latest",
"os": "OS X",
"os_version": "Big Sur"
}
},
samsung: {
desiredCapabilities: {
"device": "Samsung Galaxy S20 Ultra",
"browser": "Android",
"os_version": "10.0"
}
}
}
And you can invoke the parallel tests using the command below:
./node_modules/.bin/nightwatch -c conf/parallel.conf.js -e chrome,iPhone,safari,samsung
You can visit BrowserStack Automate Dashboard and see your test there once it has successfully completed.
browserName: 'iPhone'
or browserName: 'android'
under the desiredCapabilities
section.desiredCapabilities
section of parallel.conf.js
file.
Note: Achieve your test coverage and build execution time goals by using our calculator to understand how many parallel sessions you need.
Contact our Support team for immediate help while we work on improving our docs.
Contact our Support team for immediate help while we work on improving our docs.
Thank you for your valuable feedback!