Set up Selenium GRID

In previous section, we read about what and why Selenium GRID with architecture diagrams on how it works end-end. In this section, lets start by understanding how to setup a selenium GRID. We will NOT necessarily start consuming the GRID here as that would be for subsequent sections.

Here we would be learning how to strategize and think about setting up, start and stop selenium GRID and also options on how to continuously expand the GRID as needed.

We already alluded to the point that Selenium GRID is a network concept, so it will be difficult to show any concepts related to “networking” and “port blocking” etc. If you are in a corporate network or using a VPN, then I would advise to first try the GRID locally as in this tutorial and then experiment it on a real network.

AGENDA

  1. Environment requirements
  2. Download GRID jar
  3. Download Selenium GRID helper scripts
  4. Start GRID HUB – command line
  5. Start GRID Node – command line
  6. Start HUB – json config
  7. Start Node – json config
  8. Talk about configuration options in each of the above topics.

1) Environment Requirements

Install JDK and have JAVA_HOME environment variable point to the JDK home directory. Also add %JAVA_HOME%/jre/bin and %JAVA_HOME%/bin to PATH variable. You can see how to install JDK in this post.

Validate that typing “java -version” in a command prompt returns the JDK version on your machine.

2) Download GRID jar

Download selenium-server-standalone-xxx.jar file. The xxx is the version and it keeps changing. For example, I downloaded the 2.44.0 version from here.

Save it to your filesystem. I saved it to c:\seleniumframework\selenium-server-standalone-2.44.0.jar

3) Download Selenium GRID helper scripts

We created lot of scripts with multiple configuration options that will help configure the GRID in umpteen ways. Please download the entire selenium-grid-helper folder. It is also a github repo, so folks can checkout the directory and contribute as you deem right.

We will explain how selenium-grid-helper will make your life so easy, but first lets do it the original way as described on google pages so that we appreciate the fundamentals and then we can improve upon it once we have that context, right?

4) Start GRID HUB

Open a command prompt and navigate to c:\seleniumframework and type the below.

start_hub_plain

As you can see above, the default port on which the HUB starts is 4444. We will talk how we can change this when we talk about configuration options.

5) Start GRID Node(s)

Open a command prompt and navigate to c:\seleniumframework and type the below.

 

start_node_plain

Now the GRID is started with the default configuration [for both hub and node]

Let’s see how the GRID looks. Hit the url http://localhost:4444/grid/console

GRID_plain_started

6) Start GRID HUB – json config

We have another way to start the HUB by specifying the configuration options in a json config file. The default json config files can be downloaded from google website directly as shown below. However, I used a slightly different one that is available here. Once you download the file, place it in the same folder c:\seleniumframework

default_json_config

Now start the hub from command line by issuing the below command.

You should see a similar output as in step 4

7) Start GRID Node – json config

Download the nodeConfig.json file from hereThen from command line issue the following command.

Now hit the url http://localhost:4444/grid/console

GRID_my_started

8) Configuration Options

The content of hubConfig.json is as below

host: By default picks up localhost if null
port: Can change the port by default is 4444

nodePolling: How often to poll to check status of node. 5 sec by default

timeout:  The timeout in seconds before the hub automatically releases a node that hasn’t received any requests for more than the specified number of seconds

maxSession (5 by default): The maximum number of browsers that can run in parallel on the node. This is different from the maxInstance of supported browsers

browserTimeout: Read the section “Configuring timeouts” here

The content of nodeConfig.json is as below

browserName: name of browser {android, chrome, firefox, htmlunit, internet explorer, iphone, opera}

version: version of the browser

***_binary: The location of browser binary. Explicitly override the one available in PATH

platform: platform of the os {WINDOWS, LINUX, MAC,ANY}

maxInstances: The maximum # of instances of browser that are launched on this node. This is different from maxSession (see hub above) as maxSession is how many concurrent parallel browser sessions can be run on this node

Rest of the options are self-explantory.

SUMMARY

In this section, we have seen how to start Selenium GRID (hub and node) using command line and using a json config file. Each of the configuration options described in the json config file are also available through command line.

As we have seen there are many options here with the GRID. But a question that might pop up in your mind is – Why should I care about so many? When what I really want is a browser version that I request and probably the OS platform.

If you are a developer, then you probably already know that even simple requirements sometimes implemented through code will bring out the “real” details.

And so you might be thinking now how to abstract this complexity from the user of the GRID.

Thankfully we already put in significant time in this and wrote the selenium-grid-helper scripts that can fire up the GRID and abstract many details. With the selenium-grid-helper, you can fire up a grid by specifying as little as

  • Browser name and version
  • Platform (or OS)
  • Set up GRID as a windows service (so that it can automatically start)
  • Scalable scripts that can add newer browsers as they come

We will explain in the next section how to use selenium-grid-helper scripts [of course on a windows machine, *nix users find it easier with shell scripting and we can easily map the windows batch scripting to shell scripting]