How to Build an Automated Testing Pipeline with GitLab CI/CD & Selenium Grid?

A Selenium Grid is a smart proxy server under the Selenium suite that makes it easy to run multiple tests. It runs these tests across different browsers, OS along with machines on parallel mode. Here a server acts as a hub that routes commands to remote web browser instances. Selenium Grid is a testing tool. Selenium online training gives the advantage of implementing performance tests easily in the continuous testing environment.

GitLab CI/CD is a software development tool built into GitLab. It offers Continuous Integration and Continuous Deployment of software services. Here, CI helps to build and test the software and CD places the change of codes in the deployment of production. Continuous Deployment follows up with continuous delivery.

Both of the above tools help to build a testing pipeline with customizing options to shape the pipeline according to needs. They are very useful for automation testing. Furthermore, it will reduce the time of testing using automation in different environments.

GitLab Selenium testing

To run CI/CD it requires a special configuration file, GitLab CI YAML. This file contains the instructions to run different CI/CD pipelines.

There are different variables required to build CI/CD pipelines dynamically. It makes the job portable and easy. The most commonly used variables that make CI/CD pipeline a robust one include the follows;

CI_COMMIT_REF_NAME

CI_COMMIT_BRANCH

CI_ COMMIT_TAG

CI_EXTERNAL_PULL_REQUEST_IID

and more others.

The above variables help to shape the pipeline according to the different branches and it also provides flexibility in distributing jobs. It is good to use any environment variables to make the job more flexible.

testing.png

Each CI/CD job requires some dependencies which are built using third parties. But it takes much time to fetch these dependencies from third party sources. If these dependencies are cached to use for multiple pipelines, then it would make CI build much faster. It also reduces the network bandwidth that helps to build more pipelines easily. This cache can be invalidated by clearing the cache key.

To trigger a CI/CD pipeline we should use the following ways:-

Git Based triggers, Crons, Manual Intervention.

These are the most convenient ways to trigger a CI/CD pipeline. Everything can be automated using all these ways. But after the process of manual intervention only, the deployment will take place.

CI/CD pipeline automation testing

To automate the testing of pipelines, there are different stages to follow. For example, there are four stages in pipeline testing automation. These are;

  • Building a compilation
  • Test
  • Staging
  • Deployment

The pipeline delivery should comply with the following requirements;

  • Source code
  • Automation mechanism triggered by changing code
  • Building an application pack
  • Deployment of an application
  • Finally runs an automated test and produce the report.

How to run Selenium tests on GitLab?

Steps in building a Testing Pipeline

The following steps involve while building a test pipeline. It includes;

  1. Write the test script and run it locally

First, we will write the test script. Selenium testing course online is the best web automation tool that helps to write simple scripts. Here it requires three important components such as; Set up, run the test and tear down the test. Based on these components, we can set up, run and close the test.

  1. Setting up a runner for the testing environment

Here we need to set up a GitLab runner for the testing environment. It includes the following steps;

Usage of Docker, Downloading a binary and using repositories for rpm packages.

  1. Setting up an Image with the help of testing environment

To build an image, the usage of Docker is important. This image includes the software to be installed and it should run on the container like a virtual machine runs. We can create a container with Docker to pull the same image all the time of testing. The following things will be required to perform the test with the selenium with python online training client which includes, Python, Chrome, and Chrome driver. Furthermore, here we need to create a Dockerfile too.

Now, the environment is ready to perform the test.

Setting a GitLab CI/CD for Automation testing piepline

Here, we will create a template for the product to run the test.

image: joyzoursky/python-chromedriver:3.6

before_script:

- pip install -r requirements.txt

stages:

- test

- report

test_suite_1:

stage: test

script:

- python -u test_suite_1.py

test_suite_2:

stage: test

script:

- python -u test_suite_2.py

send_report:

stage: report

script:

- python send_report.py

The GitLab will look after the job template and installs the packages required to start the process.

  1. Run and report

After setting up the pipelines according to the user requirements the test run can be initiated. There are two different ways to integrate this such as; running the test frequently when a new code is pushed to the project and running periodical tests.

We can also use Jenkins Cron job to run the tests end to end regularly without slowing down.

Reporting the test results also vary with the teams working and their requirements. Such as; slack notification, HTML reports, and saving the test runs in the database. Displaying these reports on the dashboard as and when required.

Thus, setting up an environment of automation testing of pipelines will make the job of Quality Analyst much easier. It will help him to find out the bugs and errors easily within the application. Furthermore, whenever the code is updated by the production department, it will automatically trigger and the test will run automatically. Along with this, it will generate the reports too. The developers get notifications frequently on the tests running.

How to configure Selenium grid in Jenkins?

Selenium Grid is a powerful web application testing tool. It supports all web browsers and operating systems. Integrating the Grid with CI/CD is a little complex issue. So, here Selenium Grid uses Jenkins to quickly execute the test and generate reports.

The Selenium Grid plugin will turn the Jenkins server into a Selenium Grid hub. This makes it easy to execute tests on any machine.

Furthermore, there are certain steps involved in this configuration. These are;

Installation: At first, we need to install the Selenium Grid along with Jenkins plugin.

Creation of Node configurations: Here, we will configure Selenium Nodes using different options and navigations.

Launching Node: After configuring the Nodes we will launch them with the matching configurations of Jenkins slaves. Now, it will connect the Node with the Selenium hub using the configuration which helps to start the test.

Finally, the test will run and generate the required reports. The developers should note the test results to avoid any discrepancies.

Thus, the above writings explain how to build an automated testing pipeline with GitLab CI/CD and Selenium Grid. This involves various steps and implementations that require creating the pipelines and their testing. GitLab CI/CD and Selenium Grid are the software development and testing tools that help in automation testing. Furthermore, it requires a certain environment also where the tests will execute along with various variables.

To know more about the testing tool and to develop a great career in this regard one can opt for Selenium Online Training India from different online sources. This learning will enhance the skill and knowledge in automation testing along with the way of making a successful career.