Scaling Selenium tests using Selenoid & Selenosis

Vinay Sharma
4 min readAug 15, 2023

--

Looking to Execute Selenium Tests Across Multiple Containers?

Interested in Concurrent and Scalable Execution of Your Selenium Tests?

In this blog, we will delve into the art of scaling test automation, tapping into the potential of Kubernetes and Docker through Selenoid and the prowess of Selenosis.

To begin, let’s delve into the reasons behind adopting Selenoid and Selenosis.

Selenoid: Streamlined Selenium Hub with Docker Efficiency. Selenoid revolutionizes the Selenium hub experience by leveraging Docker containers for browser launches. This ingenious approach simplifies Selenium hub implementation, eliminating the need for dual management of both Selenium hub and Docker. With Selenoid, the emphasis shifts solely to implementing the tool, while its internal mechanisms seamlessly handle all the complexities.

According to the documentation of Aerokube, selenoid is not recommended for the Kubernetes platform. And Moon is pay per use model. So in this article, we are going to explore Selenosis — a scalable, stateless selenium hub for the Kubernetes cluster.

Selenosis: Empowering Scalable, Stateless Selenium Hub for Kubernetes Clusters. Harnessing the capabilities of a Kubernetes cluster, Selenosis seamlessly scales test automation. It intelligently distributes the load across available pods, ensuring efficient execution, and gracefully removes them post-completion. In essence, it blends Kubernetes’ orchestration prowess with the essence of test automation.

Enough of theory, Let us dive in to some action & see how it works.

Pre-requistes:

  • Docker
  • kubectl
  • Minikube — For this blog, I will be using a Minikube cluster which is the easiest and simplest way to spin up a K8s cluster on your local machine.
  • Selenium code (Basic parallel tests)
  • Basic understanding of Kubernetes will be plus.
  • Start Minikube by running the below command (docker should be up & running)

minikube start - vm-driver=docker - insecure-registry="gcr.io"

With all prerequisites in place, let’s begin.

  1. Creating a namespace: Namespaces are Kubernetes objects which help in organising resources and partition a single Kubernetes cluster into multiple virtual clusters. It provides a degree of isolation from the other parts of the cluster.

2. Creating service: Service is actually a method for exposing a network application that is running as one or more Pods in your cluster.

3. Creating Selenosis deployment: It will actually create a deployment object to manage the pods and also it will create a service which will act like a load balancer for balancing the traffic coming from all the registered nodes.

Note: In the above yaml file, I have kept browser limit to 15. You can increase or decrease based on your requirement & CPU capacity

4. Selenoid — UI: The purpose of Selenoid UI is to offer an intuitive interface that enables seamless management and visualization of Selenium containers within the Selenoid ecosystem.

5. Selenosis HPA: Horizontal Pod Autoscaler automatically scales the number of Pods in a replication controller, deployment, replica set or stateful set based on observed CPU utilisation.

6. Finally, an option is to maintain a browser file housing image files of various browsers along with their respective versions.

With all the necessary files in place, the next step involves setting up the services and exposing them to initiate the desired actions.

To streamline the process, I’ve compiled all the required commands into a convenient shell file.

To execute these commands effortlessly, simply run the following shell command.

sh start.sh

You can now check the Minikube dashboard to confirm all the pods are up & running.

minikube dashboard
Minikube dashboard

Now, proceed to your web browser and access http://127.0.0.1:8080/

Likewise, you can employ this identical address as your remote web URL within your Selenium tests. This setup empowers you to execute tests concurrently, with tests distributing across accessible nodes and queuing up. As soon as a browser node becomes available, the next queued test will seamlessly commenced.

Selenoid ui

The source code of this blog post can be found here.

Future Scope:

  1. Creating the cluster in AWS/GCP
  2. Creating scalable mobile test automation with Selenoid & Selenosis…

Reference:

  1. https://medium.com/testvagrant/scaling-tests-on-google-kubernetes-engine-with-cloud-build-624d955f6698
  2. https://github.com/alcounit/selenosis
  3. https://github.com/alcounit/selenosis-deploy

--

--