What is a Docker?

A Docker is similar to a virtual machine which consists of Docker containers. By using the container we will be able to create, deploy and run the applications. Then here comes a question like what is a container?.  A Docker container allows 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:

  • Docker installed in the  Local machine.
  • JDK 1.7 or above.
  • All web browsers installed on Local machine.
  • Selenium WebDriver + JAVA + TestNG test cases.
  • VNC viewer – for running the web browsers.
  • If you are running on Windows machine you need to have Windows 10 OS because docker supports only in Windows 10.
  • If you are running on MAC machine then you need to have Apple Mac OS Yosemite 10.10.3 or above.

You can download the docker for Windows from here & for Mac from here.

Steps to be followed when installing docker:

  • Once the binaries are downloaded, install the docker.
  • Turn ON the virtualization in the local machine.
  • Open the docker and click on the checkbox & expose Daemon on TCP://localhost. This allows to makes yourself vulnerable to remote execution attacks.

Once Docker is installed, open the command prompt and type

Docker –info this will give all the information about the installed docker.

To run the selenium webdriver scripts with docker you need to  download the following images and add to the docker container.

 

  • Selenium/hub  – which acts as a Selenium hub
  • Selenium/node-firefox – To access the firefox browser
  • Selenium/node-chrome – To access the chrome browser
  • Selenium/node-firefox-debug – To access the firefox browser via port
  • Selenium/node-chrome-debug – To access the chrome browser via port.

Smarter Test Management For QA Teams

Free up to 300 Test Cases. No credit card required

Sign up for free

Commands to download the images:

  • docker pull selenium/hub : Command for selenium hub
  • docker pull selenium/node-firefox : Command for selenium/node-firefox
  • docker pull selenium/node-chrome : Command for selenium/node-chrome
  • docker pull selenium/node-firefox-debug: Command for selenium/node-firefox-debug:
  • docker pull selenium/node-chrome-debug : Command for selenium/node-chrome-debug

Once the image is downloaded you need to start the downloaded images.

To start the selenium hub, run the below command:

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

After running this command, from the browser navigate to the your IP address followed by the port number and /grid/console. So the command will be

http://ipaddress:4444/grid/console

You will see the console running on the URL.

Then you need to start the chrome or Firefox nodes. For starting the nodes run the following commands from the command prompt.

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

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

Then you need the start the chrome or Firefox debug. For that run the below commands.

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

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

Then run the command docker ps -a – This command will list all the docker containers installed in the system and running on the port number.

container

Then refresh the link http://192.168.1.1:4444/grid/console . There you can find the chrome or Firefox nodes opening under selenium hub.

Setting up the browsers:

  • Run the VNC viewer
  • Click on the new connection.
  • In the VNC server field, enter the hub URL and the port number for the chrome or Firefox browser. The port number for each browser will be visible in the command prompt. port numbervnc viewer
  • Then click on “OK” button.
  • It will prompt and ask for the password. By default the password is “secret”. Then click on “CONNECT”. Then the browser will open.

Configuring Selenium Tests:

Once all the setup is completed, we need to connect our selenium scripts with the selenium hub.

For connecting to the hub add the below line of snippet  in your selenium script

driver = new RemoteWebDriver (new URL(“http://your ip address:portnumber/wd/hub”), capabilities);

Sample Script:

package docker;

import java.net.MalformedURLException;

import java.net.URL;

import java.sql.Driver;

import org.openqa.selenium.Platform;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.testng.annotations.Test;

public class NewTest {

 @Test

 public void dockerimp() throws MalformedURLException {

 DesiredCapabilities capabilities = DesiredCapabilities.firefox();

 capabilities.setCapability(“version”, “”);

 capabilities.setPlatform(Platform.WINDOWS);

 RemoteWebDriver driver = new RemoteWebDriver(new URL(“http://ipaddress:4444/wd/hub”),capabilities);

 driver.get(“https://localhost.com”);

 System.out.println(driver.getTitle());

 }

 }

Once the script is updated run it, then you will see the VNC viewer open the respective browser and run the test.

Hope the procedure turned out to be useful. A ton of know-how articles like this are down the pipeline and do stay subscribed to get notified about those.

References:
http://www.seleniumeasy.com/selenium-tutorials/configure-selenium-grid-using-docker
http://pragmatictestlabs.com/2016/10/13/selenium-grid-docker/
https://docker-curriculum.com/




Ready to Write an Interesting blog in QA touch?


If you have an interesting blog post you would want to share with the Testing Community, please forward it to info@qatouch.com along with your picture and a short bio. Our editorial team will review and publish it.

Subscribe to our blog

Prasanna Venkatesh

Prasanna Venkatesh

Prasanna Venkatesh – a Senior Quality Analyst in DCKAP, has experience in successfully delivering Quality Products and Services. He is passionate about everything in QA and takes ownership of every task. Loves to play cricket and chess.

Leave a Reply

avatar