Monday, August 27, 2018

Docker With Selenium WebDriver


We are now in shape to work with selenium docker containers. We need to follow the below steps

Step 1:
 We need to search docker Selenium containers to setup a distributed selenium environment, we can search it from Kitematic, cmd prompt or from Docker Hub.





We will prefer to go with Docker Hub because we get more information from this page about the searched image. We will choose the Selenium hub image from the search result which one published from SeleniumHQ.

So after clicking on details button the page will be redirected to the details page of this searched Image Details page contains the Selenium Logo those images are published from SeleniumHQ like below:






Here GitHub link is also available from where we can get more information of configuration details.
 
Step 2:
To download the latest version of Selenium/Hub image we need to type the following command in command/console
                                                    docker pull selenium/hub

Step 3:
 Give a search as “Selenium node” on Docker Hub search page. Search result should be populated as below:

We will choose Selenium/Node-firefox-Debug and Selenium/Node-Chrome-Debug. We choose this images because it is VNC enabled. We can access the GUI of this images through VNC viewer for debugging purpose of our script.

Step 4:
 To download the latest version of Selenium node images we need to type the following command in command/console

                                        docker pull selenium/node-chrome-debug
                                        docker pull selenium/node-firefox-debug

Step 5:
Now we will start selenium hub with the specific port using docker, for this, we will use the following command.

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




We get the logs of this selenium/hub container using the following command
                                                     docker logs -f selenium-hub

 If we open the following machine IP/machine name/localhost/127.0.0.1:4446 page will appear as below.


Step 6:

Now we will register selenium node to selenium hub with a specific port using docker, for this, we will use the following command.




    docker run -d -p <publish port:actual port>  -p <publish port:actual port> --link <name:alias> --name <custom name> <image name>

So this will be the command to start and link the firefox node with the selenium grid

     docker run -d -p 5557:5555  -p 49339:5900 --link selenium-hub:hub --name firefox-node selenium/node-firefox-debug



We get the logs of this selenium/node-firefox-debug container using the following command
                                                     docker logs -f firefox-node




So this will be the command to start and link the firefox node with the selenium grid

docker run -d -p 5556:5555 -p 49338:5900 --link selenium-hub:hub --name chrome-node selenium/node-chrome-debug 



So if we open the console of the grid on the web browser it will look like below:




Step 7:

Download the VNC viewer as per system OS.




Using the following command, we will get the Node Firefox and Chrome IP address and Port to connect through VNC.


We need to provide the password as secret at password field to connect those machine through VNC.


After successfully connected this screen should be available.


Note : 

  • We can configure a node with multiple browser using the following command but it is not recomended.

docker run -d -p 5557:5555 -p 49339:5900 -e NODE_MAX_INSTANCES=5 -e NODE_MAX_SESSION=5 --link selenium-hub:hub --name firefox-node selenium/node-firefox-debug

docker run -d -p 5556:5555 -p 49338:5900 -e NODE_MAX_INSTANCES=5 -e NODE_MAX_SESSION=5 --link selenium-hub:hub --name chrome-node selenium/node-chrome-debug

  • Tagging convention for images is like below:

    <Major>.<Minor>.<Patch>-<Chemical Element in Alphabetical order> 
We can follow the below commands for docker network

  •  docker network create <NETWORK_NAME>
  •  docker run -d -p <grid host port:grid docker port> --net grid --name selenium-hub selenium/hub
  •  docker run -d -p <node host port:node docker port> -p <vnc host port:vncdocker port> --net grid -e HUB_HOST=selenium-hub -v /dev/shm:/dev/shm selenium/node-chrome-debug
  •  docker run -d -p <node host port:node docker port> -p <vnc host port:vncdocker port> --net grid -e HUB_HOST=selenium-hub -v /dev/shm:/dev/shm selenium/node-firefox-debug


 

2 comments: