Selenium Grid and TestingBot

Selenium Grid is an open-source project that provides distributed testing on a variety of browsers, across different machines called nodes. Setting up and maintaining a Selenium Grid takes time and effort. For every new browser version release, the configuration will need to be adjusted.

You'll need to configure the appropriate driver (ChromeDriver, GeckoDriver, SafariDriver, IEDriver, ...), provision enough hardware and tune for performance.

Running tests on TestingBot takes away the hassle of setting up and configuring a Selenium Grid yourself. TestingBot supports 100% compatibility with Selenium and Selenium Grid and has enhanced it with new useful features:

  • Screen recording and automated screenshots for every session.
  • Every test runs on a single-use VM, configured for performance and stability.
  • Integration with various CI/CD solutions.
  • Share test results and capacity with other team members.
  • Insight into test failures with Test Insights.

Installing Selenium Grid

To get started, please make sure you have a machine that has these things available:

The machine will serve as a Selenium Grid endpoint. Tests will need to use this machine's IP address to forward test requests to. The Grid will then forward the requests to the appropriate nodes connected to the grid.

To install the Grid, please follow the Selenium Grid documentation.

Running tests on Selenium Grid

Once you have installed and configured your Selenium grid, you are ready to configure your tests to use the Selenium Grid. Below we'll show an example on how to change your existing tests from running on a local browser on your computer, to using the Selenium Grid you've just set up.

WebDriver driver = new ChromeDriver();
WebElement element = driver.findElement(By.name("q"));
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"), new ChromeOptions());
WebElement element = driver.findElement(By.name("q"));

In the example above we assume the Selenium Grid was set up on the same machine as the test you are running it from (http://localhost:4444).

Extending Selenium Grid with TestingBot

Once you have your own Selenium Grid running, you might want to extend it with browsers that are currently not available on your local network. Adding macOS, mobile browsers and physical devices takes a lot of effort. Expand your Selenium Grid with TestingBot's extensive grid of browsers and devices.

Selenium Grid offers a Relay feature that enables a local Selenium Grid to add TestingBot as an extra node. This means your tests can target browsers and devices that are not available on your local Selenium Grid, while still using the nodes that are available from your local Grid.

This results in a hybrid solution of using a local Grid, with low latency, and the TestingBot Grid with extensive coverage.

Create a toml Configuration File

Below is a sample config.toml configuration file:

detect-drivers = false

url = "https://hub.testingbot.com/wd/hub"
configs = [
  "5", '{"browserName": "chrome", "platformName": "Windows 11", "browserVersion": "110"}',
  "10", '{"browserName": "firefox", "platformName": "Windows 10", "browserVersion": "110"}',
  "5", '{"browserName": "safari", "platformName": "macOS 13", "browserVersion": "16"}',
  "2", '{"browserName": "safari", "platformName": "iOS", "appium:platformVersion": "16.2", "appium:deviceName": "iPhone 14 Simulator"}',
  "2", '{"browserName": "chrome", "platformName": "android", "appium:platformVersion": "13.0", "appium:deviceName": "Pixel 6a"}'

This will add 5 extra browser combinations, through the use of the Selenium Grid relay function. The configuration determines the capabilities that will be relayed to TestingBot, together with the maximum number of concurrent tests per configuration.

We can now start your local Selenium grid with the extra relay functionality:

java -jar selenium-server-<version>.jar node --config config.toml

Now your tests can use your own Selenium grid to run tests on your own nodes, as well as on TestingBot.

Run a test on a Selenium Grid

The following example shows how to run a test on your local Selenium Grid with forwarding to TestingBot.

SafariOptions browserOptions = new SafariOptions();
browserOptions.setPlatformName("macOS 13");

Map<String, Object> tbOptions = new HashMap<>();
tbOptions.put("username", System.getenv("TB_KEY"));
tbOptions.put("accessKey", System.getenv("TB_SECRET"));
browserOptions.setCapability("tb:options", tbOptions);

RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"), browserOptions);
WebElement element = driver.findElement(By.name("q"));

Even though this example references your local Selenium grid, it will forward the test request to TestingBot if the capability is not available on your local grid.