Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & App Percy

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:

  1. Configure your BrowserStack credentials for your Jenkins jobs.
  2. Upload your app build to BrowserStack servers.
  3. Set up and tear down BrowserStack Local binary for testing internal, development and staging environments.
  4. 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.

  1. Click on Manage Jenkins > Manage Plugins.
  2. Click on the Available tab.
  3. In the search box type BrowserStack.
  4. Choose BrowserStack from the list of available plugins. Selecting BrowserStack plugin from list

  5. Check the box and install the plugin.
  6. Once the plugin has been successfully installed you will be able to see it in the list of Installed plugins. Jenkins Installed Plugins
Note: If BrowserStack plugin doesn’t show up in the list of Available plugins, click on the Check Now button to force Jenkins to pull the latest available plugins from Jenkins update center.

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:

  1. Go to Manage Jenkins > Configure System
  2. Under BrowserStack section, click on the Add button next to BrowserStack Credentials Add the BrowserStack Credentials
  3. Enter your BrowserStack Username and Access Key which you can find on your BrowserStack Account Settings page. Enter your BrowserStack Username and Access Key

  4. 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:

  1. Go to build job > Configure
  2. In the Build section, click on the Add build step
  3. Select Upload App to BrowserStack Click on Upload app to BrowserStack option from the build step dropdown

  4. Enter the path to your app file on the local Jenkins server and click Save.

    Uploading application file from local server and clicking save under the build option

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.
Note: BrowserStack Local can only be configured per job and not via global configuration.

Enable BrowserStack Local

Under the Build Environment section check the box next to BrowserStack Local
Setting Build Environment in Jenkins

Note:
  • 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)
Note: You must pass 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.

Warning: Please make sure to use 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:

  1. Click on Add post-build action dropdown in Post-build Actions section.
  2. Select BrowserStack Test Report from the dropdown.
  3. 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:

With this integration you can now view the results of your Appium tests within Jenkins

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.

List of session of a build in BrowserStack Reports

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.

Note: This plugin also supports integration with the reporting framework in Java - TestNG and JUnit. Learn more about integrating with reporting frameworks to know more about the integration steps.

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






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






Thank you for your valuable feedback!

Talk to an Expert
Download Copy