Auto Scale Selenium Grid with Runtime Container- Zalenium

Lakmali Bandara
Javarevisited
Published in
2 min readSep 11, 2021

--

Zalenium is a flexible and scalable container-based Selenium Grid, with video recording, live preview, basic auth & a dashboard. Moreover, it has out-of-the-box Docker and Kubernetes integration. This fact makes Zalenium an attractive choice to get Selenium-based infrastructure up and running.

Zalenium provides docker images (Hub + Nodes) with the latest browser drivers, browsers, and tools (for any language bindings) required for Selenium automation. The containers created from these images can be scaled up with simple CLI commands.

This is a Selenium Grid extension to scale your local grid dynamically with docker containers. It uses docker-selenium to run your tests in Firefox and Chrome locally, if you need a different browser, your tests can get redirected to a cloud testing provider (Sauce Labs, BrowserStack, TestingBot, CrossBrowserTesting, LambdaTest).

Why use Zalenium?

Zalenium was created to solve the widespread issue that a lot of people have when they have some tests, and you want to start running them in parallel. You start by getting into Selenium Grid but encounter roadblocks pretty quickly when trying to scale.

The most common issue is that you need to start to keep up with the release of the new Selenium Versions and to have them in synchronization with the browser releases and the browser drivers release like chrome driver, gecko driver, and so on.

You end up spending a lot of time configuring all these moving parts.

Zalenium was created to handle these issues for you automatically.

Zalenium Setup:

  1. Ensure that you have the latest docker engine is running. You can get the instructions here on installing docker.

2. After installing docker, check with the below command: docker -v

3. Pull below docker images by below command.
docker pull elgalu/selenium
docker pull dosel/zalenium

4. Check the docker images by below command:docker image

5. Run Zalenium by below command on cmd:

docker run --rm -ti --name zalenium -p 4444:4444 -p 5555:5555 -v /var/run/docker.sock:/var/run/docker.sock -v /tmp/videos:/home/seluser/videos dosel/zalenium start

After successfully running the previous commands, you can check:

docker ps -m

Now you can access below :

Grid consolehttp://localhost:4444/grid/console
Zalenium Live Preview http://localhost:4444/grid/admin/live
Dashboardhttp://localhost:4444/dashboard/ after running your first test

Run the selenium script by modifying the code:

DesiredCapabilities dc = DesiredCapabilities.firefox(); //or dc = DesiredCapabilities.chrome();

RemoteWebDriver driver=new RemoteWebDriver(new URL("http://HostName:4444/wd/hub"), dc);

driver.get("https://www.google.com");

You can live to watch the application running by Zalenium live Preview:

after execution you can watch the video of the test from the Zalenium Dashboard:

By default, our Selenium grid will have 1 Chrome and 1 Firefox container. If you need more, say 3 chrome containers, 2 firefox then use the below arguments.

docker run --rm -ti --name zalenium -p 4444:4444 -p 5555:5555 \

-v /var/run/docker.sock:/var/run/docker.sock \

-v /tmp/videos:/home/seluser/videos \

dosel/zalenium start --chromeContainers 3 --firefoxContainers 2

--

--

Lakmali Bandara
Javarevisited

Technical Lead Quality Engineering | Framework Developer | API Tester | Blogger