Integration of Selenium Grid with Kubernetes for Running Selenium Scripts and Video Recording of Selenium Scripts with Docker

Iqra Ishtiaq
DiveDeepAI
Published in
6 min readJun 8, 2022

--

Kubernetes

Kubernetes is an open-source system that automates deployment, scaling and management of containerized applications. A tool for Automating DevOps Of Application and Infrastructures. It is also used for managing containers that form applications

Figure 1: Understanding of Kubernetes

It was developed over 15 years ago by Google, combining best practices from the community and skills gained during their production experience running large workloads at scale with Kubernetes in use today. Kubernetes is a great platform for machine learning because it comes with all the scheduling and scalability that you need.

Kubernetes Features

  • Automated Rollouts and rollbacks
  • Storage orchestration
  • IPv4/IPv6 dual stack
  • Batch Execution
  • Self-Healing
  • Secret and configuration management

Selenium Grid Kubernetes Architecture

Figure 2: Selenium Grid Kubernetes Architecture

Selenium

Selenium is a framework of automation testing tools, based on the JavaScript framework. Selenium suite comprises of four components:

  • Selenium Grid
  • Selenium IDE
  • Selenium RC
  • Selenium WebDriver

Selenium Grid

Selenium Grid is a powerful tool that can be used to run tests in parallel on multiple machines. It does this by routing commands from the hub application running inside of it, which are then sent out across all registered nodes for execution- ensuring coverage everywhere even if something goes wrong. It makes cross browser testing easy as a single test can be carried on multiple machines and browsers, all together making it easy to analyze and compare the results. Major components of Selenium Architecture are:

  1. Hub: is a server that accepts the access requests from the Webdriver client, routing the JSON test commands to the remote drives on nodes. It takes instructions from the client and executes them remotely on the various nodes in parallel
  2. Nodes: is a remote device that consists of a native OS and a remote WebDriver. It receives requests from the hub in the form of JSON test commands and executes them using WebDriver.
Figure 3: Selenium Grid Architecture

When should Tester use Selenium Grid?

  • To run tests on multiple browsers and their versions, different devices, and operating systems.
  • To reduce the time that a test suite takes to complete execution.

Demonstration

  1. Install Minikube, Kubectl and docker
  2. Run cmd in Administration and start minikube
minikube start

3. Check Kubernetes Dashboard

minikube dashboard

4. Download files from below link and save it

5. Deploy Selenium Hub on Kubernetes Pod

kubectl create -f selenium-hub-deployment.yaml

Output:

Figure 4: Creating Selenium Hub in Kubernetes

Kubernetes Dashboard

Figure 5: Kubernetes Dashboard

6. Deploy Kubernetes services on Kubernetes Pod

kubectl create -f selenium-hub-svc.yaml

7. Deploy Selenium Chrome and Firefox container on another pod

kubectl create -f selenium-node-chrome-deployment.yaml
kubectl create -f selenium-node-firefox-deployment.yaml

Output:

Figure 6: Deploying Chrome and Firefoc Container

Note: Wait until it the Deployments turns into green.

8. Find Selenium Grid Console (Run this command in cmd as Administrator)

minikube service selenium-hub –-url

Output:

Click the first link.

Figure 7: Selenium Grid Console url

Output:

Figure 8: Selenium Grid Dashboard

Run the testcases from your IDE in my case I’m using PyCharm. Below is the code

Figure 9: Dictionary of browsers (PyCharm Python)
Figure 9: Selenium Script in PyCharm (PyCharm Python)

9. Go to Selenium Dashboard after running your test under Session section you will see there the session is created and click the video icon to watch the test you pass from PyCharm IDE.

Output:

Figure 10: Selenium Grid Chrome Image

Selenium Grid Test Cases Recording with Docker

In order to record the testcases and save it in your devices it can be achieved using Docker. Here’s the link of Docker-selenium for further help:

https://github.com/SeleniumHQ/docker-selenium

Download the docker-compose-v3-video.yml and save it with the extension of yml/yaml.

Step 1:

Open cmd and type

docker-compose -f docker-compose-v3-video.yml up

Output:

Figure 11: Creating Selenium Grid

Go to docker Dashboard under Container/App and there you will see the Kubernetes selenium grid

Output:

Figure 12: Docker Kubernetes Selenium Grid

Step 2:

Go to http://localhost:4444/ui

Output:

Figure 13: Selenium Grid Dashboard with different nodes

Step 3:

Run the test from PyCharm IDE.

Output:

Figure 14: Selenium Script

Step 4:

Go to Selenium Dashboard under Session section, you will see after a few minutes later all testcases will start running.

Figure 15: Selenium Grid Chrome Image
Figure 16: Selenium Grid LiveView (VNC) Password

Since there are three nodes so three images will be created one by one. The password is secret ,and press Accept button. Repeat this step for all the other nodes.

Step 5:

After running the test, you will see a folder is created.

Output:

Figure 17: Docker Videos Folder

Note: It consists of all test recording.

Figure 18: Different Nodes Recording

At this moment if you click the video it won’t play it will show an error because the docker image of video is not still up it’s not closed.

Figure 19: Error can’t play video

Step 6:

Open cmd and type docker-compose -f docker-compose-v3-video.yml down. Afterwards go to the folder that has been created and you can play the video of your tests.

Selenium Grid Test with VNC Viewer using Docker

VNC Viewer is used for local computers and mobile devices you want to control from. A device such as a computer, tablet, or smart phone with VNC Viewer software installed can access and take control of a computer in another location.

Step 1:

Download VNCViewer from https://www.realvnc.com/en/connect/download/viewer/.

Step 2:

Run and install VNCViewer in your device.

Step 3:

Type the url :127.0.0.1:5900 and hit enter after few seconds you will see the live demo of your testcases. Connection will ask for permission allow it and then ask for password the password is secret.

Figure 20: Live Demo usig VNC Viewer

Video Recording using Docker

Figure 21: Recording of Chrome Node

--

--