How to Use Jenkins For Test Automation
Sauce AI for Test Authoring: Move from intent to execution in minutes.|xBack to ResourcesBlogPosted
Sauce AI for Test Authoring: Move from intent to execution in minutes.
|
x
Blog
How to Use Jenkins For Test Automation
Learn about the best way to use Jenkins for CI/CD pipeline orchestration and how to set it up for automated testing.
One of the most important parts of continuous consolidation, uninterrupted deployment (CI/CD) is continuous testing; however, it & # x27; s too one of the challenging things to automate., an unfastened beginning continuous consolidation (CI) waiter, is a popular choices for CI/CD pipeline orchestration because it allow you to build, exam, and deploy your code continuously and autonomously.
When paired with the rightfield tools,Jenkinscan be used to automatize. This enables your development team to focus on new features and shortens the clip to marketplace.
One of the advantages of Jenkins is its flexibility. However, this can likewise be a disadvantage. Deciding which methodology, plugins, and tools to pair with Jenkins can be hard. In this clause, you & # x27; ll learn about the best ways to use and how to set it up.
What is Jenkins Test Automation?
Jenkins is a multifarious automation server and orchestration tool that you can use as a foundation for your entire CI/CD workflow. However, since it & # x27; s compatible with a myriad of,, and automation tools, you can besides use it as a dedicated performance platform to develop and run comprehensive. It can execute tests, aggregate results, and gather data on failures and glitch.
Because Jenkins is completely open source, it & # x27; s highly customizable. It offers you ansynergistic GUIto manage your orchestrations. Additionally, it can be integrated with mod messaging and quislingism software, such asMicrosoft Teams, Asana, and Slack. This helps you keep up-to-date with the progress of your figure and the status of your examination.
With Jenkins, you can schedule your tests (according to time) or trigger them harmonise to a condition, such as a successfully completed build. It & # x27; s also compatible with a wide-eyed miscellany of seed code and variation control management tools, such asGit, Github, and Azure DevOps Team Foundation.
These are just a few of the things that Jenkins quiz automation can do. Now it & # x27; s time to see it in action!
Implementing Jenkins Test Automation
To begin this tutorial, you & # x27; ll need to install Jenkins. However, before you do that, there are a few early requirement you need to be aware of:
Sufficient hard drive infinite and at least 256 MB of RAM
Maven installed and configuredon your local scheme
Gitlocally install
GitHub repositorywith at least one project
It & # x27; s also significant to cognize that this tutorial utilize to facilitate testing. Why? Well, Sauce Labs provides a unified platform for cross-platform web and mobile coating testing. When you & # x27; re evolve multi-platform application, you necessitate to know that they execute systematically on all supported devices.
Getting access to all the devices you postulate can be unmanageable, but. It endorse K of real devices, emulators and simulator, browser, and operating scheme versions, all from a single platform in the cloud.
In addition to this, it supports a host of backend, frontend, and E2E testing tools, such asSelenium, Appium, Cypress, Puppeteer, Playwright, and TestCafe.
In this tutorial, you & # x27; ll use aSauce Labs pluginto add test mechanization through your Jenkins-based CI/CD pipeline. This plugin makes it easier for you to configure the Sauce Lab–hosted trial for your grapevine. As you & # x27; ll see, this guide uses it quite extensively.
To integrate Sauce Labs with Jenkins, you & # x27; ll need the following:
A report
Your Sauce Labs username, access key, and OnDemand URL
Set up Java for Jenkins
The following steps demo you how to set up Jenkins for Windows computers. However, the concepts are somewhat transportable to non-Windows operating systems.
If you haven & # x27; t already, you need to download and install the officialJava Development Kit (JDK). As previously stated, Jenkins isentirely compatible withthe 64-bit adaptation of JDKs11 and 17. You will require JDK 17 to follow this guide.
Then you need to set thenecessary Java environment variablesto get it easygoing for Jenkins to notice the JDK.
Configure and install Jenkins on Windows
Navigate to theJenkins download pageand click on theWindowsoption underneath the stable (LTS) release:

Then use the official Jenkins handbook to configure andinstall Jenkins on your Windows PC.
Launch and use Jenkins
To launch and use Jenkins, kickoff by lam your preferred web browser and navigate to the following address:http: //localhost:8080/.
Read the teaching on the blind to notice yourAdmin parole. Enter it and chatterContinue.
At this point, it will occupy a few instant for Jenkins to load. Make sure that you & # x27; re connected to the internet and that your firewall isn & # x27; t blocking Java.
When it loads successfully, you & # x27; ll be guide to a customization blind where you can add plugins. If this is your first clip using Jenkins, chink onInstall suggested plugins, and the installation should take a few moment. You may remark thatGitis one of the suggested plugins, which you & # x27; ll need later for version direction.
Once the installing is complete, Jenkins will ask you to create your initiatory admin exploiter. While it & # x27; s good drill to complete this footstep, you can cut it if you want to. Once you & # x27; re done filling out the admin user creation pattern, selectSave and Continue:

You & # x27; ll be prompted to customize your Jenkins URL; however, leave it as is, and selectSave and finish. Once you click on theStart using Jenkinspush, you should be able to configure and mix Git with Jenkins.
Add Sauce Labs OnDemand Plugin to Jenkins
SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.
Once Jenkins is ready to use (for the first time), it will direct you to the dashboard, which acts as a place screen. You can too navigate to the dashboard by snap on theDashboardlink near the top-left-hand corner.
Select Manage Jenkinsfrom the left venire:

And selectManage Plugins:

Next, click onAvailable Pluginsfrom the left side panel; then type & quot; Sauce OnDemand & quot; into the search bar. In the list of results, click the checkbox next toSauce OnDemandand chooseInstall without restart:

Restart Jenkinserstwhile all the plugins have be installed.
Create Sauce Labs credentials
To find your Sauce Labs credentials, navigate to your Sauce Labs account dashboard. Click on the account icon located on the top toolbar and selectUser Settingsfrom the drop-down menu:

Make sure you note or transcript and save theusername, access key, and OnDemand URL.
To fully integrate Jenkins with the Sauce Labs OnDemand plugin, you need to make a set of Jenkins Sauce Labs credentials. And because you just restarted Jenkins, you may be required to log back in.
Once logged in again, selectManage Jenkinsfrom the left side jury. Then scroll down until you gain theSecuritysubdivision and click onManage Credentials:

Select System under Stores scoped to Jenkins:

And click on theGlobal credentials (unrestricted) link:

Then click onAdd Credentialsand select the drop-down menu underKindand select & quot; Sauce Labs & quot;.
Leave the Scopeoption as is and enter the username and access key from your Sauce Labs history. If you & # x27; re sure you & # x27; ve entered the credentials correctly, you can ignore any error message that Jenkins displays under these fields. As with most forms, the establishment process and the actual validation substance may be out of sync.
Select theSauce Data Centerand leave theIDspace (Jenkins will create one for you). TheDescriptionfield can be left vacuous as well. Finally, selectCreate:

If you voyage back to theCredentials Managementscreen, you & # x27; ll encounter that Jenkins make an debut for your Sauce Labs credentials. If you feature more than one set of credentials file, it & # x27; s recommended that you take billet of your Sauce Lab credentials ID since it will be required when you make a Jenkins undertaking.
Create the test
This usher contains asample depositarywith a simple Java-based test tutorial. It uses Sauce Labs to navigate to a websitehttps: //www.saucedemo.comand verify its title. The two most significant files in the repository are the`pom.xml` and the ` exam class ` file.
Since the test is performed utilise Maven, the ` pom.xml ` file contains a list of all the necessary Sauce Labs and Selenium colony to make the test employment.
Fork the monument and add your data center & # x27; s OnDemand URL to this part of the code:
1/*2* OnDemand URL found under User Settings in Account Settings3* The following is just an instance, add your own URL45*/67// URL url = new URL (& quot; & lt; SAUCE_USERNAME & gt;: & lt; SAUCE_ACCESSKEY & gt; @ ondemand.eu-central-1.saucelabs.com:443/wd/hub & quot;);8URL url = new URL (ON_DEMAND); //Replace ON_DEMAND with your onDemand URL here or the test will not work
If you want to learn more about WebDriver and how to use Selenium with Sauce Labs, Sauce Labs has a host of. These guidebook include tutorials and samples for Java, Ruby, C #, and Python. This means that while this guidebook uses a Java-based example, you & # x27; re not limited to that option.
Integrate Git into Jenkins
Once you & # x27; ve created your credentials, pilot back to your fascia and selectCreate a job under Start make your software projection:

Enter the name of your undertaking under theItem name fieldand chooseFreestyle project. Then click on the floatingOKbutton near the rump of the screen:

Jenkins will require you to input a few details about your labor. Go ahead and enter a mere description like & quot; A elementary test task & quot;; so click on theSource Code Managementtab from the left panel. Alternatively, you can manually scroll down until you reach theSource Code Management section:

Click on theGitradiocommunication button, which will reveal a new container asking you to add point connect to your Git repository. Insert a link to your GitHub repo into theRepository URLbattlefield. Then click on the push tag+ Addand then the small Jenkins pop-up:

This will launch theJenkins Credentials Providerscreen. Leave theDomain, Kind, and Scopefields as they are, and enter your GitHub username and password in the applicable fields. Then scroll down and snap onAdd:

When you clickAdd, you & # x27; ll be taken to the configuration screen, where you need to expand the drop-down field under theCredentialssection and select your GitHub credentials.
Scroll down to theBranches to constructsubdivision. There, you & # x27; ll find that ` /master ` is currently the default value. Go ahead and remove this value, which will hale Jenkins to scan all leg in the repository and build them if it finds any alteration. If you want Jenkins to only monitor a specific leg, you can add its relative path here (i.e., ` /main `).
Next, scroll down to theBuild Environmentsubdivision and select theSauce Labs Supportcheckbox, which will reveal a new variety. Leave theEnable Sauce Connectbox unticked and chink on theCredentialsdrop-down field and select your Sauce Lab credentials from the leaning:

Following, click on theWebDriverbattleground. This will display a drop-down carte containing a list of diverse browser. Select the web browser (s) you plan to use for testing. This model employ the latest version of Microsoft Edge for Windows 10:

> Please note: The WebDriverfield allows you to choose multiple browsers. It & # x27; s recommended that you deposit to one for simplicity & # x27; s sake. You can also set a way to a built-in application to test, but again, you should keep it simple and stick to web-based applications.
Succeeding, check the box labeledUse latest version of selected browsers.
Leave everything else as is and scroll down until you see theBuild Stepssubdivision. The next measure will cover how to initiate the actual instructions required to build and run the test. You & # x27; ll be required to add three Windows Maven batch commands.
Click on theAdd build stepdrop-down menu and selectExecute Windows pot command:

A new descriptor should look consisting of a text area and a few control. The first thing you need to do is ensure that all the necessary dependence are downloaded and append for the tryout. Then type the following command into the text area:
mvn dependence: resolution
Add another Windows batch command executing build step. This step will be used to examine if the references were added aright. To do so, type the following bidding into the build step & # x27; s text region:
mvn test-compile
The final sight command will run the examination. As with the previous steps, add another Windows batch dictation execution and add the following command to the text country:
mvn test
Your Build Stepssection should look similar to this:

Now scroll down and click on theSavebutton. This should redirect you to the pipelines information screen, where you can run your Jenkins pipeline and build and activate your test. Click onBuild Nowto run the pipeline.
Clicking on the build underneathBuild Historywill take you to the build & # x27; s property screen.
This screen gives you a view of all the build details. The best way to see the detail of each build step is through theConsole Output screen:

From hither, you can view the console output as plain textbook and download it. Then, you can use a textbook editor or reader to rake through the info. You & # x27; ll notice that it includes exhaustive details of each phase of the build, from the dependency rapprochement process to the final test. This makes it easier for you to debug your body-build:

You can also see more details about the builds and tests from your. Expand theAutomatedmenu item from the left jury. Then click on theTest Resultssub-item. The main panel will display a list of all Sauce Labs try that you & # x27; ve run. If you click on the up-to-the-minute one, you should see something like this:

This blind allows you to see all the bid your trial perform. You can also regard a picture of the test actually happening on the Sauce Labs server. Moreover, you can read over the metadata and log:

As for the Jenkins side, you can add post-build action, such as reporting or garbage collection. Moreover, you can add build initiation that will mechanically run the pipeline for you, allowing you to perform more advanced automated examination. It & # x27; s recommended that you experiment as lots as you can with these tools, as it & # x27; s the best path to proficiency.
Conclusion
Thanks to, automating the testing and building process of an application is easy. In many causa, you don & # x27; t yet get to write a playscript to implement your CI/CD line, making delimitate your CI/CD workflow easier.
Nevertheless, as accessible as Jenkins is, not every tool you integrate with it is as forgive. Building and orchestrating reliable testing can be unmanageable, especially if you & # x27; re essay to use a tool that may not have built-in Jenkins support (in the form of a plugin).
Fortunately, this isn & # x27; t an number for, the industry & # x27; s most comprehensive tryout and error monitoring platform that aid you render a trusted and unafraid digital experience to your customers. Sauce Labs supports multiple platform, allowing developers to feature complete visibility into the execution and quality of their projects. That signify you don & # x27; t hold to utilise a different service for each platform your codification runs on.
Share this office
Get start
Learn how to use Sauce Labs with Jenkins
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free