How to set up your Selenium Grid Infrastructure using Zalenium

Why do we need selenium grid?

When you want to run 100s of automated UI tests in parallel over multiple browsers to reduce automation testing time and get early feedback, you need a selenium grid infrastructure.

What is Zalenium?

Zalenium is an open-source project that helps set up a selenium grid infrastructure that scales up and down dynamically. It is a docker-selenium based solution to boot up the grid within seconds.

Features

  • It works out of the box in Docker and Kubernetes.
  • Video recording of the test run.
  • Provides a dashboard for viewing logs, videos, etc.
  • Provides authentication for security while running the grid in AWS etc.
  • Live preview of the test run.
  • Out of the box supports firefox and chrome browsers.

How to setup Zalenium

  • Pull Selenium docker image.

    docker pull elgalu/selenium
    
  • Pull Zalenium docker image.

    docker pull dosel/zalenium
    
  • Start Zalenium on MacOS

     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 2
    
  • Start Zalenium on Linux

    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 2
    

The start Zalenium commands should be copy-pasted in one line – there should not be any line breaks.

Once the Zalenium grid starts successfully with 2 nodes, you can access:

Grid console: http://localhost:4444/grid/console

Grid Preview: http://localhost:4444/grid/admin/live

Dashboard - http://localhost:4444/dashboard/

How to run tests on Selenium Grid

  • Set the remote URL to the Zalenium grid URL

    DesiredCapabilities cap = DesiredCapabilities.firefox(); 
    URL url = new URL("http://localhost:4444/wd/hub");
    WebDriver driver = new RemoteWebDriver(url, cap);  	
    
  • Set any other Zalenium specific capabilities if required as shown below:

    DesiredCapabilities cap = new DesiredCapabilities();
    caps.setCapability(CapabilityType.BROWSER_NAME, "firefox");
    caps.setCapability("zal:name", "myTestName");
    caps.setCapability("zal:build", "myTestBuild");
    caps.setCapability("zal:tz", "Europe/Berlin");
    caps.setCapability("zal:screenResolution", "1280x720");
    caps.setCapability("zal:idleTimeout", 180);
    caps.setCapability("zal:recordVideo", false);  
    

Desired Capabilities reference: Zalenium Website

Free Resources