Out of Box

Parallel Testing with Zalenium using AKS

Selenium is most widely used open source tool for UI automation testing. As we are moving towards more Agile development and faster delivery of software product, QA team are getting short time frame to perform the testing ,so QA developers are finding ways to execute the tests in parallel to save the time .Selenium provides grid to perform the parallel test execution.

Below blog covers below topic

  • Parallel Testing
  • Challenges with selenium grid
  • What is Zalenium (in brief)
  • Why to use Zalenium?
  • Zalenium Features
  • Deploying zalenium on AKS cluster using Helm chart (Zalenium Basic Authentication Enabled)

Parallel Testing

  • Parallel Testing is a testing technique in which multiple tests are executed simultaneously in different threads to reduce execution time.
  • It allows us to execute multiple tests at the same time across different environments/Browsers instead of running tests one by one or sequentially.
  • Parallel testing helps us to run test methods/classes/tests in parallel.
  • Parallel testing helps to reduce execution time and efforts and results in faster delivery.
  • It helps in cross browser testing, compatibility testing, localization, and internalization testing.
  • It will help you to increase ROI  (return of Investment).
  • TestNG is a testing framework for Java that helps in parallel testing or parallel execution.

Challenges with selenium grid

Selenium have a Hub-Node architecture in which we need to setup machines to make hub and nodes to perform the parallel test execution. This selenium grid infrastructure setup is having below issues:

  • Have a stable grid to run UI tests with Selenium
  • Maintain it over time (keep up with new browser, Selenium and driver’s versions)
  • Provide capabilities to cover all browsers and platforms

The solution to above challenges is Zalenium was created to solve the widespread issue that a lot of people have when you have some tests, and you want to start running them in parallel.

Zalenium

A flexible and scalable container-based Selenium Grid with video recording, live preview, basic auth & dashboard. Start a Selenium Grid in seconds, a grid that scales up and down dynamically with this solution based on docker-selenium to run your tests in Firefox and Chrome.

Zalenium’ s main goal is: to allow anyone to have a disposable and flexible Selenium Grid infrastructure

Zalenium Features

  • Allow anyone to have a disposable and flexible Selenium Grid infrastructure
  • Zalenium Dashboard
  • Zalenium Live Preview
  • Video Recording
  • Integrated with Sauce Labs, BrowserStack, TestingBot, CrossBrowserTesting, LambdaTest
  • Test status and steps directly in the video
  • Basic auth grid protection when deploying Zalenium in the cloud (AWS, GCP, …)
  • Mount volumes across containers when you need to specific files in your tests
  • Customizing screen width and height, and time zone

Running Zalenium in Multiple ways:

  • Docker ,Docker Swarm & Docker Compose.
  • Kubernetes (Minikube, helm chart, AKS) & Openshift
  • One line installer and starter for OSX/Linux .

Deploying zalenium on AKS using Helm chart

Prerequisite

  1. User must have a azure account with subscription , you can create and use free account from here.
  2. Azure CLI installed on the system if not the install from here.
  3. Install Helm from here.
  4. Install Kubectl from here
  5. Basic understanding of Kubernetes

1.Create an AKS cluster

Create an AKS cluster either by azure portal from here or by using azure CLI from here.

2.Connect to AKS cluster using azure CLI

Check by below command(az) if azure CLI installed on your system.

Login to azure using CLI by below command

az login

A browser will open ,After login using your credentials ,you will get below screens.

use below command to get the AKS credentials and to fetch the cluster resources.

az aks get-credentials --resource-group <group-name> --name <cluster-name>

Just check by below if you are able to access AKS cluster resources .

Kubectl get nodes

3.Create a name space in AKS cluster

Create name space by below command in AKS cluster and check created namespace.

Kubectl create namespace <namespace_name>
Kubectl get namespace

4.Add Zalenium Helm chart to Helm repo

Use below command to add helm chart

helm repo add zalenium-github https://raw.githubusercontent.com/zalando/zalenium/master/charts/zalenium

By below command check helm chart is added to repo

Helm search repo zalenium

5.Deploying Zalenium on AKS using Helm chart

Use below command to install the zalenium helm chart on AKS

  • Using service type as “Load Balancer” to get the external IP address to access the zalenium
  • Using Basic Auth
helm install my-release --namespace zalenium-aks zalenium-github/zalenium --set hub.serviceType="LoadBalancer" --set hub.basicAuth.enabled="true" --set hub.basicAuth.username="qautomation" --set hub.basicAuth.password="Zalenium2020"

6. Fetching the IP address for Zalenium access

Use below kubernete command to get the IP address:

kubectl get service my-release-zalenium --namespace="my-zalenium"

external IP address is used to access zalenium

7. Accessing Zalenium

Zalenium Dashboard http://52.191.95.62/dashboard/#
Zalenium Live Previewhttp://52.191.95.62/grid/admin/live
Zalenium Grid consolehttp://52.191.95.62/grid/console
Zalenium Hub http://52.191.95.62/wd/hub

Note: You need to provide credential as this zalenium setup is Basic auth enabled

8. Modifying the Driver and zalenium capabilities code

Use below code and modify your selenium web driver code:

Modify web driver code in selenium
String remoteUrl = "http://"+gridusername+":"+gridpassword+"@"+gridhost+"/wd/hub";
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.BROWSER_NAME,BrowserType.CHROME);
cap.setCapability("name", “<Test_Name>-"+timestamp);
cap.setCapability(CapabilityType.PLATFORM_NAME, Platform.LINUX);     
cap.setCapability("build", <buildname>);
cap.setCapability("testFileNameTemplate", "{testName}_{browser}_{timestamp}");
cap.setCapability("idleTimeout", 180);
cap.setCapability("recordVideo", true);
cap.setCapability("tz", "Asia/Kolkata");       
driver = new RemoteWebDriver(new URL(remoteUrl),cap); 

For  running test cases in parallel we can use “parallel” attribute in testng.xml in TestNG. The parallel attribute of suite tag can accept four values:

tests – All the test cases inside <test> tag of testng.xml file will run parallel
classes – All the test cases inside a java class will run parallel
methods – All the methods with @Test annotation will execute parallel
instances – Test cases in same instance will execute parallel but two methods of two different instances will run in different thread.

<suite name="qautomation" parallel="methods" thread-count="2">

References:

https://opensource.zalando.com/zalenium/

https://github.com/zalando/zalenium/tree/master/charts/zalenium

https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough-portal

https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough

Categories: Out of Box, Selenium

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s