Selenium Grid 4 Tutorial For Distributed Testing

Image for post
Image for post

Note: The code samples may be displayed improperly because of markdown. I recommend continuing to read the original article on our blog to make sure all the examples are displayed properly.

Image for post
Image for post

Introduction to Selenium Grid 4

How to Download Selenium Grid 4?

java -jar selenium-server-4.0.0-alpha-2.jar
Image for post
Image for post

Salient Features of Selenium Grid 4

Single Jar for Hub and Node

Improved Architecture

Different Grid Types

Docker Support

Architectural Overview of Selenium Grid 4

Architecture of Selenium Grid 3

Image for post
Image for post

Architecture of Selenium Grid 4

Image for post
Image for post
java -jar selenium-server-4.0.0-alpha-2.jar sessions
java -jar selenium-server-4.0.0-alpha-2.jar distributor — sessions http://localhost:5556
java -jar selenium-server-4.0.0-alpha-2.jar router — sessions http://localhost:5556 — distributor http://localhost:5553
java -jar selenium-server-4.0.0-alpha-2.jar node — detect-drivers
Image for post
Image for post
public void testSetUp() throws MalformedURLException {
String Node = “http://localhost:4444";

DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName(“chrome”);

/* The execution happens on the Selenium Grid with the address mentioned earlier */
driver = new RemoteWebDriver(new URL(Node), caps);
}
Image for post
Image for post

Running Tests on Selenium Grid 4

@BeforeClass
public void testSetUp() throws MalformedURLException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName(“chrome”);

/* The execution happens on the Selenium Grid with the address mentioned earlier */
driver = new RemoteWebDriver(new URL(Node), caps);
Image for post
Image for post
Image for post
Image for post

Standalone Selenium Grid

java -jar selenium-server-4.0.0-alpha-2.jar standalone
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

‘Hub and Node’ Selenium Grid

java -jar selenium-server-4.0.0-alpha-2.jar hub
java -jar selenium-server-4.0.0-alpha-2.jar node — detect-drivers
java -jar selenium-server-4.0.0-alpha-2.jar node — detect-drivers — publish-events tcp://hub:4442 — subscribe-events tcp://hub:4443
Image for post
Image for post
Image for post
Image for post
DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName(“chrome”);

/* The execution happens on the Selenium Grid with the address mentioned earlier */
driver = new RemoteWebDriver(new URL(Node), caps);
Image for post
Image for post

Fully Distributed’ Selenium Grid

Step 1 — Start the Sessions Map

java -jar selenium-server-4.0.0-alpha-2.jar sessions
Image for post
Image for post

Step 2 — Start the Distributor

java -jar selenium-server-4.0.0-alpha-2.jar distributor — sessions http://localhost:5556
Image for post

Step 3 — Start the Router

java -jar selenium-server-4.0.0-alpha-2.jar router — sessions http://localhost:5556 — distributor http://localhost:5553

Step 4 — Create a Node

java -jar selenium-server-4.0.0-alpha-2.jar node — detect-drivers
Image for post
Image for post
DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName(“chrome”);

/* The execution happens on the Selenium Grid with the address mentioned earlier */
driver = new RemoteWebDriver(new URL(Node), caps);
Image for post
Image for post
Image for post
Image for post

Wrapping It Up

Author: Himanshu

Written by

Product Growth at @lambdatesting (www.lambdatest.com)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store