Certified Selenium Professiona Learning Resources Configuring selenium grid

Learning Resources
 

Configuring selenium grid


The node can be configured in 2 different ways; one is by specifying command line parameters, the other is by specifying a json file.

Configuring the nodes by command line

By default, this starts 11 browsers : 5 Firefox, 5 Chrome, 1 Internet Explorer. The maximum number of concurrent tests is set to 5 by default. To change this and other browser settings, you can pass in parameters to each -browser switch (each switch represents a node based on your parameters). If you use the -browser parameter, the default browsers will be ignored and only what you specify command line will be used.

-browser browserName=firefox,version=3.6,maxInstances=5,platform=LINUX

This setting starts 5 Firefox 3.6 nodes on a linux machine.

If your remote machine has multiple versions of Firefox you’d like to use, you can map the location of each binary to a particular version on the same machine:

-browser browserName=firefox,version=3.6,firefox_binary=/home/myhomedir/firefox36/firefox,maxInstances=3,platform=LINUX -browser browserName=firefox,version=4,firefox_binary=/home/myhomedir/firefox4/firefox,maxInstances=4,platform=LINUX

Tip: If you need to provide a space somewhere in your browser parameters, then surround the parameters with quotation marks:

-browser browserName=firefox,version=3.6,firefox_binary=c:\Program Files\firefox ,maxInstances=3, platform=WINDOWS

Selenium Grid Main Configuration File

Once you have Selenium Grid up and running, you might want to tweak some of its settings.

Most of Selenium Grid configuration is defined in the grid_configuration.ymlfile located at the root of Selenium Grid installation directory on the machine where the Hub is running.

This file is in the human-friendly YAML format, which should be mostly self explanatory.

Defining New Environments

Selenium Grid provides predefined environments for standard browsers to get you started, however, chances are that very soon, you will want to define your own.

To define a new environment, edit the grid_configuration.ymlfile located at the root of Selenium Grid installation directory on the machine where the Hub is running:

Search for a section like:

hub:
   port: 4444
   # ...
   environments:
       - name:    "Firefox on Windows"
         browser: "*firefox"
       - name:    "Firefox on OS X"
         browser: "*firefox"
       - name:    "IE on Windows"
         browser: "*iehta"

An environment is basically a binding between an arbitrary string you pick (the name) and a real Selenium browser string that will be used to start the session on the actual remote control (*firefox, safari, *iexplore, *hta, …). To add a new one, just add a new entry in the list, starting with a dash (-) and keeping the same indentation level. For instance, to add a new environment called “Shinny New Environment” that will use the *safarimode type:

  hub:
     port: 4444
     # ...
     environments:
         - name:    "Firefox on Windows"
           browser: "*firefox"
         - name:    "Firefox on OS X"
           browser: "*firefox"
         - name:    "IE on Windows"
           browser: "*iehta"
         - name:    "Shinny New Environment"
           browser: "*iehta"

Changing Hub’s Port

By default, Selenium Grid Hub is started on port 4444, which is also Selenium RC default port (this is on purpose, since, from the test’s point of view, the Hub looks just like a regular RC).

You can change the Hub port by editing the grid_configuration.ymlfile, which is located at the root of Selenium Grid installation directory on the machine where the Hub is running:

Search for a section like:

hub:
   port: 4444	   

And change 4444to the port number of your liking. For instance:

hub:
     port: 1234

Changing Hub Self-Healing Parameters

remoteControlPollingIntervalInSecondsand sessionMaxIdleTimeInSecondsconfiguration parameters can be set in grid_configuration.yml. For instance:

 hub:
    port: 4444
    remoteControlPollingIntervalInSeconds: 180
    sessionMaxIdleTimeInSeconds: 300
    environments:
        - name:    "Firefox on Windows"
          browser: "*firefox"
  • remoteControlPollingIntervalInSeconds: is how often the Hub will check for registered Remote Controls status and idle testing sessions.

  • sessionMaxIdleTimeInSeconds: is how long a testing session can be idle before the Hub automatically unregisters the associated Remote Control.

Changing Remote Control Self-Healing Parameters

When starting the Remote Control you can set hubPollerIntervalInSecondsto control how often the Remote Controls will check the Hub status and automatically re-register themselves in case the Hub does not list them as registered.

e.g.

ant -DhubPollerIntervalInSeconds=120 launch-hub  

Changing Maximum Wait Time for New Session

By default the Hub will block until a Remote Control becomes available when requesting a new browser session. This can be problematic if the requesting client times out. Since the Hub is unaware of this timeout, it will request the new session anyway and that session will become effectively orphaned.

If your client cannot wait for the session you may change the maximum time the Hub will wait in grid_configuration.yml. When the newSessionMaxWaitTimeInSecondsvalue is exceeded, the Hub will return an Error indicating that no Remote Controls were available to fulfill the request.

For instance:

  hub:
     newSessionMaxWaitTimeInSeconds: 120

This sample configuration will instruct the Hub to block for up to 2 minutes while waiting for a Remote Control to become available to handle the new session request.

NB: If this configuration value is not provided, the default value of infinite will be used.

 For Support