Skip to content

Selenium Module

Selenium If you want to create robust, browser-based regression automation suites and tests, scale and distribute scripts across many environments, then you want to use Selenium WebDriver, a collection of language specific bindings to drive a browser - the way it is meant to be driven.

Install

npm install @testcontainers/selenium --save-dev

Examples

Spin up a Chrome web browser and navigate to a URL:

const { SeleniumContainer } = require("@testcontainers/selenium");

const container = await new SeleniumContainer("selenium/standalone-chrome:112.0")
  .start();

const driver = await new Builder()
  .forBrowser(Browser.CHROME)
  .usingServer(container.getServerUrl())
  .build();

await driver.get("https://testcontainers.com");
await driver.quit();

You can use any Selenium supported web browser by providing the appropriate image and driver configuration, for example:

const container = await new SeleniumContainer("selenium/standalone-edge:112.0")
  .start();

const driver = await new Builder()
  .forBrowser(Browser.EDGE)
  ...
  .build();

A video recording of the browser session can be enabled and saved to disk once the container has been stopped:

const container = await new SeleniumContainer("selenium/standalone-chrome:112.0")
  .withRecording()
  .start();
...

const stoppedContainer = await container.stop();
await stoppedContainer.saveRecording("/tmp/videos/recording.mp4");

Troubleshooting

ARM architecture

Selenium images are not available for ARM architectures. Luckily, there are equivalent, ARM compatible images available via Seleniarm:

seleniarm/standalone-chromium:112.0
seleniarm/standalone-firefox:112.0
const { SeleniumContainer } = require("@testcontainers/selenium");

const container = await new SeleniumContainer("seleniarm/standalone-chromium:112.0")
  .start();

const driver = await new Builder()
  .forBrowser(Browser.CHROME)
  .usingServer(container.getServerUrl())
  .build();

await driver.get("https://testcontainers.com");
await driver.quit();