logo_zalenium_wide

Selenium WebDriver – Disposable Selenium Grid Infrastructure Setup using Zalenium

Overview:

We already have seen the challenges related to setting up the Selenium Grid infrastructure and how docker helps us in setting up a flexible/disposable/highly scalable selenium grid within few seconds in these articles below.

In this article, We will see how Zalenium (a similar dockerized selenium grid infrastructure with few other features) helps.

Zalenium Setup:

  • Ensure that you have latest docker engine is running. You can get the instructions here on installing docker.
  • Pull below docker images.
    • docker pull elgalu/selenium
    • docker pull dosel/zalenium
  • Run the below command to start the zaleniukm-selenium-grid
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
  • Zalenium is ready to use now in our tests.
DesiredCapabilities dc = DesiredCapabilities.firefox(); 
RemoteWebDriver driver=new RemoteWebDriver(new URL("http://10.11.12.13:4444/wd/hub"), dc);
 
driver.get("https://www.google.com");

Zalenium – Live Preview:

  • One of the cool features of zalenium is the live preview of the dockerized containers. We can access this using below URL.
    • http://ipofdockerenginer:4444/grid/admin/live#

zalenium-preview-001

  • 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 below arguments
    • –chromeContainers 3
    • –firefoxContainers 2
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

 

Demo:

I am running the test I had created as part of DatePicker Automation in this demo.

Dashboard:

  • Zalenium also has  a nice dashboard to show the list of recorded tests it has captured.
    • Can be accessed at this URL:  http://ipofdockerengine:5555

zalenium-dashboard-001

  • By default, name of the test has some random string which can be replaced by passing the name of test in the Desired Capabilities.
desiredCapabilities.setCapability("name", "myTestName");
  • Disable the video recording feature using below capability.
desiredCapabilities.setCapability("recordVideo", false);

Integrating with Cloud Testing Platforms:

  • Yet another cool feature of zalenium is – It can be integrated with cloud based testing solutions like BrowserStack/SuaceLabs.
  • Any incoming request to the hub is verified by zalenium – If it can create a container for the request, It starts a container and runs the test.
  • Otherwise, the test gets executed at the cloud testing platforms.

how_it_works

Sauce Labs:

export SAUCE_USERNAME=[your Sauce Labs username]
export SAUCE_ACCESS_KEY=[your Sauce Labs access key]
docker run --rm -ti --name zalenium -p 4444:4444 -p 5555:5555 \
        -e SAUCE_USERNAME -e SAUCE_ACCESS_KEY \
        -v /tmp/videos:/home/seluser/videos \
        -v /var/run/docker.sock:/var/run/docker.sock \
        dosel/zalenium start --sauceLabsEnabled true

BrowserStack:

export BROWSER_STACK_USER=[your BrowserStack username]
export BROWSER_STACK_KEY=[your BrowserStack access key]
docker run --rm -ti --name zalenium -p 4444:4444 -p 5555:5555 \
        -e BROWSER_STACK_USER -e BROWSER_STACK_KEY \
        -v /tmp/videos:/home/seluser/videos \
        -v /var/run/docker.sock:/var/run/docker.sock \
        dosel/zalenium start --browserStackEnabled true

For more information on Zalenium, please check here.

 

Happy Testing & Subscribe 🙂

 

Share This:

Categories: Articles, CI / CD / DevOps, Docker, Framework, Selenium, Selenium Grid