Thursday, March 11, 2021

Most useful Docker commands for Automation tester

 













Docker command

Meaning

docker image pull selenium/standalone-chrome

 Here we are pulling chrome image

docker image ls

To list out the available/downloaded images

docker container create selenium/standalone-chrome

Here we are creating chrome container --it will return container id

docker container start containerID

To start container

docker container ps

To check whether container started or not

docker stop containerID

To stop the running container

docker stop containerID1 containerID2 containerID3

To stop the multiple running container at a time

docker restart containerID

To restart the container

docker images -f "reference=selenium/*:latest"

It will filter images starting with name ‘selenium’

/* - regular expression with latest version

docker ps

you can check the status whether the container is running or stopped

docker ps -a

It will show all the running containers

docker rm containerID

It will delete container

docker stop containerID1 containerID2 containerID3

It will delete multiple container at a time

docker rm imageID

It will delete image ‘imageID

docker inspect containerID

It will allow to inspect the container

docker kill containerID

It will terminate the running container

docker container run

It will pull, create and start the container by single command

docker run -p 4444:4444 selenium/standalone-chrome

It will map local port 4445 to docker port 4444

docker run -p 4444:4444 --name selgrid selenium/standalone-chrome

It will map local port 4445 to docker port 4444 with container name selegrid

docker run -d -p 4444:4444 --name selgrid selenium/standalone-chrome

It will map local port 4445 to docker port 4444 with container name selegrid and and all the process will be done in background

docker container --help

To seee the docker commands

docker exec –ti containerID  /bin /bash

It will allow you to take inside the container.

-t à indicate you want to see the output from the comd prompt

-I -àIndicate that you want to enter some input to cmd promt inside the container

 

 

How to run selenium test cases on Dockerised selenium grid (Traditional Approach)

Pre-requisites:

1. Download selenium/hub image

2. Download selenium/node-chrome-debug

3. Download selenium/node-Firefox-debug

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

or

 

docker run -d -p 4444:4444 - -restart always --name selenium-hub selenium/hub:latest

‘Docker run –d’ Running this docker container in back ground and ‘-p 4444:4444’ mapping the local port 4444 to selenium hub port 4444 and giving name

‘-  - name selenium-hub’ and creating container from ‘selenium/hub:latest’ with latest tag

docker logs containerID

To seee the logs

http://localhost:4444/grid/console

Hit the url in browser. You must see Hub created

Hub is created, Now our next task is to link chrome node to selenium hub

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

 

or

 

docker run –d - -link selenium-hub:hub - -restart on-failure:3 selenium/node-chrome-debug:latest

Creating node and inking with selenium hub

‘docker run –d’ – To run the command in background

‘- -link selenium-hub:hub’ – linking with selenium hub with name ‘selenium-hub’ which is acts as hence giving name as hub ‘:hub’

‘selenium/node-chrome-debug:latest’ – linking with node with latest tag

http://localhost:4444/grid/console

Refresh the browser and you must be able to see chrome node created with version

Similarly, Now link firefox node to selenium hub

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

 

or

 

docker run –d - -link selenium-hub:hub - -restart on-failure:3 selenium/node-firefox-debug:latest

Creating node and inking with selenium hub

‘docker run –d’ – To run the command in background

‘- -link selenium-hub:hub’ – linking with selenium hub with name ‘selenium-hub’ which is acts as hence giving name as hub ‘:hub’

‘selenium/node-firefox-debug:latest’ – linking with node with latest tag

http://localhost:4444/grid/console

Refresh the browser and you must be able to see firefox node created with version

Here we have created two node – if you have to connect again one firefox or chrome node, simply run

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

http://localhost:4444/grid/console

Refresh the browser and you must be able to see three node 1 chrome node and 2 firefox

 

 

Container Restart policy-

Suppose you are executing test suit of 100 test cases and at 5th test case your Container got crashed in that

case all rest of the test cases will be failed. In this scenario, restart policy is very important and good practice.

 

No(Default)

This is default flag

On Failure

When container crashes then only docker daemon will restart the container

Always

Container will restart always unless docker daemon stopped

Unless-stopped

Restart always until manually stopped

How to update container with restart policy

docker update - -restart on-failure:2 containerID

Restart policy will be applied to particular container ,

It is updating a container with restart policy on failure 2 times

docker inspect containerID

you can check the container restart policy by

inspectin git

 

 

How to run selenium test cases on Dockerised selenium grid- Docker Compose file

Pre-requisites:

1.      Create docker-compose.yaml file in eclipse

2.      Open command promt

3.      Go to docker-compose file

4.      Entre below commands

docker-compose up

or

docker-compose up -d

It will execute compose file with extension .yaml, also you can see the logs

It will run in background

docker-compose –f selenium-compose.yaml up

Or If your docker compose file name is different, you can us can use this command

docker-compose down

It will stop your compose file

docker-compose ps

To see what an all serices and container there in docker compose file

docker-compose scale chrome=5

It will create 4 new chrome instances as 1 is already there in compose file.

Chrome –it Is service name in docker-compose file

 

 

 

Refer docker-compose file

version: "3"

services:

  selenium-hub:

    image: selenium/hub:latest

    container_name: selenium-hub

    restart: always

    ports:

      - "4444:4444"

  chrome:

    image: selenium/node-chrome-debug:latest

    volumes:

      - /dev/shm:/dev/shm

    depends_on:

      - selenium-hub

    environment:

      - HUB_HOST=selenium-hub

      - HUB_PORT=4444

    restart: on-failure:3

  chrome_79:

    image: selenium/node-chrome-debug:3.141.59-zinc

    volumes:

      - /dev/shm:/dev/shm

    depends_on:

      - selenium-hub

    environment:

      - HUB_HOST=selenium-hub

      - HUB_PORT=4444

    restart: on-failure:3

  firefox:

    image: selenium/node-firefox-debug:latest

    volumes:

      - /dev/shm:/dev/shm

    depends_on:

      - selenium-hub

    environment:

      - HUB_HOST=selenium-hub

      - HUB_PORT=4444

    restart: on-failure:3 

 

Real time Dashboard:

Important Link:

Getting started with elastic search

Download Elasticsearch

Install elastic search with docker

Environment variable configuration

Docker hub - elasticsearch

 

Docker command

docker run -p 9200:9200 -p 9300:9300 --name elasticsearch -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.11.1

To run elastic search

http://localhost:9200/

To check elastic search is up and running

docker run -p 5601:5601 --name kibana --link elasticsearch:elasticsearch docker.elastic.co/kibana/kibana:7.11.1

To run Kibana

http://localhost:5601/

To check elastic search and kibana is up and running

 


Once elastic search is up and running, you can push your data to elastic search as shown below

URI - http://localhost:9200/world/countries

End point - http://localhost:9200/
Index – world
Type - countries

To see data in elastic, download chrome extension for elastic search:
1. Type elastic search chrome extension in google
2. Install ‘Elastic search head’ the extension
3. Launch the extension by clicking on elastic search head extension

You can see all your data in elastic using its extension.

 

 

***Manager your Docker container using Portainer 

docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer

To run portainer

http://localhost:9000/

To check portainer is up and running

 

Setup Selenoid in docker

 

 

 

 

 

 

No comments:

Post a Comment

How to install Java on EC2

***************************************** How to install Java on EC2 ***************************************** To be continued, In this post...

All Time Popular Post