Setting Up and Using Selenoid

Sudeep Jayaram
3 min readMay 15, 2024

--

Selenoid is a powerful tool for running browser automation tests in Docker containers. This guide will walk you through the complete setup process, including prerequisites, configuration, and usage.

Prerequisites

— — — — — — — — — — — — — — — — — — — — — — — —
Before you begin, ensure that you have the following installed on your system:

1. Docker : Install Docker from [Docker’s official website](https://www.docker.com/get-started).
2. Docker Compose (optional but recommended for managing multiple containers): Install Docker Compose from [Docker’s official website](https://docs.docker.com/compose/install/).

Step-by-Step Setup

— — — — — — — — — — — — — — — — — — — — — — — —
1. Create a Configuration Directory

Create a directory on your local machine where you will store the Selenoid configuration files. I am considering selenoid-config folder in C drive.

mkdir -p C:\selenoid-config

2. Create the `browsers.json` Configuration File

Inside the `C:\selenoid-config` directory, create a file named `browsers.json` with the following content:

{
“firefox”: {
“default”: “latest”,
“versions”: {
“latest”: {
“image”: “selenoid/firefox:latest”,
“port”: “4444”,
“path”: “/wd/hub”,
“maxDockerSessions”: 5
}
}
},
“chrome”: {
“default”: “latest”,
“versions”: {
“latest”: {
“image”: “selenoid/chrome:latest”,
“port”: “4444”,
“path”: “/”,
“maxDockerSessions”: 5,
“vnc”: {
“enabled”: true
},
“log”: {
“enable”: true
}
}
}
},
“MicrosoftEdge”: {
“default”: “latest”,
“versions”: {
“latest”: {
“image”: “browsers/edge:latest”,
“port”: “4444”,
“path”: “/”,
“maxDockerSessions”: 5
}
}
},
“safari”: {
“default”: “15.0”,
“versions”: {
“15.0”: {
“image”: “browsers/safari:15.0”,
“port”: “4444”,
“path”: “/”
}
}
}
}

3. Pull the Required Browser Images

Pull the necessary Docker images for the browsers you want to use.

docker pull selenoid/chrome:latest
docker pull selenoid/firefox:latest
docker pull browsers/edge:latest

4. Run Selenoid

Run the Selenoid container with the following command:

<windows>
docker run -d — name selenoid -p 4444:4444 -v /var/run/docker.sock:/var/run/docker.sock -v C:\selenoid-config:/etc/selenoid:ro aerokube/selenoid:latest-release -conf /etc/selenoid/browsers.json -limit 7

<linux>
docker run -d — name selenoid -p 4444:4444 -v /var/run/docker.sock:/var/run/docker.sock -v C:\selenoid-config:/etc/selenoid:ro aerokube/selenoid:latest-release -conf /etc/selenoid/browsers.json -limit 7

5. Run Selenoid UI

Run the Selenoid UI container to provide a web interface for managing and monitoring your Selenoid instance:

<windows/linux>
docker run — rm -d — name selenoid-ui — link selenoid:selenoid -p 8080:8080 aerokube/selenoid-ui — selenoid-uri=http://selenoid:4444

6. Access Selenoid UI

Open your browser and navigate to `http://localhost:8080` to access the Selenoid UI. This interface will allow you to see the running sessions, logs, and more. If you have setup in a VM then use `http://<VM_IP>:8080`

Using Selenoid

— — — — — — — — — — — — — — — — — — — — — — — —
1. Integrate with Your Test Automation Framework

Selenoid can be integrated with popular test automation frameworks like Selenium WebDriver. Below is an example of how to configure Selenium WebDriver to use Selenoid.

Java Example (Using Selenium WebDriver)

Add the following dependencies to your `pom.xml` file if you are using Maven:

<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.x.x</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>4.x.x</version>
</dependency>
</dependencies>

Use the following Java code to configure WebDriver to use Selenoid:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.MalformedURLException;
import java.net.URL;

public class SelenoidTest {
public static void main(String[] args) {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(“chrome”);

try {
WebDriver driver = new RemoteWebDriver(new URL(“http://localhost:4444/wd/hub"), capabilities);
driver.get(“http://www.example.com");
System.out.println(driver.getTitle());
driver.quit();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}

2. Running Tests

Run your tests as usual. The tests will be executed in the Docker containers managed by Selenoid.

3. Monitoring Tests

Use the Selenoid UI (`http://localhost:8080`) to monitor the status of your tests, view logs, and access other useful information.

Conclusion

— — — — — — — — — — — — — — — — — — — — — — — —
By following these steps, you will have a fully functional Selenoid setup capable of running automated browser tests in Docker containers. This setup ensures a scalable and efficient testing environment, leveraging the power of containerization.

--

--