How to integrate Jenkins with Selenium?
On This Page What is Jenkins in Selenium?Steps t
- What is Jenkins in Selenium?
- Steps to instal Jenkins & amp; Selenium
- Integrating Jenkins with Selenium (using Jenkins Dashboard)
- Integrating Jenkins with Selenium using Maven
- Spry Installation – Jenkins plugins for Selenium integration
- Configuring Jenkins to run Selenium tests
- Creating a Jenkins job for Selenium screen
- Running Selenium Tests with Jenkins
- Top 3 Best Practices for Jenkins-Selenium Integration
- Benefits of integrating Jenkins with Selenium
How to integrate Jenkins with Selenium?
Jenkins is a well-known open-source DevOps instrument used in many establishment ’ CI/CD pipelines. Selenium is a popular open-source automation tool for prove website. Because of its user-friendliness and community help desk, Selenium enjoys widespread acceptation in the examination industry. There is no best example of uninterrupted integrating and deployment than the Jenkins Selenium combination.
Overview
What Is Jenkins in Selenium?
- Jenkins acts as an mechanization server to actuate Selenium tryout runs on code commits or docket.
- It helps in automate habitus, test execution, and reports.
Setup & amp; Configuration Steps
- Install Jenkins (download war file or via package) and go to the dashboard.
- Install Selenium and import the required fabric.
- Create Jenkins job in dashboard: Freestyle or Maven project.
- Configure build steps, workspace, test execution script, and browser/drivers.
- Use BrowserStack plugin or credential to run tests in the cloud if want.
Best Practices & amp; Benefits
- Maintains version control for your test codification.
- Schedule regular test performance and get feedback via reports.
- Make use of cloud platform (like BrowserStack) to run on different browsers/devices.
This clause will explain how to set up, configure, and use Jenkins to run Selenium trial expeditiously.
What is Jenkins in Selenium?
Jenkins, created by Hudson Lab, is the most popular open-source continuous integration application. It & # 8217; s cross-platform, meaning it works with Mac OS X, Linux, and Solaris. Jenkins is written in Java. Whether it & # 8217; s an SVN checkout, a cron job, or the status of an application, Jenkin can keep tabs on it all. When a specific job precondition is met, it will activate the specified actions.
- Whenever you vary your code, Jenkins can automatically perform your Selenium tests and then deploy your code to a new surroundings if the tests pass.
- Jenkins permit you to set a clip and date for action your tests.
- The Test Reports and performance logs can be salve for future reference.
- Jenkins can be used in a uninterrupted integration setup with Maven to create and essay a project.
can be performed in Jenkins whenever there is a software update, allowing for comprehensive testing of the updated codification against all possible inputs.
Steps to install Jenkins & amp; Selenium
Configuring Jenkins
You can install Jenkins from the Jenkins website on your computer. Jenkins may be launched from the command line or run on a web application waiter.
For command-line execution, see the details below.
- At the command prompting, execute java -jar postdate by the location of a .war file.
- If your Jenkins.war file has begun to run, you can confirm this by weigh enter and viewing the console output.
- Now you can see if Jenkins is set to go by using the default port of 8080.
- Just type & # 8220; http: //localhost:8080 & # 8221; into your browser & # 8217; s address bar. Your Jenkins user interface will load.
Installing Selenium
Several requirement must be set up before instal Selenium.
To begin automating with Selenium, you will need the next component:
- Java (JDK)
- Eclipse
- Selenium Client and WebDriver Language bindings
- Configuring
- Creating and Running the 1st trial
Must-Read:
Configuring Selenium
The methods toare as follow:
- Launch Eclipse foremost
- Create a workspace in Eclipse in measure two.
- Create a new Java project in the BrowserStack workspace in step three.
- Create a package and a class under the Java project in step four.
- Include Selenium JARs in Eclipse & # 8217; s Java Project
Integrating Jenkins with Selenium (utilize Jenkins Dashboard)
- To initiate a bracing project, go to the Jenkins dashboard and select the New Item button.
- Choose the Freestyle Project choice and enter the project & # 8217; s name. Proceed with theOK button.
- Fill out the Description box underGeneral Section to briefly overview the task.
- Select & # 8220;None& # 8221; under & # 8220; Source Code Management. & # 8221;
- When deciding how to schedule the occupation, we can pick the appropriate choice from the furnish option. To schedule the undertaking, let & # 8217; s go ahead and set a time boundary. Here is a list of guidelines that must be observed when mention the time figure.
- Make a project with to fulfill the tests.
importee electrostatic org.testng.Assert.assertEquals; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; signification org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public family LoginPage {WebDriver driver; @ BeforeTest public void setUp () {System.setProperty (`` webdriver.chrome.driver '', `` C: \\Users\\Sidharth\\Downloads\\chrom86_driver\\chromedriver.exe ''); driver = new ChromeDriver ();} public null login () {String login_url = `` https: //opensource-demo.orangehrmlive.com/ ''; driver.get (login_url); driver.manage () .window () .maximize (); driver.manage () .timeouts () .pageLoadTimeout (10, TimeUnit.SECONDS); driver.findElement (By.id (`` txtUsername '')) .sendKeys (`` Admin ''); driver.findElement (By.id (`` txtPassword '')) .sendKeys (`` admin123 ''); System.out.println (driver.getTitle ());} @ Test public void dashboard () {driver.findElement (By.id (`` menu_dashboard_index '')) .click (); String textPresent = driver.findElement (By.xpath (`` // * [@ id=\ '' content\ ''] /div/div [1] /h1 '')) .getText (); String textToBePresent = `` DashBoard ''; assertEquals (textPresent, textToBePresent);} @ AfterTest populace void tearDown () {driver.quit ();}}- Create a file named TestNG.xml.
- Create a distinguishable pamphlet for each dependency and property it in the project folder. Make a bat file with the information listed below.
java -cp bin; lib/ * org.testng.TestNG TestNG.xml
- Give a accurate name to the TestNG.xml file you made in your project.
- Choose the newly constitute project in Jenkins & # 8217; s dashboard. Click Configure. ClickAdvanced in the General section, so select & # 8220;Use custom workplace. & # 8221; Indicate the test projection & # 8217; s itinerary (path).
- Select the & # 8220; Execute Windows batch Command & # 8221; choice from the Add Build Step dropdown box in the Build section. Indicate the name of the bat file generated in Step 7.
- Click Apply and then Save to commit your changes to the Jenkins project. Click Build now to see the status of the tests being run in the Jenkins project.
Integrating Jenkins with Selenium using Maven
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
Maven
is a substantial project and build management tool based on the mind of a POM (Project Object Model). Its configuration data includes projection info and details about the construction directory, source directory, dependency, tryout source directory, goals, and plugins, among other things.
- First, found the Jenkins service.
- Launch a browser and go to the port and localhost where Jenkins run.
- On the dashboard, select New Item.
- Enter the undertaking gens and choose Maven task as the project category.
- Hit & # 8220; OK. & # 8221; You can see in the dashboard that a job has been effectively create.
- After selecting the project, hit Configure.
- Enter the full route to your pom.xml under the Build subdivision. Enter the command & # 8220; clean trial & # 8221; in the Goals and Options.
- Save after selecting Apply.
- Select & # 8220; Build Now. & # 8221;
- Click the console output to see the entire records.
Quick Installation – Jenkins plugins for Selenium integration
With the help of the, setting up Jenkins to conduct tests on BrowserStack is a air. Jenkins is a tool for continuous consolidation that countenance for the examination, building, and deploying of code in its many iterations.
Failures can be prevented before they reach the production stage with.
Ensure the following task are finished before you start the integration:
- You now have the modish version of the Jenkins CI server (v1.653+) loaded.
- Possession of one & # 8217; s Access Key and Username for one & # 8217; s BrowserStack chronicle.
- You feature set up a grapevine, and the Jenkins server operates locally at the default porthole of http: //localhost:8080/.
- You are the secretary & # 8217; s owner or sustainer.
- Your project & # 8217; s repository will now include a Jenkinsfile.
Configuring Jenkins to run Selenium examination
To install the BrowserStack plugin, follow the steps below:
- Click Manage Jenkins in the unexpended navigation on your Jenkins page, which is accessible by default at http: //localhost:8080/.
- Click Manage Plugins on the Manage Jenkins page.
- On the page for Plugin Manager, select the Available tab.
- Find BrowserStack habituate the search box.
- Depending on your preference, select BrowserStack and pick Install without restart or Download now and install after restart.
- View the installation status of the plugin on the Installing Plugins/Upgrades page.
- Once facility is accomplished, select Return to the top page to configure the plugin.
Creating a Jenkins job for Selenium examine
At this point, all that remains is to build and set up a new Jenkins design to execute the machine-controlled examination.
- Click Manage Jenkins & gt; Configure System on your Jenkins page athttp: //localhost:8080.
- Click Add & gt; Jenkins in the BrowserStack Credentials subdivision.
- Type your Username and Access Key into the Jenkins Credentials Provider: Jenkins window.
- Then click Authenticate. A Success argument display after the plugin has sustain your BrowserStack credentials.
- In the Jenkins Credentials Provider: Jenkins window, click Add at the bottom. You & # 8217; ll be conduct to the configuration screen after that.
- Click Save on the configuration screen.
- Click Manage Jenkins & gt; Manage Credentials on the Jenkins Dashboard.
- Write down the ID of the certificate that is displayed in the ID column in the Credentials area. This ID will be used in your project & # 8217; s Jenkinsfile.
- Add the BrowserStack (credentialsId: & # 8216; credential_id & gt; & # 8217;) line to your projection & # 8217; s Jenkinsfile and enclose all exam require inside of it as evidence below:
browserstack (credentialsId: ' & lt; credential_id & gt; ') {# your test commands}The next instance Jenkinsfile specifies a sample shell bid, the setup footstep, and the credential ID:
pipeline {agent any stages {stage ('setup ') {steps {browserstack (credentialsId: 'dw471drf-db68-4r23b-969d-24r3r32f ') {echo `` hi ''}}}}}Running Selenium Tests with Jenkins
1. Triggering Selenium trial with Jenkins
Integrating BrowserStack with current test cases implicate editing your trial case to add BrowserStack capableness, credentials, and a remote URL. Even though your current test scripts include capabilities, BrowserStack anticipate specific capabilities, such as browser version, to facilitate determine how tests are run.
This codification snip mentioned below demonstrates the BrowserStack-specific features
username = process.env.BROWSERSTACK_USERNAME accessKey = process.env.BROWSERSTACK_ACCESS_KEY buildName = process.env.JENKINS_LABEL var capability = {'bstack: options ': {'' os '': `` Windows '', '' osVersion '': `` 10 '', '' sessionName '': `` BStack Build Name: `` + buildName, '' userName '': username, '' accessKey '': accessKey, '' seleniumVersion '': `` 4.0.0 '',}, '' browserName '': `` Chrome '', '' browserVersion '': `` 100.0 '',} var driver = new webdriver.Builder (). usingServer (`` https: //hub-cloud.browserstack.com/wd/hub ''). withCapabilities (capabilities). progress ();Add the following dictation to your Jenkinsfile to begin your test:
- Go to your undertaking & # 8217; s Jenkinsfile.
- As shown below, add the instructions and wrap all examination require inside the BrowserStack statement. Add the command expend to perform parallel tests.
grapevine {agent any phase {stage ('setup ') {steps {browserstack (credentialsId: ' & lt; credential_ID & gt; ') {// add command to run test // Following are some of the representative command -- -- - s 'npm install' sh 'node single.js' sh 'node parallel.js'}} # ...}}}2. Scheduling Jenkins for Automatic Execution
Let & # 8217; s expression at the Jenkins job scheduling apparatus. You don & # 8217; t need to be familiarize with Linux & # 8217; s require line environment to understand it, but it resembles the cron syntax quite a bit. A scheduling entry comprises five fields that are separated by whitespace. By supply extra debut, you can schedule a task multiple times.
One of the key features of Jenkins is scheduling builds (Selenium Tests), which automatically induct the build found on predefined criteria. Jenkins & # 8217; s Build Trigger contour volunteer respective methods to start the build operation.
3. Viewing Test Results in Jenkins
You can integrate the test findings from BrowserStack Automate into Jenkins using the BrowserStack Jenkins plugin.
The method below can:
- Go to the project & # 8217; s Jenkinsfile.
- After the BrowserStack section in the Jenkinsfile, add the adjacent line of code:
// Enable reporting in Jenkins browserStackReportPublisher 'automate '
- The following is an example Jenkinsfile that makes use of the browserStackReportPublisher & # 8216; automate & # 8217; argument:
pipeline {agent any instrument {nodejs `` node ''} stages {stage ('setup ') {steps {browserstack (credentialsId: 'e04r231dce-cb60-23db-939d-2ewdc95f03edf7b3 ') {// some example trial commands ... sh 'npm install' sh 'node parallel.js'} // Enable reporting in Jenkins browserStackReportPublisher 'automate'}}}}Now that Jenkins is integrated, you can see the outcomes of the exam that you ran on BrowserStack.
Top 3 Best Practices for Jenkins-Selenium Integration
1. Organizing tests in Jenkins
You can test web apps hosted on internal, private, and development waiter using. You can establish a individual, untroubled link between your internal servers and the BrowserStack Selenium Grid utilise the Local testing binary. The BrowserStack Jenkins plugin carries out these tasks.
2. Version Control for Selenium test
The operation of monitoring and handle modifications to package codification is known as version control, also mention to as source control. Software tools, and version control system, assist package development teams in tracking changes to source codification over time.
- You can better savvy the context and the coverage anticipated by the test lawsuit by understanding how and when a exam case was modified.
- The tester who created the test may have understood why the function was screen that way, but would a new team member today comprehend it?
- A variation history will enable the new squad member to grasp precisely what the test was intended to cover in its initial loop and why and how it has changed over time.
- Additionally, it aids the testers in insure that the test still covers the purposes for which it was initially written despite numerous minor modifications made over time.
Github and Gitlab are two major options for this, but there are other pick. Using Git & # 8217; s robust feature, you can easily track changes to your codification tests and label specific subdivision or pushes with adaptation numbers.
3. Integrating other tools with Jenkins and Selenium
The Jenkins plugin for BrowserStack makes it simpler to set up Jenkins to perform trial on BrowserStack. This will exhibit you how to integrate the results of your BrowserStack Automated tests with test reporting framework.
Benefits of integrating Jenkins with Selenium
Using test frameworks like Nose2, PyTest, Robot, Selenium, and more, Jenkins can be expend to channel out automation testing.
- Selenium can run test hand, make test findings, and carry out post-actions like printing test reports, among other things.
- It can still test cases against various input combinations to achieve great tryout coverage.
- The receives update whenever there is an execution modification.
- Developers are updated on the outcomes of the shape and test stages, and automation testing is conducted continuously.
Closing Notes
Choose a cloud-based testing program like BrowserStack that.
Implement the BrowserStack Jenkins faculty to:
- Establish and tear down the BrowserStack Local binary to evaluate internal, development, and staging environments.
- Include exam results from BrowserStack, such as video, logs, and snapshot, in your Jenkins job event.
- Start conducting tests on a of 3000+ real browsers and device, and integrate the tests seamlessly into a CI/CD pipeline for maximum efficiency and accuracy.
On This Page
- What is Jenkins in Selenium?
- Steps to install Jenkins & amp; Selenium
- Integrating Jenkins with Selenium (using Jenkins Dashboard)
- Integrating Jenkins with Selenium using Maven
- Quick Installation – Jenkins plugins for Selenium integrating
- Configuring Jenkins to run Selenium exam
- Creating a Jenkins job for Selenium testing
- Running Selenium Tests with Jenkins
- Top 3 Good Practices for Jenkins-Selenium Integration
- Benefits of integrating Jenkins with Selenium
# Ask-and-Contributeabout this topic with our Discord community.
Related Guides
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