问题
At my current company, we have about 10 websites.. That all extend from a single codebase.
Whenever we change something in the 'core' codebase, we want to run tests on all 10 websites in parallel. Its a lot easier in the cloud, but we also want to be able to do it locally.
For this to happen, I basically start multiple Selenium instances, all with its own port, and set a different nightwatch launch_url for every instance
So I made a NodeJS script.. That creates a nightwatch.json for every site, each holding its own launch_url and selenium port.. And spawns nightwatch 10 times referring to its own json config file.
But I wonder if thats the 'correct' approach.
Does Selenium Grid solve this problem? Also for local testing?
Thanks!
回答1:
Selenium grid is designed to be able to handle multiple parallel sessions.
You should have just one selenium hub with one or more selenium nodes.
Start your selenium node with extra params -browser
example
java -jar selenium_server.jar -Dwebdriver.chrome.driver=$CHROMEDRIVER -role node -hub http://localhost:4444/grid/register -maxSession 20 -browser browserName=chrome,maxInstances=10 -browser browserName=firefox,maxInstances=10"
(for difference between maxSession vs maxInstances check this one: Selenium Grid: MaxSessions vs MaxInstances)
All your tests could be configured to use the same selenium hub instance.
回答2:
Selenium grid won't solve your problem. Because selenium grid runs the same test cases over different instances. Selenium grid is used to check whether these test cases are compatible with different browsers, version of browsers or different OS. Check Selenium grid: http://www.seleniumhq.org/docs/07_selenium_grid.jsp
And in your case, you want to run test cases for different url's, therefore there are 10 different test cases set.
You are doing it right, "So I made a NodeJS script.. That creates a nightwatch.json for every site, each holding its own launch_url and selenium port.. And spawns nightwatch 10 times referring to its own json config file."
You can run each test case set in parallel by setting test_workers. Example: "test_workers" : {"enabled" : true, "workers" : "auto"}. Check test_workers to run test case in parallel http://nightwatchjs.org/gettingstarted/#basic-settings
Correct me if I am wrong.
回答3:
If you want cloud solution, nightwatch works really well with browserstack or saucelabs in the nightwatch.json file
"selenium" : {
"start_process" : true,
"server_path" : "lib/selenium/selenium-server-standalone-2.53.0.jar",
"start_session" : true,
"log_path" : "log/",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "lib/drivers/chromedriver"
}
},
"test_settings" : {
"bstk" : {
"launch_url": "http://hub.browserstack.com",
"selenium_port" : 80,
"selenium_host" : "hub.browserstack.com",
"silent": true,
"screenshots": {
"enabled": false,
"path": ""
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"browserstack.user": "username",
"browserstack.key": "..."
}
},
来源:https://stackoverflow.com/questions/38721599/running-multiple-nightwatch-instances