Selenium Grid allows running automated tests across different browsers, operating systems, and machines. It works on a master-slave architecture with a hub that distributes tests to node machines. This allows reducing test execution time by running tests in parallel on multiple machines. Selenium Grid supports cross-browser testing and running tests with different data sets on multiple browser instances simultaneously. Setting up a hub is done by running a Java command, and nodes register with the hub using a URL from the hub terminal output. Jenkins can also be configured as a hub to integrate Selenium Grid into a CI/CD pipeline.
2. Lack of etiquette and manners is a huge turn off.
KnolX Etiquettes
Punctuality
Respect Knolx session timings,
you are requested not to join
sessions after a 5 minutes
threshold post the session start
time.
Feedback
Make sure to submit a
constructive feedback for all
sessions as it is very helpful for
the presenter.
Mute
Please keep your window on
mute.
Avoid Disturbance
Avoid leaving your window
unmuted after asking a question
3. Our Agenda
01 Small introduction : Selenium Grid
03 Selenium Grid Architecture
04
What is Selenium Grid and Why to use it?
05
Benefits of Selenium Grid
Selenium Grid vs. Saucelabs
02
Setting up the Hub and nodes
06 Jenkins CI/CD integration using Selenium grid
07
08 Demo
4. What is Selenium Grid and Why to use it?
● Selenium Grid is a part of the Selenium Suite that specializes in running
multiple tests across different browsers, operating systems, and
machines.
● Selenium Grid works on master slave architecture where the master or
hub runs the test scripts on slave or node machines.
● Selenium Grid can help us reduce our test execution time. This is
achieved by executing the scripts on remote machines.
● Selenium Grid helps us run our tests or multiple OS with different
browser configurations.
5. What is Selenium Grid and Why to use it?
● We can use Selenium Grid to run our tests with multiple data sets. Each
browser instance can execute the tests with different data.
● Cross browser testing is one of the advantages of Selenium Grid. We can
execute the same test scripts on different browsers.
7. What are Hub and nodes?
● Hub
○ A Hub is a central point where all your tests are sent.
○ Selenium grid contains only one hub.
● Nodes
○ Nodes are different Selenium instances that receives commands
from the hub and executes the tests on individual computer systems.
○ The machines which are nodes are not required to be on the same
platform or have the same browser selection as that of the hub or
the other nodes.
8. Benefits of Selenium Grid
● We can use multiple programming languages like Java, C#, Python etc to
write test scripts in Selenium Grid.
● Selenium Grid supports all the major web browsers like Chrome, Firefox,
Safari, Internet Explorer, Microsoft Edge.
● Selenium Grid also supports multiple platforms or operating systems like
Linux, Windows, macOS, etc.
● All the tests can be executed in parallel to speed up the execution speed.
9. Setting up the Hub
● To configure your system as a hub, download the latest Selenium server
(Grid) jar file.
● To register the system as the Hub use the following command:
○ java -jar selenium-server-standalone-3.141.59.jar -role hub
● Extract the link to register the nodes from the terminal.
10. Setting up the Nodes
● To configure your system as a node, we again need to download the
latest Selenium server jar file and the version should be the same as the
Hub.
● To register the system as a Node use the following command:
○ java -Dwebdriver.chrome.driver="Usersank11Downloadschromedriver" -jar
selenium-server-standalone-3.141.59.jar -role webdriver -hub
http://192.168.0.105:4444/grid/register -port 5566
● We are using the link extracted from the Hub.
12. How to speed up parallel execution?
The answer is to increase browser instances.
● We can set the number of browser instances that will run in parallel.
● To achieve this we can use the following command.
○ java -Dwebdriver.chrome.driver="/home/ankur/Downloads/chromedriver" -jar
selenium-server-standalone-3.141.59.jar -role webdriver -hub
http://172.16.144.1:4444/grid/register/ -browser
browserName=chrome,maxInstances=2 -maxSession 2
● Using this command we can run only 2 instances at one time.
● We can increase or decrease the instances according to our requirements.
13. Configuring code for chrome browser
ChromeOptions chromeOptions = new ChromeOptions();
//initialize chromeOptions
chromeOptions.setCapability("browserName", "chrome");
//Define on which browser you want to execute your tests.
chromeOptions.setCapability("platformName","LINUX");
//Define the platform on which you will execute your tests
14. Configuring code for firefox browser
FirefoxOptions ffOptions = new FirefoxOptions();
//initialize ffOptions
ffOptions.setCapability("browserName", "firefox");
//Define on which browser you want to execute your tests.
ffOptions.setCapability("platformName","LINUX");
//Define the platform on which you will execute your tests
15. Jenkins CI/CD integration using
Selenium grid
● We can also configure Selenium Grid on Jenkins using the selenium
plugin.
● After installing this plugin the jenkins acts as the hub and other nodes can
connect to it.
● We need to add node configurations, define the location of drivers
(chromedriver,gecko driver) and also define the number of maximum
instances. Then finally start the node.
● After this we can execute our tests using the headless mode in Jenkins.
18. Selenium Grid vs. Saucelabs
● Selenium Grid is free to use and can be scaled up with adding physical
machines to our network. But Saucelabs is a paid service which only
offers a limited time trial period.
● Selenium Grid is also useful if the organization has some security
concerns regarding the data access as the tests are run on a physical
machine instead of on some device farm which is used by Saucelabs.
● Selenium Grid is open source but Saucelabs is not.