Integrate BrowserStack App Automate with Jenkins
Integrate your Appium test suite with Jenkins and BrowserStack device cloud for testing native and hybrid apps using our Jenkins plugin.
Introduction
Jenkins is an open-source Continuous Integration (CI) server, which automates the build and deploy process of your applications. By running your Appium test suite in Jenkins, you also automate testing as part of the build process. Add BrowserStack to the mix, and your apps can be tested across 3000+ real devices. BrowserStack allows you to integrate your Appium tests with Jenkins using a plugin that connects your Jenkins CI server to BrowserStack.
Use BrowserStack Jenkins plugin to:
- Configure your BrowserStack credentials for your Jenkins jobs.
- Upload your app build to BrowserStack servers.
- Set up and tear down BrowserStack Local binary for testing internal, development and staging environments.
- View BrowserStack test results, including video, logs, and screenshots in your Jenkins job results.
Prerequisites
You need the following set up before you begin
- An existing Jenkins CI server (version 1.653+)
- A BrowserStack account
Install Jenkins plugin
To run your Appium tests with Jenkins on BrowserStack, you will first need to download our Jenkins plugin. Before installing the plugin, ensure you have the necessary privileges to administer your Jenkins installation. We recommend doing this when there are no active build jobs running on Jenkins.
- Click on Manage Jenkins > Manage Plugins.
- Click on the Available tab.
- In the search box type BrowserStack.
-
Choose BrowserStack from the list of available plugins.
- Check the box and install the plugin.
- Once the plugin has been successfully installed you will be able to see it in the list of Installed plugins.
Configure your BrowserStack credentials
Once you’ve installed the plugin, you will need to configure your BrowserStack credentials to complete the integration between Jenkins and your Appium tests. Follow these steps to configure BrowserStack inside Jenkins:
- Go to Manage Jenkins > Configure System
- Under BrowserStack section, click on the Add button next to BrowserStack Credentials
-
Enter your BrowserStack Username and Access Key which you can find on your BrowserStack Account Settings page.
- Save your changes
Configure app upload step
Next, you will need to upload your app to BrowserStack servers and for that, you will need to configure the app upload build step. Follow these steps to configure a build step to upload your app to BrowserStack servers:
- Go to build job > Configure
- In the Build section, click on the Add build step
-
Select Upload App to BrowserStack
-
Enter the path to your app file on the local Jenkins server and click Save.
Configure BrowserStack Local
BrowserStack Local Testing allows you to test apps that retrieve data from servers on your local machine, CI/CD machines/nodes, and other private network configurations. The BrowserStack Jenkins plugin is responsible for:
- Downloading BrowserStack local binary for every platform that the build job is running on
- Setting up and tearing down the secure tunnel.
Enable BrowserStack Local
Under the Build Environment section check the box next to BrowserStack Local
- If you are using an externally downloaded binary, you can enter its location at BrowserStack Local Path. If left empty, the plugin will automatically download the binary (recommended). This is recommended especially if you are using Jenkins in master-slave configurations since the plugin will download the appropriate binary for the build agent OS.
- Use BrowserStack Local Options to set any additional configuration options when running the binary. Full list of options available in documentation for local testing modifiers
Once you’ve integrated BrowserStack Local through the Jenkins plugin, you can test mobile apps that access resources hosted in development or testing environments during automated test execution.
Set Environment variables
The BrowserStack Jenkins plugin sets the following environment variables:
BROWSERSTACK_USERNAME
BROWSERSTACK_ACCESS_KEY
BROWSERSTACK_APP_ID
BROWSERSTACK_BUILD_NAME
BROWSERSTACK_LOCAL
BROWSERSTACK_LOCAL_IDENTIFIER
Use these environment variables to set the DesiredCapabilities in your tests. For example:
String userName = System.getenv("BROWSERSTACK_USERNAME");
String accessKey = System.getenv("BROWSERSTACK_ACCESS_KEY");
String browserstackLocal = System.getenv("BROWSERSTACK_LOCAL");
String buildName = System.getenv("BROWSERSTACK_BUILD_NAME");
String browserstackLocalIdentifier = System.getenv("BROWSERSTACK_LOCAL_IDENTIFIER");
String app = System.getenv("BROWSERSTACK_APP_ID");
public static void main(String args[]) throws MalformedURLException, InterruptedException {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("app", app);
caps.setCapability("device", "Samsung Galaxy S8");
caps.setCapability("build", buildName);
caps.setCapability("browserstack.local", browserstackLocal);
caps.setCapability("browserstack.localIdentifier", browserstackLocalIdentifier);
}
driver = new AndroidDriver(new URL("https://"+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub", caps);
userName = process.env.BROWSERSTACK_USERNAME
accessKey = process.env.BROWSERSTACK_ACCESS_KEY
browserstackLocal = process.env.BROWSERSTACK_LOCAL
buildName = process.env.BROWSERSTACK_BUILD_NAME;
browserstackLocalIdentifier = process.env.BROWSERSTACK_LOCAL_IDENTIFIER
app = process.env.BROWSERSTACK_APP_ID
var capabilities = {
"browserstack.user" : userName,
"browserstack.key" : accessKey,
"app" : app,
"build" : buildName,
"device" : "Samsung Galaxy S8",
"browserstack.local" : browserstackLocal,
"browserstack.localIdentifier" : browserstackLocalIdentifier
}
driver = wd.promiseRemote("https://hub-cloud.browserstack.com/wd/hub");
driver
.init(capabilities)
//Write your code here
.fin(function() { return driver.quit(); })
.done();
userName = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");
accessKey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");
buildName = Environment.GetEnvironmentVariable("BROWSERSTACK_BUILD_NAME");
browserstackLocal = Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL");
browserstackLocalIdentifier = Environment.GetEnvironmentVariable("BROWSERSTACK_LOCAL_IDENTIFIER");
app = Environment.GetEnvironmentVariable("BROWSERSTACK_APP_ID");
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability("browserstack.user", userName);
caps.SetCapability("browserstack.key", accessKey);
caps.SetCapability("app", app);
caps.SetCapability("device", "Samsung Galaxy S8");
caps.SetCapability("build", buildName);
caps.SetCapability("browserstack.local", browserstackLocal);
caps.SetCapability("browserstack.localIdentifier", browserstackLocalIdentifier);
AndroidDriver driver = new AndroidDriver(new Uri("https://hub-cloud.browserstack.com/wd/hub"), caps);
$user_name = getenv("BROWSERSTACK_USERNAME")
$access_key = getenv("BROWSERSTACK_ACCESS_KEY")
$browserstack_local = getenv("BROWSERSTACK_LOCAL")
$buildName = getenv("BROWSERSTACK_BUILD_NAME")
$browserstack_local_identifier = getenv("BROWSERSTACK_LOCAL_IDENTIFIER")
$app = getenv("BROWSERSTACK_APP_ID")
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("app", app);
$capabilities->setCapability("device", 'Samsung Galaxy S8');
$capabilities->setCapability("build", buildName);
$capabilities->setCapability("browserstack.local", browserstack_local);
$capabilities->setCapability("browserstack.localIdentifier", browserstack_local_identifier);
$driver = RemoteWebDriver::create("https://"+user_name+":"+access_key+"@hub-cloud.browserstack.com/wd/hub", $capabilities);
user_name = os.getenv("BROWSERSTACK_USERNAME")
access_key = os.getenv("BROWSERSTACK_ACCESS_KEY")
browserstack_local = os.getenv("BROWSERSTACK_LOCAL")
build_name = os.getenv("BROWSERSTACK_BUILD_NAME")
browserstack_local_identifier = os.getenv("BROWSERSTACK_LOCAL_IDENTIFIER")
app = os.getenv("BROWSERSTACK_APP_ID")
desired_cap = {
'app': app,
'device': 'Samsung Galaxy S8',
'browserstack.local': browserstack_local,
'build': build_name,
'browserstack.localIdentifier': browserstack_local_identifier
}
driver = webdriver.Remote("https://"+user_name+":"+access_key+"@hub-cloud.browserstack.com/wd/hub", desired_cap)
user_name = ENV["BROWSERSTACK_USERNAME"]
access_key = ENV["BROWSERSTACK_ACCESS_KEY"]
browserstack_local = ENV["BROWSERSTACK_LOCAL"]
build_name = ENV["BROWSERSTACK_BUILD_NAME"]
browserstack_local_identifier = ENV["BROWSERSTACK_LOCAL_IDENTIFIER"]
app = ENV["BROWSERSTACK_APP_ID"]
desired_caps = {
'app': app,
'device': 'Samsung Galaxy S8',
'build': build_name,
'browserstack.local': browserstack_local,
'browserstack.localIdentifier': browserstack_local_identifier
}
appium_driver = Appium::Driver.new({
'caps' => desired_caps,
'appium_lib' => {
:server_url => "https://#{user_name}:#{access_key}@hub-cloud.browserstack.com/wd/hub"
}}, true)
browserstack.local
and browserstack.localIdentifier
capabilities to test on your local development servers.
View test report in Jenkins
BrowserStack Jenkins plugin enables you to embed the test results from BrowserStack App Automate into Jenkins. It shows summary of the build, and a grid of all the sessions in any given build. The plugin helps you to debug faster by highlighting failed tests and linking tests to the App Automate dashboard.
BROWSERSTACK_BUILD_NAME
environment variable to set build name in your test code. If you don’t use BROWSERSTACK_BUILD_NAME
the plugin will not be able to embed reports in Jenkins. Refer Using Environment variables section on how to use environment variables.
Enabling reporting is a simple process and doesn’t require any code change, follow the below steps:
- Click on Add post-build action dropdown in Post-build Actions section.
- Select BrowserStack Test Report from the dropdown.
- Click Save.
With this integration, you can now view the results of your Appium tests within Jenkins. You can know the summary of a build:
You can view the list of session of a build by clicking on View Full BrowserStack Report or by clicking on BrowserStack Test Report link in the sidebar.
Selecting any session from this table will take you to the App Automate dashboard where you can refer to video logs, text logs, screenshots, and other debugging options for a session.
Conclusion
By following the steps outlined in this guide, you should have a seamless integration between your existing automation in Jenkins, your Appium tests and BrowserStack device cloud. This will help you leverage all the benefits of test automation and the scale and coverage offered by BrowserStack
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
- RESOURCES
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!