This post documents how I set up the Ubuntu Selenium node I was using for generating screenshots about Claro’s components.

Requirements

  • A Selenium hub instance that is able to accept node registrations.
  • A working and properly configured Ubuntu VirtualBox machine.

    If you don’t have this,

    • Download a desktop Ubuntu iso (from the official page or from a mirror)
    • Create a new VirtualBox machine for the Ubuntu instance:
      • Set Type to Linux
      • Set Version to Ubuntu (64-bit)
      • RAM could be be 2048Mb
      • Virtualized hard drive’s size 10Gb
    • Install Ubuntu
    • Install Google Chrome
    • Change the VM network adapter to Bridged Adapter
  • Java runtime environment: sudo apt install default-jre
  • The standalone Selenium server 3.4.0
  • The latest geckodriver, and a chromedriver whose version is compatible with the installed Chrome.
  • Executable flag on Selenium, geckodriver and chromedriver binaries: chmod u+x selenium-server*.jar geckodriver chromedriver

If you have these set up, you’re able to start and run Selenium in any kind of role.

Configuration and some DX

For running a Selenium node instance, you have to provide webdriver paths, the endpoint of your running Selenium hub instance and define your node’s capabilities. I strongly advise to use a config file for this.

This is what I have in my selenium-node-config--3.4.0--ubuntu.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
  "capabilities":
  [
    {
      "browserName": "firefox",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "chrome",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 6,
  "port": 5660,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://localhost:4444",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {}
}

As you can see, I hard-coded some dynamic stuff like the url of the Selenium hub instance or the port number. Thanks to Selenium, these values can easily be overridden with CLI arguments.

The usual bash script which starts the Selenium in node role:

1
2
3
4
5
6
7
8
9
#!/bin/bash
HOST=${1:-"172.16.0.107"}
java \
  -Dwebdriver.gecko.driver="~/selenium/geckodriver" \
  -Dwebdriver.chrome.driver="~/selenium/chromedriver" \
  -jar ~/selenium/selenium-server-standalone-3.4.0.jar \
  -role node \
  -hub http://"$HOST":4444/grid/register \
  -nodeConfig ~/selenium/selenium-node-config--3.4.0--ubuntu.json

The main goals of this script are:

  • I don’t have to remember command line args and params
  • If I don’t specify a host, the node will use the default IP 172.16.0.107 – this is my laptop’s static address if I’m at Cheppers’ office 🙃

Profit

If you strictly follow this article and have the same config and bash script too, you are done. Launch your local Selenium hub, and in the Ubuntu guest, execute the script: ./selenium-node.sh. If you see “INFO - The node is registered to the hub and ready to use”, you can use this new node for using the browsers on Ubuntu.