Open In App

How to Use Jenkins For Test Automation?

Last Updated : 22 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In the current dynamic software development arena, automation is paramount to the realization of quality and efficiency. These could be assured with test automation, greatly applied under the standard practices of CI and CD. Jenkins is used in implementing CI/CD pipelines. In this article, we will see how Jenkins can be put to use for automation in testing, such that the testing process will become faster and part of the development workflow.

What is Jenkins?

Jenkins is an open-source automation server that is commonly used in automating building, testing, and deploying software. It provides a robust platform for setting up CI/CD pipelines with the possibility of continuously integrating changes in the code and automating test runs. Jenkins is very rich in plugins; it is very extensible and has full-scale integration with tools and technologies, including but not limited to version control systems, build tools, and testing frameworks.

Why Jenkins Test Automation?

Using Jenkins for test automation brings several benefits to the software development lifecycle:

  • Continuous Testing: Jenkins automates the execution of test cases on every new code commit, ensuring early problem detection.
  • CI/CD Pipeline Integration: Jenkins integrates automatically with CI/CD pipelines, and automated tests can be run through various stages of a build and deployment process
  • Scalability: Jenkins is a distributed build tool that scales the process of test automation across many machines and environments.
  • Extensibility: This tool has more than 1,800 plugins and can be easily extended with other tools and frameworks for testing, such as Selenium, JUnit, and TestNG.

Advantages of Using Jenkins

  • Automated Testing: Jenkins enables you to automate the execution of your test cases, reducing manual effort and increasing test coverage.
  • Early Bug Detection: By running tests automatically with each code commit, Jenkins helps in identifying bugs early in the development process.
  • Consistent Environment: Jenkins ensures that tests are run in a consistent environment, reducing the chances of environment-related issues.
  • Integration with Other Tools: Jenkins can be integrated with a wide range of tools, including Git, Maven, and Docker, providing a comprehensive CI/CD solution.

Limitations of Using Jenkins

  • Complex Setup: Setting up Jenkins, in particular, is difficult and time-consuming for any large project with complex pipelines.
  • Maintenance Overhead: There is no denying that Jenkins indeed comes with a lot of maintenance overhead, from updating plugins to monitoring the server and troubleshooting pipelines.
  • Resource-Intensive: Running Jenkins, especially with distributed builds and complex pipelines, can become resource-intensive and require huge hardware resources.

When to Use Jenkins for Test Automation?

Jenkins is especially well-suited for automated testing in the following scenarios:

  • Frequent Code Integrations: Continuous testing by Jenkins will ensure that changes do not result in new issues in case there is a team of developers who commit codes frequently.
  • Complex Pipelines: Jenkins is very useful for projects that require complex continuous integration or continuous deployment pipelines where automated testing and deployment comprise part of the workflow.
  • Large test suites: With a large test suite to be executed consistently on various project environments, Jenkins will help in automating and scaling it without any hassles.

Step-by-Step process for using Jenkins for test automation

Step 1: Install Jenkins

  • Download and install Jenkins from the official website.
  • Follow the installation instructions for your operating system.
  • Start Jenkins by running the appropriate command or service.
sudo systemctl start jenkins
Screenshot-2024-08-09-141208

Integrating Jenkins with Git

  • Before going to create a new job we need to install some plugins to work with selenium

Step 2: Install Plugins

  • Navigate to manage jenkins and then plugins
  • Browserstack plugin
  • Testng results plugin for code generation
  • HTML Publisher Plugin
  • Maven Integration Plugin
Screenshot-2024-08-14-16

Now add credentials

  • Navigate to manage jenkins --> Credentials
  • Add credential to browser stack
Screenshot-2024-08-14-170657
  • Now same add github credentials also into jenkins

Step 3: Create New Job

  • Go to the Jenkins dashboard and click on New Item.
Screenshot-2024-08-09-141320
  • Enter a job name, and then select Freestyle project.
as
  • Click OK to create the job.

Step 4: Configure Git Repository

  • In the configuration of this job, under the Source Code Management section, select Git.
  • Enter the repository URL and credentials (if required).
  • Specify which branch is to be used for testing.
Screenshot-2024-08-14-165

Configuring a Job to Run an Automated Test with Jenkins

Step 5: Configure Build Triggers

Configure build triggers—this is how you can define the times of execution for the job. You may be available to use after each commit, schedule builds or execute your builds manually.

  • Here i am selecting build periodically * * * * * , meaning of this is its build every minute every day and every month
Screenshot-2024-08-09-142236

In Build Environment

  • Select in Build Environment as Browserstack and then add credentials which is previously added to jenkins
Screenshot-2024-08-14-171231

Step 6: Add Build Steps

  • It involves the inclusion of a build step in the configuration of the job for running automated tests, you can do this through several options like Execute shell, Invoke Ant, or Invoke Maven.
Screenshot-2024-08-14-171548

Save and Apply:

  • Save the configuration now when all the settings are in place.

Step 7: Executing the Job

Once the job is set up, an end-user may either execute it manually or let it run itself according to the configured triggers. Here's how one can run the job manually:

  • Go to the Job Dashboard Navigate to the job you created on the Jenkins dashboard.
  • Click on Build Now: This will trigger the job, and Jenkins will start running the test automation process.
Screenshot-2024-08-09-142528
  • Observe the Build: You are able to see the build progress and console output, in which you will find the test results.
Screenshot-2024-08-14-171724
Screenshot-2024-08-14-171927
  • Build was Successfully completed

Conclusion:

Jenkins is an amazing and powerful tool for test automation within CI/CD pipelines. By integrating Jenkins with your development workflow, you can ensure that your code is continuously tested, allowing for early bug detection and maintaining high-quality standards throughout the software development lifecycle. While Jenkins might have a steeper learning curve and require maintenance, its extensive plugin ecosystem, scalability, and community support make it a valuable asset for any development team aiming to implement robust continuous integration and delivery practices.


Next Article
Article Tags :

Similar Reads