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.
Pre-requisites
- JDK 1.7 or later is installed
- All required web browsers are installed on local machines
- Selenium WebDriver + Java + TestNG test cases are available.
- 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
After opening “Docker quickstart terminal”, Docker will configure your default machine with the IP Address: 192.168.99.100.
Install the Docker Images
To use selenium grid with Docker you need to install the following 5 images to your Docker container.
- Selenium/hub
- Selenium/node-firefox
- Selenium/node-chrome
- Selenium/node-firefox-debug
- 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
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.
Start selenium hub
First of all you have to start selenium hub
docker run -d -p 4444:4444 – – name selenium-hub selenium/hub
After that you can verify that whether the selenium grid is running or not by navigating http://192.168.99.100:4444/grid/console
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
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
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.
By using docker ps –a command, you can see all the Docker containers and their running ports.
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
- Download VNC viewer from https://www.realvnc.com/download/viewer/
- Run it
- Type your hub URL and port number of each browser (debug mode browser)
- Click connect button
- 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)
Configuring Selenium Tests
As usual you have to create an automation script for selenium grid.
Your grid.xml will be like this
After executing your grid script the VNC viewer will open the browsers and run the test.
Comments