Selenium with Docker for Test Case Execution

 What is docker ?

Docker is the next step beyond virtualisation. A Docker image contains everything it needs to run, independent of the Linux server on which it lives: a copy of the operating system, a database, code, configuration files, dependencies, and so on. Images can also be packaged and shared with other Docker admins.

Why selenium execution using Docker ?

Selenium helps you run tests locally, and it makes the process easy as you can configure your Windows manager. Wrapping the tests with Docker will help you easily move it to a different workspace as required.

One of the biggest benefits of Docker is its capacity to scale. It’s particularly helpful because running Selenium grid on virtual machines or even separate machines takes up a lot of unnecessary computing overhead. Docker images share some system resources, so you need less resources than a virtual machine. You can easily cram several nodes in a single instance. Both Docker and Compose also handle the networking part easily.

Once Docker installation is complete, SeleniumHQ maintains the whole range of Docker images. These images can be pulled down easily and used right away. The list of images is available at Docker Hub or GitHub repository, and falls into four main categories:

Base - Where you can build your own images.

Hub - A cloud-based registry service where you can link to code repositories so you can create images, test and store them.

Node - Images used in correlation with Hub image and general Selenium grid. It is possible to start a number of node containers with Hub image.

Standalone - Standalone images on the Selenium server. However, it is possible to run only one at a time on the local machine, or there will be a 4444 port conflict.

Docker setup -

Create account on - https://hub.docker.com/ 

Search images for selenium - 

https://hub.docker.com/search?q=selenium&type=image

If you want to see the execution of test cases then you should prefer debug images for selenium -

Ex -

1. selenium/node-chrome-debug

2. selenium/node-firefox-debug 

3. selenium/hub 

Download VNC player to see execution 

- https://www.realvnc.com/en/connect/download/viewer/macos/

Command to start the docker -

Create docker configuration file - docker-compose.yml 

and hit below command to start the docker -

  1. docker-compose up -d ( inside docker file folder) 
  2. docker-compose ps  ( command to get IP for containers )
  3. docker run -d -P --name selenium-hub selenium/hub
  4. docker run -d -P --link selenium-hub:hub selenium/node-chrome-debug
  5. docker run -d -P --link selenium-hub:hub selenium/node-firefox-debug


The above command will link the chrome and firefox nodes with selenium grid hub

No alt text provided for this imageOnce containers are up and running , we can check the selenium hub status by hitting URL - 
seleniumAddress: 'http://0.0.0.0:4446/wd/hub'

This will open below page for us -
No alt text provided for this imageNow add config to suite file -
multiCapabilities: [{
'browserName': 'firefox'
}, {
'browserName': 'chrome'
  }],

Provide selenium hub address -

seleniumAddress: 'http://0.0.0.0:4446/wd/hub',

Run test cases -

protractor conf.js


Thank you
Amit Tayade
#docker #testautomation #softwaretesting #selenium #webdrivers #protractor #devops

Comments

Popular posts from this blog

What’s the Difference Between Docker and Kubernetes?

TestNG Listeners

Database Sharding