Selenium Grid is a tool, that allows to runs multiple tests across different operating systems, browsers in parallel at the same time. Grid architecture contains Hub that only runs tests on a single machine, execution, however, these tests are performed on different machines called nodes. This approach obviously has its advantages. Speeds execution of a test, otherwise the application under tests is tested simultaneously on several environments, giving additional feedback.

## Selenium Grid Architecture:

An architecture of grid is very simple. First, we should have a hub, only one hub in a grid. This will be our starting point and to a hub, we will load tests into. From there, tests are loaded into nodes.

Simple node architecture

Nodes are instances that will execute tests that were loaded from a hub. There can be one or more nodes, this depending on our configuration and of course needs.

To install Selenium Grid on a local machine we should make two things: first, install java JDK, and second download Selenium Server JAR file from SeleniumHq webpage.

After download, all needed files lets start with hub configuration. To start selenium grid hub on a local machine, open console and go to the directory where is located selenium server JAR file.

After that, we can open a browser and go to http://192.168.0.2:4444/grid/console and for now, we should get an empty console, as bellow:

Console

and config:

Console

For now, we don’t have only a lot in this configuration. Next step is to configure nodes. To configure node on localhost: java -jar selenium-server-standalone-3.3.1.jar -role node -hub http://192.168.0.2:4444/grid/register/

And now we can see our first node:

Node

To override default configurations node, we can register the second node as fallows:

Listing below:

After refreshing console with nodes configuration we should have second with custom configuration:

Node

## How to write tests for Selenium Grid?

To design tests for the grid is not that complicated that you thing. But first od course we must create some changes in our code. Wery important is to import DesiredCapabilites package. This allows us to use: DesiredCapabilites object.

Define a browser and initialize a DesiredCapabilites object with firefox method:

Declare requirements for a specific platform and browser version.

For this configuration, we will run out tests for OSX with Firefox 52.0.2 browser. Below is configuration for all platforms: