DEV Community

Mitz
Mitz

Posted on

Tried Zalenium to run Selenium tests on scalable containers

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

# 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
Enter fullscreen mode Exit fullscreen mode

(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

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

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")
}

Enter fullscreen mode Exit fullscreen mode

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

GebConfig.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)
}
Enter fullscreen mode Exit fullscreen mode

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

groovy HelloZalenium
Enter fullscreen mode Exit fullscreen mode

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

Live Preview

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
Enter fullscreen mode Exit fullscreen mode

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

Live Preview3

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

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)
}
Enter fullscreen mode Exit fullscreen mode

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

Live Preview4

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!

Top comments (3)

Collapse
 
avinashrana profile image
avinashrana

Hello,

I would like to know how can I run my selenium tests on UNIX platform? I am done with the LINUX platform (I used the same desired capabilities in my MacBook Pro using java mentioned above in your script). I am using the MacBook Pro (OSX).

So I re-phrase my question --> How can I run my selenium script with the platform as UNIX using zalenium & docker. Any help is much appreciated.

Regards,
Avinash Rana
avinashrajput455@gmail.com

Collapse
 
flohrein profile image
Florian Rein • Edited

A bit late to the party.. I compiled a minimal Zalenium Setup a while ago. Maybe this helps you getting up & running at least on Macos. As long as UNIX supports docker, it should run there too.

florianreinhard.de/2019-06-23/zale...

Collapse
 
karloabapo profile image
Karlo Abapo

I tried it today and it's cool! It's my first time to setup docker containers and selenium grid. I still don't know how to parallel test and put it on a CI but that's next on the list.