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
High-level Steps
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
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
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
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
Recommended by LinkedIn
You should see something like below
4. Create Service for Selenium-Hub in order to allow external traffic
kubectl create -f selenium-hub-svc.yaml
Run the below command to get the grid external IP address
kubectl get services
Now you can check the grid ui at http://yourExternalIPAddress:4444/grid/console
5. Create Selenium nodes (chrome or firefox or edge)
kubectl create -f selenium-node-chrome-deployment.yaml
Now you can see below 2 chrome nodes registered to your hub ( i have added only 2 replicas in my config file above)
Creating firefox nodes
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)
make changes to the below test as per your selenium grid ip config
Now run the tests like below ( my tests are in wdio dir)
npm install
npm run test
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.
Do you know what command used to trigger selenium tests on grid using release pipeline???
Hi Ravee, The article is very useful .Can you please share the details for Azure pipeline too if it is ready..
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" :)