Get your setup working faster. Join our Discord for optimisation tips from elite testers.Join our Discord
View Build reports in Jenkins
Jenkins is a continuous integration tool that enables continuous testing, build, and deployment of iterative code changes. CI/CD tools help catch failures ahead of the production stage and mitigate them as they occur.
Prerequisites
Before you can start integration, ensure that the following tasks are complete.
Jenkins CI server (v1.653+) is installed on your machine.
After installing and configuring the BrowserStack plugin, you can now integrate Test Reporting & Analytics with Jenkins using either of the following methods:
Using the jenkinsfile.
Using Post-build actions in Jenkins.
Step 1: Install the BrowserStack Plugin
To install the BrowserStack plugin, complete the following steps:
Go to your Jenkins page, running by default on http://localhost:8080/, and click Manage jenkins in the left navigation bar.
On the System configuration page, click Plugins.
Search for BrowserStack in the search box.
Select BrowserStack and click either Install without restart or Download now and install after restart, depending on your preference.
On the Installing Plugins/Upgrades page, view the installation status of the plugin.
After installation is successful, click Go back to the top page to configure the plugin.
Step 2: Configure BrowserStack credentials in Jenkins
After you’ve installed the plugin, complete the following steps to configure your BrowserStack credentials in the plugin:
On your Jenkins page (http://localhost:8080/), click Manage Jenkins > System.
Under the BrowserStack Credentials section, click Add > Jenkins.
In the Jenkins Credentials Provider: Jenkins window, enter your Username and Access Key.
Click Authenticate. After the plugin verifies your BrowserStack credentials, a Success text appears.
Click Add at the bottom of the Jenkins Credentials Provider: Jenkins window. You will be redirected to the configuration page.
On the Configuration page, click Save.
On your Jenkins Dashboard, click Manage Jenkins > Credentials.
In the Credentials section, note down the ID of the credential shown in the ID column. This ID will be used in the Jenkinsfile of your project.
In the Jenkinsfile of your project, add the browserstack(credentialsId: '<credential_id>') statement and wrap all the test commands inside it, as follows:
```
browserstack(credentialsId: '<credential_id>') {
# your test commands
}
```
Integrate BrowserStack TRA with Jenkins using the Jenkinsfile
To integrate BrowserStack with Jenkins using the jenkinsfile, you need to add the BrowserStack plugin to your pipeline script. Here’s an example of how to do this:
pipeline{agentanystages{stage('Test'){steps{script{browserstack{// Your test commands go here}}}}}}
Integrate existing test cases
With existing test cases, integrating BrowserStack involves editing your test cases to add BrowserStack capabilities, credentials, and remote URL.
Though your existing test scripts include capabilities, BrowserStack expects specific capabilities, such as browser version, etc. that help determine how tests are run. This example code snippet shows the BrowserStack specific capabilities.
Step 1: Set environment variables in test script
The BrowserStack Jenkins plugin sets the following environment variables:
username=ENV['BROWSERSTACK_USERNAME']accessKey=ENV['BROWSERSTACK_ACCESS_KEY']buildName=ENV['JENKINS_LABEL']# to run on Chromeoptions=Selenium::WebDriver::Options.chromecapabilities={'bstack:options'=>{"os"=>"Windows","osVersion"=>"10","sessionName"=>"BStack Build Name: "+buildName,"seleniumVersion"=>"4.0.0",},"browserName"=>"Chrome","browserVersion"=>"100.0",}options.add_option('bstack:options',bstack_options)driver=Selenium::WebDriver.for(:remote,:url=>"https://"+username+":"+accessKey+"@hub.browserstack.com/wd/hub",:capabilities=>options)
Stringusername=System.getenv("BROWSERSTACK_USERNAME");StringaccessKey=System.getenv("BROWSERSTACK_ACCESS_KEY");StringbuildName=System.getenv("BROWSERSTACK_BUILD_NAME");DesiredCapabilitiescapabilities=newDesiredCapabilities();capabilities.setCapability("os","Windows");capabilities.setCapability("os_version","10");capabilities.setCapability("browser","chrome");capabilities.setCapability("browser_version","latest");capabilities.setCapability("name","BStack-[Java] Sample Test");// test buildNamecapabilities.setCapability("build",buildName);// CI/CD job name using BROWSERSTACK_BUILD_NAME env variabledriver=newRemoteWebDriver(newURL("https://"+username+":"+accessKey+"@hub.browserstack.com/wd/hub"),capabilities);
varusername=process.env.BROWSERSTACK_USERNAME;varaccessKey=process.env.BROWSERSTACK_ACCESS_KEY;varbuildName=process.env.BROWSERSTACK_BUILD_NAME;varcapabilities={"os":"Windows","os_version":"10","browser":"chrome","browser_version":"latest","name":"BStack -[Jenkins] Sample Test",// test name"build":buildName,// CI/CD job name using BROWSERSTACK_BUILD_NAME env variable"browserstack.user":username,"browserstack.key":accessKey};vardriver=newwebdriver.Builder().usingServer("https://hub-cloud.browserstack.com/wd/hub").withCapabilities(capabilities).build();
usingSystem;usingOpenQA.Selenium;usingOpenQA.Selenium.Remote;namespaceSeleniumTest{classProgram{staticvoidMain(string[]args){username=Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");accessKey=Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");buildName=Environment.GetEnvironmentVariable("BROWSERSTACK_BUILD_NAME");IWebDriverdriver;OpenQA.Selenium.Chrome.ChromeOptionscapability=newOpenQA.Selenium.Chrome.ChromeOptions();capability.setCapability("os","Windows",true);capability.AddAdditionalCapability("os_version","10",true);capability.AddAdditionalCapability("browser","Chrome",true);capability.AddAdditionalCapability("browser_version","latest",true);capability.AddAdditionalCapability("name","BStack-[Jenkins] Sample Test",true);// test namecapability.AddAdditionalCapability("build",buildName,true);// CI/CD job name using BROWSERSTACK_BUILD_NAME env variablecapability.AddAdditionalCapability("browserstack.user",username,true);capability.AddAdditionalCapability("browserstack.key",accessKey,true);driver=newRemoteWebDriver(newUri("https://hub-cloud.browserstack.com/wd/hub/"),capability);// test steps}}}
$username=getenv("BROWSERSTACK_USERNAME");$accessKey=getenv("BROWSERSTACK_ACCESS_KEY");$buildName=getenv("BROWSERSTACK_BUILD_NAME");$caps=array("os"=>"Windows","os_version"=>"10","browser"=>"chrome","browser_version"=>"latest","name"=>"BStack-[Jenkins] Sample Test",// test name"build"=>$buildName,// CI/CD job name using BROWSERSTACK_BUILD_NAME env variable);$web_driver=RemoteWebDriver::create("https://".$username.":".$accessKey."@hub-cloud.browserstack.com/wd/hub",$caps);
username=os.getenv("BROWSERSTACK_USERNAME")access_key=os.getenv("BROWSERSTACK_ACCESS_KEY")build_name=os.getenv("BROWSERSTACK_BUILD_NAME")caps={'os':'Windows','os_version':'10','browser':'chrome','browser_version':'latest','name':'BStack-[Jenkins] Sample Test',# test name
'build':build_name,# CI/CD job name using BROWSERSTACK_BUILD_NAME env variable
'browserstack.user':username,'browserstack.key':access_key}driver=webdriver.Remote(command_executor='https://hub-cloud.browserstack.com/wd/hub',desired_capabilities=caps)
username=ENV["BROWSERSTACK_USERNAME"]access_key=ENV["BROWSERSTACK_ACCESS_KEY"]build_name=ENV["BROWSERSTACK_BUILD_NAME"]caps=Selenium::WebDriver::Remote::Capabilities.newcaps["os"]="Windows"caps["os_version"]="10"caps["browser"]="chrome"caps["browser_version"]="latest"caps["name"]="BStack-[Jenkins] Sample Test"# test namecaps["build"]=build_name# CI/CD job name using BROWSERSTACK_BUILD_NAME env variablecaps["browserstack.user"]=usernamecaps["browserstack.key"]=YOUR_ACCESS_KEYdriver=Selenium::WebDriver.for(:remote,:url=>"https://hub-cloud.browserstack.com/wd/hub",:desired_capabilities=>caps)
Use the following example code snippet to set environment variables and capabilities in your app tests:
Add commands in your Jenkinsfile to run your test using the following steps:
Go to the Jenkinsfile of your project.
Add the commands and wrap all the test commands inside the browserStack statement, as follows. To run parallel tests, add the command used to run parallel tests.
```groovy
pipeline {
agent any
stages {
stage('setup') {
steps {
browserstack(credentialsId: '<credential_ID>') {
// add commands to run test
// Following are some of the example commands -----
sh 'npm install'
sh 'browserstack-node-sdk jest src/sample.test.js'
}
}
# ...
}
}
}
```
```groovy
pipeline {
agent any
stages {
stage('setup') {
steps {
browserstack(credentialsId: '<credential_ID>') {
// add commands to run test
// Following are some of the example commands -----
sh 'npm install'
sh 'node single.js'
sh 'node parallel.js'
}
}
# ...
}
}
}
```
Integrate BrowserStack TRA with Jenkins using post-build actions in Jenkins
In Jenkins, you can set up post-build actions for BrowserStack Report Integration. To do this, complete the following steps:
In Jenkins, click Configure.
In the Post-build Actions section, click Add post-build action.
Select BrowserStack Test Report and Insights.
View test reports in Jenkins
The BrowserStack Jenkins plugin enables you to embed the test results from BrowserStack TRA into Jenkins. The report gives an overall summary of the test build and its sessions.
Ensure that you set the build capability to the BROWSERSTACK_BUILD_NAME environment variable in your test script without which the plugin fails to generate and embed reports in Jenkins. Check out the Using Environment variables section to learn about environment variables.
With this integration, you can now view the results of your tests run on BrowserStack within Jenkins.
Click either View Full BrowserStack Report or BrowserStack Test Report link in the left navigation bar to view the list of test sessions.
Selecting any session from this table redirects you to the dashboard where you can view video recording, text logs, and other debugging options for a session.
This plugin also supports integration with the reporting framework in Java - TestNG and JUnit & NodeJS - Protractor and WebdriverIO. Check out the integrate Jenkins with reporting frameworks section to learn about the integration steps.
Rerun failed tests
You can rerun failed tests from the BrowserStack Test Reporting & Analytics dashboard after integrating Jenkins. For more information, refer to rerun failed tests using Jenkins
Did this page help you?
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback
Is this page helping you?
Yes
No
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked