Tried Zalenium to run Selenium tests on scalable containers
Tags: zalenium, selenium, geb, groovy
Published: 2018-04-04 15:09:43

---
title: Tried Zalenium to run Selenium tests on scalable containers
published: true
description: 
tags: #zalenium #selenium #geb #groovy
---

My friend, who is a great test engineer, mentioned Zalenium yesterday and I was interested in it. So I tried it.

## Zalenium?

https://zalando.github.io/zalenium/

After a few hours trial, I've come to like it because

* 1) it's very easy to try in my local machine,
* 2) it dynamically starts containers to run Selenium tests,
* 3) and provides video recording of the tests

## 1) it's very easy to try in my local machine

### Start Zaleinum

```bash
# Pull 2 docker images
docker pull elgalu/selenium
docker pull dosel/zalenium

# Run it!
docker run --rm -ti --name zalenium -p 4444:4444 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /tmp/videos:/home/seluser/videos \
  --privileged dosel/zalenium start
```

(You may want to take care when you mount docker.sock, though it isn't a main topic here.)

Then you can access Live Preview page http://localhost:4444/grid/admin/live and find 2 machines are running.

![Live Preview](https://thepracticaldev.s3.amazonaws.com/i/yzahzecr9idpsdsuxic9.png)

### Run your tests

Now you are ready to run your Selenium tests on Zalenium.

I parepared Geb script here since I like it, but you can use whatever you like.

http://www.gebish.org/

**HelloZelenium.groovy**

```groovy
Browser.drive {
  go "http://gebish.org"

  assert title == "Geb - Very Groovy Browser Automation"

  $("div.menu a.manuals").click()
  waitFor { !$("#manuals-menu").hasClass("animating") }

  $("#manuals-menu a")[0].click()

  assert title.startsWith("The Book Of Geb")
}

```

This is from Geb document. I skip the explanation of this script, because I think you can easily imagine what it does.

**GebConfig.groovy**

```groovy
driver = {
  def capabilities = new DesiredCapabilities();
  capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
  capabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.LINUX);

  def remoteWebDriverUrl = new URL("http://localhost:4444/wd/hub")
  new RemoteWebDriver(remoteWebDriverUrl, capabilities)
}
```

We can set configuration with GebConfig. We use RemoteWebDriver with the Zelenium Hub URL.

Full source code including `import` is here: https://gist.github.com/bufferings/a8980ea515a893e21a3a95955ace5dc9

Run the test

```bash
groovy HelloZalenium
```

Then you can see the tests are executed on the live preview page.

![Live Preview](https://thepracticaldev.s3.amazonaws.com/i/3sjj8eqddbfqp25q7ts5.png)

So easy!!

## 2) it dynamically starts containers to run Selenium tests,

Then I would like to run multiple tests simultaneously.

```
for i in {1..8};do groovy HelloZalenium & done
```

Then, 8 machines are up and testing! After the tests, it automatically shutdown the containers.

![Live Preview3](https://thepracticaldev.s3.amazonaws.com/i/4mnjn4erdt7wsduq7tw7.png)

## 3) and provides video recording of the tests

By default, all the tests are recorded. We can check them on http://localhost:4444/dashboard/#

![Recorded Video](https://thepracticaldev.s3.amazonaws.com/i/odim68hse2g8fxvtfy14.png)

## Configuration Options

In addition, we can ask Zelenium to do something by configuration for example:

```
driver = {
  def capabilities = new DesiredCapabilities();
  capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);
  capabilities.setCapability(CapabilityType.PLATFORM_NAME, Platform.LINUX);
  capabilities.setCapability("screenResolution", "1280x720");
  capabilities.setCapability("tz", "Asia/Tokyo");

  def remoteWebDriverUrl = new URL("http://localhost:4444/wd/hub")
  new RemoteWebDriver(remoteWebDriverUrl, capabilities)
}
```

In this time, we can see FireFox is used with 1280x720 and Asiz/Tokyo timezone.

![Live Preview4](https://thepracticaldev.s3.amazonaws.com/i/7krp9rt8w3sjkh6wy1b7.png)

## and more!

I haven't tried yet, but Zalenium has nice features more:

* SauceLabs/BrowserStack/TestingBot integration
* Support Kubernetes environment
* etc...


## Conclusion

Zelenium is so convenient and easy to run Selenium Grid with Docker. I would like to keep trying and learning it!