Setting up RSpec with Zalenium – a Selenium grid Docker solution

Femi Alashi -

The Problem?

  1. If you are looking to run your test on multiple browsers and can’t justify why you should have third party solutions like Browserstack or Sauce Labs, or you want more flexibility with third-party solutions.
  2. Setting up and running selenium grid on your local machine connected to other computers as nodes can be very hectic to set up, computers connected to the grid can go to sleep or have
    network issues, which can fail tests if there is no check for the active node before running test, just to mention a few issues with the current solution available. Adding all kinds of checks and writing extra code to manage grid makes the test suite too brittle to work with and diverts test engineers time from what is important, writing tests.

A Solution
The problem mentioned above is solved by integrating RSpec test framework with Zalenium.

What is Zalenium? 

Zalenium gets its name from the combination of Zalando and Selenium. It is a flexible and scalable container based Selenium Grid with video recording, live preview,
basic auth & dashboard built on docker-selenium to build a Selenium Grid in seconds, a grid that scales up and down dynamically with this solution based on docker-selenium
to run your tests in Firefox and Chrome.

Assumption
This tutorial assumes that you are somewhat familiar with Docker(Beginner level)

  • Can write tests in RSpec
  • Understands POM – Page Object Model

Getting started

Download and start Docker

Run test without Docker compose

  • On local Chrome:
    • run bundle exec rake local
  • Zalenium solution:
    • Set up – on your terminal


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 --desiredContainers 5 --maxTestSessions 5

The set up above simply means docker will be running a new container named – zalenium on port 4444:4444, mapping the videos gotten to the directory on /home/seluser/videos

The most important part of this command is on the last line and as the saying “Save the best for last”, that is exactly what is done in the command above. Privilege is given to dosel/zalenium which then enables it to start the number of desiredContainers as needed and also the maximum number of sessions that can be started simultaneously, the importance of having these sessions will be posted in the follow-up to this post, which will be on running tests parallel. ThedesiredContainers makes 5 containers available for us to run the test while maxTestSessions- allows the number of sessions declared

  • On the grid console, you can see 5 chrome and firefox browsers – Selenium grid console
  • On Terminal – bundle exec rake remote

Test Result

  • Rake local –
    • Finished in 41.82 seconds (files took 1.14 seconds to load)
      8 examples, 0 failures
  • Rake remote
    • Finished in 39.05 seconds (files took 0.76222 seconds to load)
      8 examples, 0 failures

Conclusion

As seen in the result above, Zalenium is more efficient and easy to set up when it comes to tests infrastructure. It is easy to scale depending on your organization’s needs. It has ready integrations for other third-party solutions like Sauce labs and Browserstack…

Happy Testing 🙂

author img

Femi Alashi

Over 7 years of excellent, broad experience and knowledge on the client-server and web-based application in Functional/ Non-functional testing using all test automation frameworks from Java-selenium, RSpec, Minitest, NightwatchJS to mention a few.

Leave a Reply

Your email address will not be published.