DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Selenium Grid Tutorial: Setup and Cross-Browser Testing

Selenium Grid Tutorial: Setup and Cross-Browser Testing

Learn about the Selenium Grid testing tool, how it works, and how to take advantage of it for performance testing.

Nishant Mankar user avatar by
Nishant Mankar
·
Nov. 05, 18 · Tutorial
Like (1)
Save
Tweet
Share
20.30K Views

Join the DZone community and get the full member experience.

Join For Free

What Is Selenium Grid?

Selenium Grid is a testing tool which allows us to run our tests on different machines against different browsers. It is a part of the Selenium Suite which specializes in running multiple tests across different browsers, operating systems, and machines. You can connect to it with Selenium Remote by specifying the browser, browser version, and operating system you want through Selenium Remote’s Capabilities.

There are two main elements to Selenium Grid — a hub and nodes.

What Is a Hub?

In Selenium Grid, the hub is a computer which is the central point where we can load our tests. The hub also acts as a server, so it acts as a central point to control the network of test machines. The Selenium Grid has only one hub and it is the master of the network. When a test with given DesiredCapabilities is given to hub, it searches for the node which matches the given configuration. For example, you can say that you want to run the test on Windows 10 and Chrome browser with any version. The hub will try to find a machine in the Grid which matches the criterion and will run the test on that machine. If there is no match, the hub returns an error. There should be only one hub in a Grid.

What Is a Node?

In Selenium Grid, a node is a test machine which opts to connect with the hub. This test machine will be used by the hub to run tests on. A Grid network can have multiple nodes. A node is supposed to have different platforms, i.e. different operating system and browsers. The node does not need the same platform for running as that of the hub.

How Selenium Grid Works

First, you need to create a hub. Then you can connect (or “register”) nodes to that hub. Nodes are where your tests will run, and the hub is responsible for making sure your tests end up on the right one (e.g., the machine with the operating system and browser you specified in your test).

Architecture and RemoteWebDriver Workflow

You can use RemoteWebDriver the same way you would use WebDriver locally. The primary difference is that RemoteWebDriver needs to be configured so that it can run your tests on a separate machine. The RemoteWebDriver is composed of two pieces: a client and a server. The client is your WebDriver test and the server is simply a Java servlet, which can be hosted in any modern JEE app server.

RemoteWebDriver is an implementation class of the WebDriver interface that a test script developer can use to execute their test scripts via the RemoteWebDriver server on a remote machine.

There are two parts to RemoteWebDriver: a server (hub) and a client (node).

The RemoteWebDriver server is a component that listens on a port for various requests from a RemoteWebDriver Once it receives the requests, it forwards them to any of the following: Firefox Driver, IE Driver, or Chrome Driver, whichever is asked.

The language-binding client libraries that serve as a RemoteWebDriver The client, as it used to when executing tests locally, translates your test script requests to JSON payload and sends them across to the RemoteWebDriverserver using the JSON wire protocol.

When you execute your tests locally, the WebDriver client libraries talk to your Firefox Driver, IE Driver, or Chrome Driver directly. Now, when you try to execute your tests remotely, the WebDriver client libraries talk to the RemoteWebDriverserver and the server talks to either the Firefox Driver, IE Driver, or Chrome Driver, whichever the WebDriver client asks for.

Image title

We will do this step by step as we move in this tutorial, but first let’s look at the overall architecture diagram as to how the workflow happens. Some jargon below.

JSON over wire: JSON messages hold the entire information that is required by the server [can be Selenium GRID or WebDriver components] and hence instead of RPC, plain JSON messages are exchanged between server and client. Also referred to as WebDriver protocol.

Desired Capabilities: Object in automation code that has requesting browser configuration information.

RemoteWebDriver: Object in automation code that knows how to communicate remotely with WebDriver / Selenium GRID.

Starting a Hub

We are now going to launch a hub. Open the command prompt and navigate to the C: Drive, because that is the directory where we placed the Selenium Server. On the command prompt, type:

 java -jar selenium-server-standalone-3.3.1.jar -role hub 

Image title

To verify whether the hub is running, open the browser and navigate to http://localhost:4444.

Image title

Now click the Console link and then click View Config. The config of the hub should be displayed like this:

Image title

Click on View Config.

Set Up the Node Machine

Ideally, the Node Machine has to be different from the Hub Machine, but to maintain the simplicity of this tutorial, I am setting up the Node on the same machine where I have the Hub running. The steps are the same, except that the IP address is changed to the Node Machine IP Address.

To register the Hub Machine with Node Machine, type:

java -jar selenium-server-standalone-3.3.1.jar -role node -hubhttp://192.168.1.164:4444/grid/register -port 5555


Image title

After executing the command, return to the Hub and navigate the URL http://localhost:4444 or http://192.168.1.164:4444 and the hub will now display the node which is attached to it.

Image title


Testing operating system Machine Driver (software)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Securing VMs, Hosts, Kubernetes, and Cloud Services
  • Writing a Modern HTTP(S) Tunnel in Rust
  • Why Open Source Is Much More Than Just a Free Tier
  • Why You Should Automate Code Reviews

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: