In this tutorial, You are going to learn about docker. Before you jump into the docker, I want you to know how much time it will take to learn this docker in protractor.
For me, it took almost 7 hours to make it work on my laptop, so you can think now how much patience you need to have.
I have followed many tutorials, before starting this, but somehow things get outdated and will not work, so if this any of the steps in this tutorial is not working keep calm and search in google sometimes, it may be an issue only with protractor, so you give a try with selenium.
With all said, we would be going in baby steps, so I have created 50-60 images in this docker tutorial, if you feel like you do not want to waste time then please do navigate to List of docker commands used in this tutorial section
After writing this, I Will start watching "You Were Never Really Here" movie.
Docker is nothing but a virtual machine packed in containers, and we use the docker to run our protractor Grid. Docker server as a Virtual machine with a specific product like Unit with Chrome or Firefox.
Most of the Companies use the docker to create their own applications just like Firefox inside a container. Docker is worth a thing for cross-browser testing; instead of paying more money to cloud-based companies, it is better to use the Docker.
I know there are too much explanations for Docker, but this much is enough for our automation and for all.
FYI : I am using the Win10 operating system for this tutorial because I have only one laptop, silly.






Kitematic provides the UI for the Docker; When you download docker, it will be like a cli/cmd terminal, so let's download it.
But sometimes this KiteMatic may not work during those time please do use the Docker cli or Command prompt to install things.






Sometimes, you might face an issue with the installation of the image in Kitematic UI, and same issues you will face with Cli/Cmd as well
DockerCli.exe -SwitchDaemon







docker run -d -P --name selenium-hub selenium/hub


docker ps


Yes, you can install the node just like a hub, but there are two kinds of nodes, which one to chose.
docker run -d -P --link selenium-hub:hub selenium/node-chrome-debug
[Hub.start] - Nodes should register to http://172.17.0.2:4444/grid/register/
[Hub.start] - Clients should connect to http://172.17.0.2:4444/wd/hub
After Connecting the Node
# after node installation
[Hub.start] - Nodes should register to http://172.17.0.2:4444/grid/register/
[Hub.start] - Clients should connect to http://172.17.0.2:4444/wd/hub
[DefaultGridRegistry.add] - Registered a node http://172.17.0.3:5555
As I said earlier, you may want to see the execution of the program in the given docker. You cannot view a docker just like that; we have to connect the docker with our system using some tool.
I would recommend using the VNC viewer to connect the Docker. VNC viewer helps to connect the Remote machine with Local machine.






// install the Hub
docker pull selenium/hub
// invoke the hub
docker run -d -P --name selenium-hub selenium/hub
// install the Node
docker pull selenium/node-chrome-debug
// invoke the node
docker run -d -P --link selenium-hub:hub selenium/node-chrome-debug
// list the running process
docker ps
// list all the running process
docker ps -a
Now we are on the important part of the tutorial, Let's integrate the protractor scripts with Docker. Be aware that it is a single line change in the conf file.
Consider below protractor Test file for docker integration; this script will take a screenshot of the opened page.
import{createWriteStream} from 'fs'
import { browser, by, element, ExpectedConditions} from 'protractor'
describe('Protractor Typescript Demo', function() {
browser.ignoreSynchronization = true; // for non-angular websites
it('get Cookie test in Protractor', function() {
browser.get("https://google.com")
browser.getTitle().then(function(t){
console.log("Title of Google : "+t)
})
// take screenshot
browser.takeScreenshot().then(function (png) {
var stream = createWriteStream("Chercher_tech_Screenshot.png");
stream.write(new Buffer(png, 'base64'));
stream.end();
});
});
});
Conf file that we use for execution, The only change is SeleniumAddress Parameter in the conf file. SeleniumAddress should be the one that I have highlighted in the Hub in the KiteMatic UI. 
After Connecting the Node
# after node installation
[Hub.start] - Nodes should register to http://172.17.0.2:4444/grid/register/
[Hub.start] - Clients should connect to http://172.17.0.2:4444/wd/hub
[DefaultGridRegistry.add] - Registered a node http://172.17.0.3:5555
Now lets have a look at the conf.js file
exports.config = {
framework:'jasmine',
browserName:'chrome',
seleniumAddress:'http://localhost:4444/wd/hub',
specs: ['D:Protractor DemoJSFilesLocation est.js'],
}
C:Program FilesDockerDocker>DockerCli.exe -SwitchDaemon
seleniumAddress:'http://localhost:4444/wd/hub',
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
In layman terms, Compose contains a set of commands, just like the batch file in your windows operating system.
services:
NameOfHub:
image: selenium/hub
container_name: NameOfHub
privileged: true
ports:
- 4444:4444
environment:
- GRID_TIMEOUT=240000
- GRID_BROWSER_TIMEOUT=240000
NameOfNode:
image: selenium/node-chrome-debug
privileged: true
depends_on:
- NameOfHub
ports:
- 5900
environment:
- HUB_PORT_4444_TCP_ADDR=NameOfHub
- HUB_PORT_4444_TCP_PORT=4444
I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.