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

Gradle plugin

Browserstack provides a Gradle plugin GitHub repository to build, upload and start Espresso tests on App Automate. You can use this plugin for your development workflow as well as easy integration with BrowserStack on CI/CD server.

Getting started

Step 1: Update build.gradle

In order to configure the plugin, add the following to your app-level build.gradle file:

a. Add plugin dependencies

Add the plugin dependency and define the plugin task in the in the project level build.gradle file as shown below:

buildscript {
  repositories {
    ...
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.com.browserstack.gradle:browserstack-gradle-plugin:3.0.2"
  }
}
...
apply plugin: "com.browserstack.gradle"
...

Add the following maven repository & plugin dependency in the in the project level build.gradle.kts file as shown below:

allprojects {
  repositories {
    google()
    jcenter()
    maven ("https://plugins.gradle.org/m2/")
  }
}




dependencies {
  implementation("gradle.plugin.com.browserstack.gradle:browserstack-gradle-plugin:3.0.2")
}

b. Add browserStackConfig parameters

Add your BrowserStack access credentials and the file path to the Espresso configuration file (explained in next step) in the app level build.gradle file as shown below:

browserStackConfig {
    username = "YOUR_USERNAME"
    accessKey = "YOUR_ACCESS_KEY"
    configFilePath = "path/to/your/json/configFile"
}

Add your BrowserStack access credentials and the file path to the Espresso configuration file (explained in next step) in the app level build.gradle.kts file as shown below:

browserStackConfig { this:BrowserStackConfigExtension
    username = "YOUR_USERNAME"
    accessKey = "YOUR_ACCESS_KEY"
    configFilePath = "path/to/your/json/configFile"
}

Step 2: Create an Espresso configuration file

Create a JSON configuration file that contains all parameters to configure your Espresso test execution on BrowserStack. These parameters include setting the device(s), debugging options and any other App Automate feature you want to use. An example configuration file is shown below:

Select device
This device is not available in the free plan. Please upgrade to paid plan.
 

Step 3: Run the Gradle tasks

To build, upload and execute your Espresso tests, run the command below:

gradle clean executeDebugTestsOnBrowserstack

This will execute the following:

  1. Build the app (Debug APK) and Espresso test-suite (Test APK), as dependencies are declared on assembleDebug and assembleDebugAndroidTest tasks.
  2. Find the latest app APK and test APK in the app directory recursively.
  3. Upload both the APK files to BrowserStack servers.
  4. Execute Espresso test using the uploaded apps and test-suites on the devices specified in the Espresso configuration file.

On successful task execution, the test results will be available on the command-line interface, as well as the App Automate dashboard.

Sample command-line output:

Most recent DebugApp apk: /Users/{username}/AndroidStudioProjects/espresso-browserstack/app/build/outputs/apk/debug/app-debug.apk
Most recent TestApp apk: /Users/{username}/AndroidStudioProjects/espresso-browserstack/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk

App upload Response Code : 200
{"app_url":"bs://83c5dab1adac36004b5f6fc72d9d3136c17e3b5c"}

TestSuite upload Response Code : 200
{"test_url":"bs://83c5dab1adac36004b5f6fc72d9d3136c17e3b5c"}

Response Code : 200
{"message":"Success","build_id":"5a2bac8e53d4786bc2895316badc92299ee22fb9"}
View build status at https://app-automate.browserstack.com/builds/5a2bac8e53d4786bc2895316badc92299ee22fb9

For running tests on a project with build variants (i.e “product flavours”), you can simply run following command for to build, upload and run your Espresso tests:

gradle clean execute${buildVariantName}TestsOnBrowserstack

Replace ${buildVariantName} with your build variant name. For example, if your productFlavor name is “phone” and you want to test a debug build type of this variant, then command will be:

gradle clean executePhoneDebugTestsOnBrowserstack

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