For those of you that are using Selenium WebDriver 3 but haven’t set up a remote Selenium Server, here is a simple guide to get you going.
In this example we are just using 2 PCs.
PC1 – This is the PC with Eclipse and WebDriver 3 installed (IP: 10.0.0.37)
PC2 – This is the remote machine, which acts as both the Selenium Hub and has a Selenium Node (IP: 10.0.0.152)
So first of all we need to understand what the difference is between the Selenium Hub and the Selenium Node. The Selenium Hub (Server) acts as the controller that receives requests to execute tests on certain platforms & browsers, and then re-directs them to the appropriate Node that matches the request. So we have one Hub and we register multiple Nodes to the Hub, each Node could be a physical or virtual machine (creating a Grid of remote machines to execute tests against).
For this demo we are just using 2 physical machines, one with Eclipse/WebDriver 3 on, and the other which will take both roles of Hub and Node.
Step 1: On our remote PC, we need to download Java JRE and install it. We used JRE 1.8.0_121, downloaded from here
You can check it is installed correctly by opening a command prompt and typing java -version
Step 2: On our remote PC, we need to download the following files from SeleniumHQ :
- Selenium Server (we used selenium-server-standalone-3.3.1.jar for our demo)
Just extract these files into a folder such as documents/SelServer
Step 3: On our remote PC, add the directory that you put the selenium server and browser server files in step 2, to the system path.
On the remote machine, open the System Control Panel (Control Panel->System and Security->System) and click the Advanced system settings link on the left. On the System Properties dialog that appears, on the Advanced tab, click the Environment Variables… button.
Now select the Path variables in the system variables and click Edit… Click the New button and add the path to the directory from Step 2.
Step 4: On our remote PC, start Selenium Hub running.
Open a command window, change directory to the selenium server directory (on ours it was cd C:\Users\edgewords\Documents\SelServer)
Now start the Selenium Server, type the following and hit enter:
java -jar selenium-server-standalone-3.3.1.jar -role hub
The hub should now be running on localhost port 4444
Step 5: On our remote PC, register a Node to the Hub
Open another command prompt window and add a node to the hub:
java -jar selenium-server-standalone-3.3.1.jar -role node -hub http://localhost:4444/grid/register
We can check this has worked now by opening a web browser and going to: http://localhost:4444/grid/console
you should see the following:
Step 6: On our WebDriver 3 PC, we can now connect to the remote Selenium Hub and execute our Web Tests.
To do this, we have simply created a new project in Eclipse, Created a simple Java Class file, added our Selenium Libraries and written the code below:
And complete the details. Remember – your remote machine (Hub) IP address (highlighted in yellow in above screenshot) will be different so find out your Selenium Hub IP address on the remote machine by opening a command prompt and typing ipconfig and enter key
Now go ahead and run your web tests remotely!
Edgewords Training is a dedicated Automated Testing Tools training company. We are a Ranorex Training Partner, and provide training in Ranorex, Selenium, Cucumber, SpecFlow, HP Tools, JMeter and many other tools.