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.

Udemy – Selenium WebDriver With Docker:

TestAutomationGuru has released a brand new course in Udemy on Selenium WebDriver with Docker. 14 hours course which starts with installing docker from scratch and goes all the way up to running dockerized selenium tests on AWS cloud. Please access the above link which gives you the special discount.  You can also get your money back if you do not like the course within 30 days.

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://localhost: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.

I have embedded this live preview in Jenkins itself. You would like to know how? Check here.

Dashboard:

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

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:

9 thoughts on “Selenium WebDriver – Disposable Selenium Grid Infrastructure Setup using Zalenium

  1. on Windows I can run it using this command

    docker run –rm -ti –name zalenium -p 4444:4444 ^
    -v /var/run/docker.sock:/var/run/docker.sock ^
    -v /d/docker:/home/seluser/videos ^
    –privileged dosel/zalenium start

    but following docker-compose.yml file doesn’t work
    version: ‘2.1’

    services:
    zalenium:
    image: “dosel/zalenium”
    container_name: zalenium
    hostname: zalenium
    tty: true
    volumes:
    – /d/docker:/home/seluser/videos
    – /var/run/docker.sock:/var/run/docker.sock
    – /usr/bin/docker:/usr/bin/docker
    ports:
    – 4444:4444
    command: >
    start –desiredContainers 2
    –maxDockerSeleniumContainers 8
    –screenWidth 800 –screenHeight 600
    –timeZone “Europe/Berlin”
    –videoRecordingEnabled true
    –sauceLabsEnabled false
    –browserStackEnabled false
    –testingBotEnabled false
    –startTunnel false
    environment:
    – HOST_UID
    – HOST_GID
    – SAUCE_USERNAME
    – SAUCE_ACCESS_KEY
    – BROWSER_STACK_USER
    – BROWSER_STACK_KEY
    – TESTINGBOT_KEY
    – TESTINGBOT_SECRET

    after run docker-compose up I got
    Creating zalenium … error

    ERROR: for zalenium Cannot create container for service zalenium: b’Mount denied:\nThe source path “\\usr\\bin\\docker:/usr/bin/docker”\nis not a valid Windows path’

  2. Hi, Sir

    After “http://ipofdockerenginer:4444/grid/admin/live#”, the below was I got
    “Hmm. We’re having trouble finding that site.
    We can’t connect to the server at ipofdockerenginer.
    If that address is correct, here are three other things you can try:
    Try again later.
    Check your network connection.
    If you are connected but behind a firewall, check that Firefox has permission to access the Web.”

    I need help!
    Thank

    Mak

  3. Someone can help me?
    When I trying to execute my test in parallel using zalenium, I have many problems with connection and my tests are ignored.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.