Deploy Selenium-Grid version 4 in Azure Kubernetes Cluster

This article outlines Deploying a selenium grid in one of the cloud services, ex Azure Cloud. I always find articles on setting selenium-grid up on the local m/c with minikube (local Kubernetes version) which is not always a real use case, hence thought of putting all information I gathered into one place as a self notes on how to set up selenium grid on Azure Kubernetes cluster from scratch and run the wdio test on this new selenium grid setup.

To set up a selenium grid over azure infrastructure need to understand the below concepts at a basic level at least.

Pre-requisite

  • Azure Fundamentals with Azure account ( i used my free trial account)
  • Knowledge on selenium-hub
  • Basic knowledge of Azure Kubernetes

High-level Steps

  1. Create AKS cluster with Virtual Nodes
  2. Connect to the cluster via Azure CLI or Kubectl from the local pc terminal or azure cloud shell
  3. Create Selenium-Hub
  4. Create Service for Selenium-Hub in order to allow external traffic
  5. Create Selenium nodes (chrome, firefox, edge)
  6. Run Selenium tests on grid setup

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image



1. Create AKS cluster:

After login to Azure Portal with your account, Create a Kubernetes cluster by following the screenshots and finding details I have entered in the Azure classic portal view

You can provide any values

Resource Group: Create new - > rg-ak8-se

Kuberentes cluster name: ak8-cluster-se-hub

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

2. Connect to aks cluster from terminal

Open command prompt or terminal and login to the Azure subscription

az login        

You will see like below on successful login to your account

No alt text provided for this image

Now we need to connect to the cluster in order to deploy our applications (selenium-hub and nodes), execute the below command by replacing your resource group and cluster name given in previous steps

az aks get-credentials --resource-group rg-ak8-se --name aks-cluster-se-hub        

You will see output like below if succuss

No alt text provided for this image

3. Create Selenium-Hub

Now we create a selenium-hub deployment using a YAML file like the below command.

kubectl create -f selenium-hub-deployment.yaml
        
No alt text provided for this image

You should see something like below

No alt text provided for this image

4. Create Service for Selenium-Hub in order to allow external traffic

kubectl create -f selenium-hub-svc.yaml        
No alt text provided for this image

Run the below command to get the grid external IP address

kubectl get services        
No alt text provided for this image

Now you can check the grid ui at http://yourExternalIPAddress:4444/grid/console

No alt text provided for this image


5. Create Selenium nodes (chrome or firefox or edge)

kubectl create -f selenium-node-chrome-deployment.yaml        
No alt text provided for this image


No alt text provided for this image

Now you can see below 2 chrome nodes registered to your hub ( i have added only 2 replicas in my config file above)

No alt text provided for this image

Creating firefox nodes

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

6. Run tests on the grid setup

Now let's run simple webdriverIO tests on our grid setup

make dir and create the below package file ( assuming node setup is there in your system)

No alt text provided for this image

make changes to the below test as per your selenium grid ip config

No alt text provided for this image

Now run the tests like below ( my tests are in wdio dir)

npm install
npm run test        
No alt text provided for this image
No alt text provided for this image


Hi Ravee Mullaguri just one question about selenium grid, do we need run the selenium grid always or we can run only during the testing.

Like
Reply

Do you know what command used to trigger selenium tests on grid using release pipeline???

Like
Reply

Hi Ravee, The article is very useful .Can you please share the details for Azure pipeline too if it is ready..

Like
Reply

You should definitely automate this. AKS creation, as well as selenium grid creation, and then running tests. "make setup-cluster" "make setup-grid" "make run-tests" :)

To view or add a comment, sign in

Others also viewed

Explore content categories