Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Setup selenium grid

Meo edited this page Apr 25, 2018 · 2 revisions

A. Prequisitions

Depends on which version of browsers you want to test, you’ll need the appropriate version of the followings (* you might need to set JAVA_HOME & MAVEN_HOME to your PATH ):

  • Selenium server standalone here.
  • Chromedriver here.
  • Geckodriver here.
  • MiscrosofWebDriver here.
  • Java jdk 8 here.
  • Maven here.
  • KITE engine here, for first simple test. Then to verify every thing is OK, follow the README of KITE to launch first *simple test.

Selenium-Grid allows you run your tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines running different browsers and operating systems. Essentially, Selenium-Grid support distributed test execution. It allows for running your tests in a distributed test execution environment.

A grid consists of a hub and one or many nodes. They are all http servers under the hood, using JsonWire protocol to communicate.

Selenium hub

The hub receives the requests from user and forwards them to nodes according to their availability. The ip of the hub will be communicated to all the node of the same grid. There are 2 ways to set up a hub:

  • Simple way:
java -jar selenium-server-standalone-3.x.x.jar -role hub -port PORT -host IP

With this you can set up quickly a hub with specific port number and ip address (if you have multiple IP on different interfaces).

  • Using a configuration file: You can choose to set various options on your hub. Of course you can do it with command line with different java flags, but the easier way is to use a configuration file (json). For example (hubConfig.json):
{
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets": [],
  "withoutServlets": [],
  "custom": {},
  "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "throwOnCapabilityNotPresent": true,
  "cleanUpCycle": 5000,
  "role": "hub",
  "debug": false,
  "browserTimeout": 0,
  "timeout": 1800
}

To launch the hub:

java -jar selenium-server-standalone-3.x.x.jar -role hub -hubConfig hubConfig.json

Selenium node

The nodes receive the requests from the hub and forward them to the webdrivers registered to it, to execute accordingly on the browsers. Like the hub, there are 2 ways to set them up. After registering the nodes to the hub, you can see all the nodes at the hub console (http://HUB_IP:HUB_PORT/grid/console).

  • Simple way: This ways is by providing all of the necessary informations in one command line. Different from the hub, the nodes need a bit more details, example:
java -Dwebdriver.gecko.driver=./geckodriver -jar selenium-server-standalone-3.7.1.jar -role node -hub http://192.168.1.2:4445/grid/register -port PORT -host IP -maxSession 10 -browser browserName=firefox,version=59,platform=LINUX,maxInstances=10

This line allow you to :

  • Inform the node the path of the driver for firefox (geckodriver).
  • Inform the node that it’s in charge of firefox, version 59 on linux and it can open up to 10 instances at a time.
  • Register the node to the hub at the hub’s registration address.
  • Specify the port and IP address that the node is on
  • Specify the capacity of the node.

You can set up multiple nodes on one machine, or across several machines, as long as the hub is reachable to the nodes.

  • Using a configuration file: Of course there are many more parameters you can assign for the node. Using a configuration file is more convenient than typing the command line all the time. Example (nodeConfig.json):
{
  "capabilities": [
    {
      "browserName": "firefox",
      "version": "58",
      "platform": "MAC",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "chrome",
      "version": "64",
      "platform": "MAC",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "safari",
      "platform": "MAC",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 5,
  "port": 5555,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://HUB_IP_ADDRESS:HUB_PORT",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets": [],
  "withoutServlets": [],
  "custom": {}
}

To launch the node:

On Windows:

java -Dwebdriver.chrome.driver=./chromedriver.exe -Dwebdriver.gecko.driver=./geckodriver.exe -Dwebdriver.edge.driver=./MicrosoftWebDriver.exe -jar selenium-server-standalone-3.x.x.jar -role node -nodeConfig nodeConfig.json

On Mac & Linux, Ubuntu:

java -Dwebdriver.chrome.driver=./chromedriver -Dwebdriver.gecko.driver=./geckodriver -jar selenium-server-standalone-3.x.x.jar -role node -nodeConfig nodeConfig.json

C. Browsers

While setting up the selenium nodes, you can also specify the path to the binary of the browsers, however, using the binary this way can cause some of the arguments that you want to use to launch the browser ineffective. I would recommend using only one version of one browser on each machine, configured so that the webdrivers can find them easily.

For Ubuntu 16.04 (Chrome Canary is not available):

  • Firefox Nightly, 4 easy steps (command lines):
sudo add-apt-repository ppa:ubuntu-mozilla-daily/ppa
sudo apt-get update
sudo apt-get install firefox-trunk
sudo mv /usr/bin/firefox-trunk /usr/bin/firefox
  • Chrome Dev, only 3 needed:
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo apt-get update
sudo apt-get install google-chrome-unstable

For Windows 10 (and Insider Preview):

  • Google Chrome Canary:
  • Install normally from the google chrome canary download page (https://www.google.com/chrome/browser/canary.html).
  • The canary version is install by default at C:\User\username\AppData\Local\Google\Chrome SxS. Therefore the chromedriver will not be able to find it. Coppy the Google folder to the supposed default folder of Chrome (C:\Program Files (x86)\Google)
  • Change the name of the sub folder "Chrome SxS" to "Chrome". Done.
  • Every time Chrome Canary updates, you'll need to move the folder like 2 steps above
  • Firefox Nightly: If there is only Nightly on the machine, geckodriver can find it without any problem.

  • Edge: appropriate version is install with the Windows 10 or Windows 10 Insider Preview, nothing to be done (Check to see if it's the latest version, if not, update Windows).

For HighSierra:

  • Google Chrome Canary:
  • Install normally from the google chrome canary download page (https://www.google.com/chrome/browser/canary.html).
  • Go into Applications, change the name of "Google Chrome Canary.app" to "Google Chome.app".
  • Go inside the package contents folder of the name of the binary to Google Chrome also (Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary). In some of the cases, the OS will attempt to rename the name of the binary back to Google Chrome Canary, so need to check this before run a test.
  • Done.
  • Firefox Nightly:
  • Safari (Stable 11.0):
  • Open Safari, on the top left, open the Preference menu (Safari/Prefrences...). Then in the Advance tab, enable the option "Show Develop menu in the menu bar".
  • In this newly enabled Develop top menu, enable "Allow Remote Automation".
  • Selenium will use the default path to safari driver so no noeed for specification.
  • Open STP make Develop tab visible by going to Safari/Preferences/Avanced -> Show Develop menu in menu bar
  • In the Develop tab of the top menu, enable "Allow Remote Automation".
  • Enable fake media stream for safari:
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2MockCaptureDevicesEnabled 1
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2MockCaptureDevicesPromptEnabled 0
  • Safari Technology Preview (Release 45):
defaults write com.apple.SafariTechnologyPreview IncludeInternalDebugMenu 1
  • Open STP, in the Develop tab of the top menu, enable "Allow Remote Automation".
  • Selenium 3.4.0++ should let you specify the path tho the STP driver (/Applications/Safari Technology Preview/Contents/MacOS/safaridriver).
  • Enable fake media stream for safari:
defaults write com.apple.SafariTechnologyPreview com.apple.Safari.ContentPageGroupIdentifier.WebKit2MockCaptureDevicesEnabled 1
defaults write com.apple.SafariTechnologyPreview com.apple.Safari.ContentPageGroupIdentifier.WebKit2MockCaptureDevicesPromptEnabled 0

D. Setup Virtual Machine for testing

For the Selenium Hub and Node, you don't necessarily have to use really physical machines, you can certainly use virtual machine to save budget or resources.

Prerequisite:

  • VirtualBox installed.
  • ISO files:
hdiutil create -o /tmp/HighSierra.cdr -size 5130m -layout SPUD -fs HFS+J
hdiutil attach /tmp/HighSierra.cdr.dmg -noverify -mountpoint /Volumes/install_build
sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/install_build
mv /tmp/HighSierra.cdr.dmg ~/Desktop/InstallSystem.dmg
hdiutil detach /Volumes/Install\ macOS\ High\ Sierra
hdiutil convert ~/Desktop/InstallSystem.dmg -format UDTO -o ~/Desktop/HighSierra.iso

You should get something like this:

You should now have a file called HighSierra.iso.cdr on your Desktop folder, rename it to HighSierra.iso, and you're good to go.

How to setup these VMs:

General steps:

  • Download and install VirtualBox
  • Create appropriate blank VMs:
    • Open VirtualBox, click New to start the setup wizard.
    • Input the name you want for the VM, choose appropriate OS and OS version for it, Continue.
    • Choose the RAM for VM, preferably 4GB, or 4096 MB, Continue.
    • Choose create a virtual hard disk now, then VDI (VirtualBox Disk Image), then Dynamically Allocated, input the name (the same as the machine name is better) and size (25 to 30GB is enough) for your hard disk, Create
    • Configure Settings for these blank VMs:
      • Verify your VM's name and OS in General Tab.
      • In System Tab, verify RAM, then in processor, increase the number of processor to at lease 2 (to ensure the smoothness of the VM).
      • In Display Tab, if the Video Memory is not 128MB, set it to 128MB.
      • In Storage Tab, choose the appropriate ISO file for the Optical Drive.
      • In Network Tab, choose Bridged Adapter, then in advanced option, choose Allow All for Promiscuous Mode.
      • OK.

For Ubuntu 16.04 and Windows 10:

  • Start up the VM, and follow the installation instructions as usual.
  • For updating to Windows 10 Insider:
    • Open up Windows Update, at the end on the left you should see the Insider Preview program

  • Click on that, and it will ask you to link to an Microsoft account, then choose Active Developments, then Fast, OK.
  • The VM will need to restart. Open Windows Update setting and update the OS to Insider Preview, this can take a while.

For HighSierra, it can be a little bit trickier:

  • Start up the VM, it will take you to MacOS Utilities Menu, open up the Disk Utility.

/images/grid/MacUtilities.png

  • You will not see the virtual hard disk that you created, on the top menu, click on View → Show all devices, then you will see it.
  • Select the virtual hard disk, then Erase.

/images/grid/MacUtilities2.png

  • Input the name you want for it, then Erase. Then close down the Disk Utility to go back to MacOS Utilities, choose install MacOS and proceed with the instructions.
  • When the installation is finish, and the VM reopened the MacOS Utilities, shut it down. Go back to the Setting in VirtualBox, eject the HighSierra.iso from the optical drive, then start it up again.
  • The VM will show something like this:

  • Don't worry, type "fs1:", Enter, if it shows FS1> instead of Shell> , you are OK. Next, type in these commands:
FS1:> cd "macOS Install Data"
FS1:\macOS Install Data> cd "Locked Files"
FS1:\macOS Install Data\Locked Files> cd "Boot Files"
FS1:\macOS Install Data\Locked Files\Boot Files> boot.efi
  • The installation will continue and you'll just have to wait and follow the instructions until the end. If it gets stuck at some point for too long, just restart the VM.

E. Maintenance Selenium grid

Browser updates

Normally, every 6 weeks or so, Mozilla and Google release a new stable version of their browsers. For the Nightly version of Firefox and Canary version of Chrome, well, they comes out nightly. So you might want to schedule your plan to keep them up to date, depending on what you are testing.

For Apple's Safari and Microsoft's Edge, there isn't any schedule for their releases. They can come out a new update every few month, half a year or a year, or can be every few days (Windows Insiders), so keep an eye out for their update to keep your grid up to date.

On Ubuntu

To update the browsers on ubuntu is quite simple. Update first:

sudo apt-get update

And then:

sudo apt-get install firefox
sudo apt-get install google-chrome-stable

for stable version of them, or:

sudo apt-get install firefox-trunk
sudo apt-get install google-chrome-unstable

for the Firefox Nightly and Chrome Dev

On Windows:

You can rely on auto update for Chrome and Firefox stable. However, the Nightly and Canary might require a bit more of effort.

To trigger their update, you can simply open their About page in their setting. For Chrome Canary, you might want to replace the folder in default Chrome installation folder like mention in the Browser Setup part of the documentation.

If you choose to skip this step, make sure that all of the flags (arguments) you want to use work when using Selenium's chrome_binary argument (fake-media flag doesn't work for example).

On High Sierra

Same as on Windows, the only difference is that you'll need to rename Google Chrome Canary to Google Chrome with every update since the OS renames it back to Canary, very annoying. And again, your choice.