Selenium Grid is a proxy server that enables the user to run tests in parallel on multiple machines. It manages different browser versions and configurations centrally. Selenium Grid allows the selenium test scripts to route the commands to remote web browsers. Two versions of Selenium Grid are the older ‘Grid 1’ and the newer ‘Grid 2’. We will only be concerned about Grid 2 because Grid 1 is gradually being despised by the Selenium Team. It uses a hub-node concept where the test is run only on a single machine called a hub, but parallel execution will be done by different machines called nodes.
With Selenium Grid, there is one server acting as the hub that routes the JSON formatted test commands to one or more registered Grid nodes. Tests contact the hub for accessing the remote browser instances. Hub has the list of all the registered servers to which it has to provide access and allows us to control these instances. Two important definitions related to selenium grid are:
Hub: The hub is the central point that kicks off the tests or a point where you load your tests. A Grid has only one hub and it is launched from one system. The hub will connect one or more registered nodes and the tests will be delegated to these registered nodes only. The tests will be run on the machine containing the hub but the browser on the node gets automated.
Node: Nodes are the Selenium instances that will execute the tests you have loaded on the hub on individual computer systems. A grid can have many nodes. The machines running the nodes need not be on the same platform as that of the hub or have the same browser as that of the hub or the other nodes.
Selenium Grid must be used when you want to do either one or both of the following:
1. Tests can be run against different browsers, operating systems, and machines all at the same time: For this, you need to ensure whether the application being tested is fully compatible with a wide range of browser-OS combinations.
2. Save the time in your test suites’ execution: If Selenium Grid is run, say, 3 tests at a time, then the whole suite would be finished around 3 times faster.
A testing framework runs a sample Grid test case as it supports parallel test execution. Selenium Grid uses TestNG for running parallel tests. TestNG is quite similar to JUnit and it supports various test methods, parallel testing, and multi-threaded testing. TestNG being a threading model supports running multiple instances of the same test. After the creation of hub and nodes, TestNG must be configured in eclipse.
[ Related Read: Intro to TestNG Framework ]
1. Go to the machine where you want to launch the hub. Navigate to the machine’s ‘C’ drive using the command prompt as it is the directory where the Selenium server is placed.
2. Type ‘java -jar selenium-server-standalone-2.30.0.jar -role hub’ on the command prompt.
3. The hub should be launched successfully.
4. After setting up the hub, a node needs to be launched.
5. Now go to the machine which will act as a node and launch a command prompt there.
6. After navigating to the machine’s Drive ‘C’, type
C:\> java -jar selenium-server-standalone-2.30.0.jar -role hub
webdriver –hub http://192.168.1.3:4444/grid/register – port 5566
where 192.168.1.3 is the IP address of the machine where the hub is running. We have used port 5566 while you can choose the port number as desired.
At this point, a simple grid has been configured. Now a test can be run remotely on the machine acting as a node.
1. Only one machine should act as “One node”.
2. Only one browser must be run by “One node”.
3. For parallel execution of various threads, a driver must be created as the ‘ThreadLocal’ variable.
Interested to share your
Read More
BugRaptors is one of the best software testing companies headquartered in India and the US, which is committed to catering to the diverse QA needs of any business. We are one of the fastest-growing QA companies; striving to deliver technology-oriented QA services, worldwide. BugRaptors is a team of 200+ ISTQB-certified testers, along with ISO 9001:2018 and ISO 27001 certifications.
Corporate Office - USA
5858 Horton Street, Suite 101, Emeryville, CA 94608, United States
+1 (510) 371-9104Test Labs - India
2nd Floor, C-136, Industrial Area, Phase - 8, Mohali -160071, Punjab, India
+91 77173-00289Corporate Office - India
52, First Floor, Sec-71, Mohali, PB 160071,India
United Kingdom
97 Hackney Rd London E2 8ET
Australia
Suite 4004, 11 Hassal St Parramatta NSW 2150
UAE
Meydan Grandstand, 6th floor, Meydan Road, Nad Al Sheba, Dubai, U.A.E