Selenium-Grid is used to speed up the execution of a test by using multiple machines to run tests in parallel, it is also used to support running tests against multiple environments, specifically, against different browsers at the same time. Selenium Grid can be used in below scenarios:
- To run your tests against multiple browsers, multiple versions of browser, and browsers running on different operating systems.
- To reduce the time it takes for the test suite to complete a test pass.
Installation is simple. Download Selenium Server jar file from Selenium’s official website which was formerly known as Selenium RC Server and save it at any location on the local disk.
Here is the download page in selenium HQ: http://www.seleniumhq.org/download/
User would see a file like "selenium-server-standalone-3.141.59.jar" in the download folder after download is completed.
To ease out the configuration we have attached a Grid Setup zip file which is having all required files under it, download and extract Grid Setup folder, copy extracted Grid Setup folder to C drive.
Last part is to copy above downloaded Selenium Server jar file and past it under C:\Grid Setup folder.
Running Selenium Hub
The Hub is the central server which manages nodes, takes instructions from client and executes them remotely on the nodes and manage test threads. Each Selenium Grid consists of exactly one hub. The hub needs to be reachable from the respective clients (i.e. CI server, Developer machine etc.) The hub will connect one or more nodes that tests will be delegated to.
Lets learn how to setup HUB:
Navigate to C:\Grid Setup folder, you will see below files under it.
Right click on hub.bat file and edit it to make sure that the selenium server name (in blue below) is exactly same as you downloaded, after update save and close it. Please note that the bat file consist of a command that takes the jar file and refer hubconfig.json file to get configurations need to run HUB. We have created a default config to run in bare minimum configuration, but user can update it based on their requirements (Read more about selenium config).
After saving double click on hub.bat file to run it, once running it should be shown as below.
To verify whether hub is running, open the browser and navigate to http://localhost:4444/grid/console. Console gives the information what is available on the Hub. As of now it will be blank, as there is no machine connected to it. User can also click the Console link and then click View Config.
Running Selenium Node
Nodes are different Selenium instances that will execute tests on individual computer systems. There can be many nodes in a grid. A node on Windows might have the capability of offering Internet Explorer as a browser option, whereas this wouldn't be possible on Linux or Mac.
Getting files ready
Selenium nodes are best suited to setup in multiple machines(virtual machines typically) however, user can setup a node on same machine as on hub. Here we are going to setup node on same machine as hub, user can follow same steps to setup node on different machine.
Let's navigate to C:\Grid Setup folder which was downloaded earlier and you will see below files under it.
Let's go thru these files and theirs usage one by one:
First three files in above screenshot are browser driver.exe files, node will use these files to intact with browser, please update them to latest version using below latest Driver Download links:
Node Config File
Node.json file consist of configurations and capabilities for node, below are few important configurations:
- "browserName": "chrome" - It is the browser name where the tests are to be triggered
- "maxInstances": 5 - Maximum number of Chrome instances that can be run.
- "hub": "http://localhost:4444"-localhost:4444 can be replaced by hub IP/machine name in case hub resides in different machine
Node require below information to be able to connect hub, user has to find below two details from hub machine and supply them to "hub": "http://localhost:4444" configuration:
IP address/Machine name of HUB machine
Port on which the hub is running (by default it is 4444)
If you are trying this on local machine within 'Grid Setup' folder then you can use 'localhost' as machine name and 4444 as port of hub.
Now, right click on node.bat file and edit it to make sure that the selenium server name (in blue below) is exactly same as you downloaded, after update save and close it.
Please note that the .bat file consist of a command that takes jar file, browser drivers (mentioned above) and node.json file to run the node. Please run the node.bat file under C:\Grid Setup folder by double clicking it.
Once the nodes is successfully registered to the HUB, navigate the URL http://localhost:4444/grid/console (or http://<IP Address of the HUB machine>:4444/grid/console when hub is remote machie) and the hub should now display the node which is attached to it.
User can run multiple nodes on multiple machines by setting up Grid Setup folder on multiple machine and editing node config pointing towards hub.
Configure you LEAPWORK environment to start your test using this article. You are now ready to run your first test in selenium grid.
For any clarification, please contact our Priority Support.