Set up Selenium Grid2 on Windows (for testing with IE, Safari, Chrome/Opera, and Firefox)
Update: If you have an Amazon Web Services (AWS) account, here's a nice CloudFormation template that will do everything for you!
~~~~~~~~~~~
Confused by Selenium? You're not the only one! There are many Selenium guides out there but I couldn't find any that provided a complete tutorial for installing it on Windows for IE, Safari, Chrome, and Firefox testing so I thought I'd document my process with Windows Server 2008 R2:
1. login to Windows with an account that has administrator rights
2. if not already open, click on Start and search for Server Manager to open; then click on Configure IE ESC link (in the Security Information section) and turn off IE ESC for both Administrators and Users
3. if not already done, use this guide to show file extensions and hidden folders
4. install Java
5. install Chrome
6. install Firefox
7.
8. create a folder in C:\ called selenium and download http://selenium-release.storage.googleapis.com/2.41/selenium-server-standalone-2.41.0.jar into it
9. download and extract the InternetExplorerDriver and ChromeDriver drivers into the C:\selenium folder (Notes: Use the 32-bit versions even if your Windows OS is 64-bit because even if your OS is 64-bit, browsers run as 32-bit. The Firefox and Safari drivers are already included in the selenium-server-standalone.jar file as pre-built extensions. Opera uses the same engine as Chrome so you don't have to run separate tests for it.)
10. click Start and search for Edit the system environment variables to open the System Properties dialog, then click the Environment Variables... button, then click on the Path variable in the System variables list and click the Edit... button. At the end of the Variable value textbox add:
;C:\Program Files (x86)\Java\jre7\bin\;C:\selenium\11. restart Windows
12. create a file called hub.json in the C:\selenium folder with the following contents:
{
"host": null,
"port": 4440,
"newSessionWaitTimeout": -1,
"servlets" : [],
"prioritizer": null,
"capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
"throwOnCapabilityNotPresent": true,
"nodePolling": 5000,
"cleanUpCycle": 5000,
"timeout": 300000,
"browserTimeout": 0,
"maxSession": 5,
"jettyMaxThreads":-1
}
13. create a file called node.json in the C:\selenium folder with the following contents:
{
"capabilities":[
{
"platform": "WINDOWS",
"browserName": "firefox",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
},{
"platform": "WINDOWS",
"browserName": "chrome",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
},{
"platform": "WINDOWS",
"browserName": "internet explorer",
"version": "11",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
},{
"platform": "WINDOWS",
"browserName": "internet explorer",
"version": "10",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
},{
"platform": "WINDOWS",
"browserName": "internet explorer",
"version": "9",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
},{
"platform": "WINDOWS",
"browserName": "internet explorer",
"version": "8",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
},{
"platform": "WINDOWS",
"browserName": "safari",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
}
],
"configuration":{
"maxSession":7,
"port":5550,
"host":"127.0.0.1",
"register":true,
"registerCycle": 5000,
"hubPort":4440,
"hubHost":"127.0.0.1",
"nodeTimeout":120,
"nodePolling":2000,
"registerCycle":10000,
"cleanUpCycle":2000,
"timeout":30000
}
}
14. test the Selenium server by:
i. opening a command prompt and typing:
java -jar C:\selenium\selenium-server-standalone-2.41.0.jar -role hub -hubConfig C:\selenium\hub.jsonii. opening another command prompt window and typing:
java -jar C:\selenium\selenium-server-standalone-2.41.0.jar -role node -nodeConfig C:\selenium\node.json -Dwebdriver.chrome.driver=chromedriver.exe -Dwebdriver.ie.driver=IEDriverServer.exeiii. open a browser and go to http://127.0.0.1:4440/grid/console and verify all browsers are displayed
15. stop the hub and node by closing each command prompt
16. download NSSM (used to start Selenium as a Windows service) and extract nssm-{version}\win64\nssm.exe (assuming your OS is 64-bit, otherwise use the 32-bit NSSM executable) to C:\selenium
17. open a command prompt and type:
nssm install seleniumhub java -jar C:\selenium\selenium-server-standalone-2.41.0.jar -role hub -hubConfig C:\selenium\hub.json18. then, type:
nssm install seleniumnode java -jar C:\selenium\selenium-server-standalone-2.41.0.jar -role node -nodeConfig C:\selenium\node.json -Dwebdriver.chrome.driver=chromedriver.exe -Dwebdriver.ie.driver=IEDriverServer.exe19. restart the computer
20. after it restarts, login, open a browser, and go to http://127.0.0.1:4440/grid/console to verify all browsers are displayed
21. add firewall exceptions by opening a command prompt and typing:
netsh advfirewall firewall add rule name="SeleniumIn" dir=in action=allow protocol=TCP localport=4440
netsh advfirewall firewall add rule name="SeleniumOut" dir=out action=allow protocol=TCP localport=4440
Congratulations! Your Selenium grid is now functional and you can use a Selenium WebDriver-compatible testing framework (such as Codeception, WebDriverJS, etc) to connect to it (using the server's actual IP address, not localhost or 127.0.0.1).
P.S. For security reasons, in my tutorial I've used non-default ports 5550 and 4440 instead of the default 5555 and 4444. Feel free to use your own custom port numbers if you wish.
P.P.S. For ease and convenience, this tutorial installed the hub and node on the same server. In a more realistic scenario, there would be a central hub on one server and multiple worker nodes on separate servers. In that case, you would follow steps 1-4,8,10-12,14i,15-17,19,21 for the hub and all steps except 12,14i,14iii,17 for the node(s). You will also need to update the "host" and "hubHost" settings in step 13 to point to the node's and hub's actual IP address, respectively.
_____________________________
Additional resources:
The latest version of safari for windows.to download safari windows
ReplyDeletego:download safari windows
Hi Garry, thanks for the link. FYI, upon further review I've decided to drop my recommendation of installing Safari on Windows altogether (see updated post).
ReplyDeleteWhen using separate servers for nodes, is it possible to start selenium on each from PowerShell on Hub machine ? I trying that but since PS doesnt actually open visible Browser, Selenium can't find elements on web page. Is there a headless parameter ? Or set display etc ?
ReplyDeleteThanks for looking :-)
Hi Tzimoe, Windows doesn't have a native remote execution tool like SSH on Linux, but if you have a requirement to remote start the nodes and an autostart service using nssm won't work for you, you might try http://www.powershellserver.com/overview/ssh/
ReplyDeleteThanks for the documentation.
ReplyDeleteCan anyone help me how to remove the same from services... i mean uninstall completely.
Hi chinni, at a command prompt run "nssm remove seleniumhub", then run "nssm remove seleniumnode", then delete the Selenium jar file and nssm.exe.
ReplyDeleteHi Tzvimoe, Selenium grid works by having the nodes register with the hub and then the hub sends commands to the nodes. PowerShell doesn't open the browser, Selenium does. If Selenium can't find elements on the web page, make sure you have the right webdriver installed (IE, Chrome, etc.). If you want to do headless testing, you're better off with a solution like http://nightwatchjs.org/
ReplyDeleteHi Guys,
ReplyDeleteI configured selenium grid for Firefox, chrome and IE 10 and IE11.
Do you know, how to run tests in codeception in selenium grid for internet explorer 11 and internet explorer 10 parallel?
I am entering following commands but it doesnt work
$php codecept.phar run acceptance --env ie10 --env ie11
Any error messages? Try php codecept.phar -vvv --env=ie10,ie11
ReplyDelete@Blue thanks
ReplyDeleteI followed your command and now I am getting following error
[Facebook\WebDriver\Exception\UnknownServerException]
Session [3f11bc78-1308-4eba-be93-82f400689574] was terminated due to TIMEOUT
Below is my acceptance.suite.yml
class_name: WebGuy
modules:
enabled:
- WebDriver
config:
WebDriver:
url: 'http://www.*************'
host: 'http://**********'
port: 4444
browser: 'firefox'
wait: 10
window_size: maximize
clear_cookies:
#window_size: 700x768
capabilities:
unexpectedAlertBehaviour: 'accept'
platform: 'WINDOWS'
#javascriptEnabled: true
env:
chrome:
modules:
config:
WebDriver:
browser: 'chrome'
ie10:
modules:
config:
WebDriver:
browser: 'internet explorer'
version: '10'
platform: 'WINDOWS'
ie11:
modules:
config:
WebDriver:
browser: 'internet explorer'
version: '11'
platform: 'WINDOWS'
Whereas below is my config.json
{
"capabilities":
[
{
"browserName": "internet explorer",
"version": "11",
"platform": "WINDOWS",
"maxInstances": 5}],
"configuration":
{
"nodeTimeout":120,
"port":5555,
"hub":"http://****************:4444/grid/register",
"nodePolling":2000,
"registerCycle":10000,
"register":true,
"cleanUpCycle":5000,
"timeout":29000,
"maxSession":1}
}
I have same config.json for ie 10 on another server...
Hi Usman, if you followed my guide exactly then you may need to change your ports since I use non-default ports 5550 and 4440
ReplyDeleteThanks @Blue
ReplyDeleteI am using 5555 and 4444 as you can see in my code..
Problem is still there.
Selenium grid launch the browser successfully, and I can see the script is working but suddenly browser window get close. Below is the error
"Session [] was terminated due to TIMEOUT"
In command window I can also see
"firefox driver cannot be used after quit() was called"
Have you tried setting a larger connection_timeout in your config? http://codeception.com/docs/modules/WebDriver#.VuBAMKgrJE4
ReplyDeleteYou may also want to play around with the timeout and browserTimeout settings: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/4566#issuecomment-192091201
ReplyDeleteHi @Blue
ReplyDeleteI am playing around time out issue..
I will update here if I get any solution.
Mr.Blue Coat, thanks for the documentation.
ReplyDeleteI have followed and started both hub and node services. But Firefox browser is not opening in GUI, browser is running in back-end. I have verified in task manager but not opening in desktop.
If i run hub.json and node.json in cmd prompts, browser is opening and i can able to see the running tests.
Pls help me to resolve this issue. thanks.
Note:
created seleniumHub service with hub port no:1010
created seleniumNode service with node port no:2020
right click both services->properties->log on tab->selected "local system account" and clicked check box " Allow service to interact with desktop".
run steps:
ReplyDelete---------
1) my source code in 'Vagrant', i ran right click->testNg.xml file from JBoss Studio(eclipse).. this is linux machine
2) i have started both hub and node in my local windows 8.1 desktop as services
3) i have added host entry of my local desktop full computer name in both windows and linux hosts files
my test cases are not failing. all test cases are passed. only problem is, firefox browser is not opening in GUI.
ReplyDeleteHi Sathish, my setup assumes the grid is running as an unattended service so you wouldn't see the browser launch (Selenium is being launched by nssm which is a service that doesn't interact with the desktop). If you want to see the tests running, follow the guide but don't use nssm.
ReplyDeleteThanks blue coat. any alternate approach to run as windows service without nssm?
ReplyDeleteMy requirement is, we need to start as windows service without command prompt and need to see launching browsers in GUI.
any luck? thanks in advance.
Sorry, not that I know of.
ReplyDeleteOk :)
ReplyDeleteHi @Blue Coat
ReplyDeleteI found the solution for Selenium Grid timeout....I played around time out and where below is the stable /smooth running of automated scripts in Grid for me.
1 - ) Just change following values in the Hubconfig.json;
"cleanUpCycle":5000,
"timeout":100000,
"browserTimeout":100000,
2 - ) and change following values in the nodeconfig.json;
"cleanUpCycle":5000,
Cheers,
Usman
Thanks Usman!
ReplyDelete