info@pragmatictesters.com +94 11 253 8512


Introduction

What is selenium grid?

Selenium grid is used to run test execution in different machines, different operating systems and multiple browsers at the same time.

What is Docker?

Docker is similar to a virtual machine and it consists  a docker container. By using that container developer can create, deploy, and run applications. Docker containers allow you to package up an application with all  the parts it needs, such as libraries and other dependencies, and ship it out as one package.

1

Pre-requisites

  1. JDK 1.7  or later is installed
  2. All required web browsers are installed on local machines  
  3. Selenium WebDriver + Java + TestNG test cases are available.
  4. Testng.xml file is configured to run the test suite successfully

Downloading Docker for windows

To run the “docker” command you need to install Docker tool box. You can download it from https://www.docker.com/products/docker-toolbox link. Then install the file. If you installed it successfully you will get following Docker tool box icons

2

After opening “Docker quickstart terminal”, Docker will configure your default machine with the IP Address: 192.168.99.100.

3

 

Install the Docker Images

To use selenium grid with Docker you need to install the following 5 images to your Docker container.

  1. Selenium/hub
  2. Selenium/node-firefox
  3. Selenium/node-chrome
  4. Selenium/node-firefox-debug
  5. Selenium/node-chrome-debug
  • Command for selenium/hub: docker pull selenium/hub
  • Command for selenium/node-firefox: docker pull selenium/node-firefox
  • Command for selenium/node-chrome: docker pull selenium/node-chrome
  • Command for selenium/node-firefox-debug: docker pull selenium/node-firefox-debug
  • Command for selenium/node-chrome-debug: docker pull selenium/node-chrome-debug

4

After entering each command, docker will get some time to download the images to the container. Therefore you have to wait some time. After downloading all the images you can check your container using “docker images” command.

5

Start selenium hub

First of all you have to start selenium hub

docker run -d -p 4444:4444 – – name selenium-hub selenium/hub

6

After that you can verify that whether the selenium grid is running or not by navigating http://192.168.99.100:4444/grid/console

7

 

Start selenium nodes

Once the hub is up and running, you need to launch the nodes that are needed to run the tests. You can run  many nodes as you wish.

docker run -d –link selenium-hub:hub selenium/node-chrome

docker run -d –link selenium-hub:hub selenium/node-firefox

8

Start debug mode of each browser

docker run –link selenium-hub:hub selenium/node-chrome-debug

docker run –link selenium-hub:hub selenium/node-firefox-debug

Sometimes these two commands will be ignored by the Docker quick start terminal. If so you can use below commands for starting debug mode of each browsers

docker run –d –P –link selenium-hub:hub selenium/node-chrome-debug

docker run –d –P –link selenium-hub:hub selenium/node-firefox-debug

                                                 OR

docker run –d –link selenium-hub:hub selenium/node-chrome-debug

docker run –d –link selenium-hub:hub selenium/node-firefox-debug

9

Then start “debug mode” in VNC (Virtual Network Computing) viewer to view different browser actions in the same computer.

After refreshing your browsers “Firefox” and “Chrome”, the nodes will be opening under selenium hub.

211213

By using docker ps –a command, you can see all  the Docker containers and their running ports.

134242

Here the running port number for Chrome is 32771 and running port number for Firefox is 32772

Now you can up two browsers by using VNC viewer

999999

  • Then VNC viewer will ask a password to up the browser. You need to type the password as “secret”  and then click “Ok”. Then Chrome browser will be open.
  • Like that, you have to open the Firefox browser by using VNC viewer. For that open the VNC application in your local computer and use Firefox running port number
  • (In my example port number is 32772)

ukukuk

Configuring Selenium Tests

As usual you have to create an automation script for selenium grid.

yryry

Your grid.xml will be like this

ggsdg

After executing your grid script the VNC viewer will open the browsers and run the test.

fdgfgf

 

 

Author: Janesh Kodikara

Performance Tester | JMeter Trainer | Software Testing Service Provider

Your Turn To Talk

Leave a reply:

Your email address will not be published.