We use cookies to enhance user experience, analyze site usage, and assist in our marketing efforts. By continuing to browse or closing this banner, you acknowledge that you have read and agree to our Cookie Policy, Privacy Policy and Terms of Service.

Browserstack logo
  • Live for Teams
  • Pricing
    • Test your websites
    • Live
      Interactive cross browser testing
    • Automate
      Selenium testing at scale
    • Percy
      Visual testing & review
    • Test your mobile apps
    • App Live
      Interactive native & hybrid app testing
    • App Automate
      Test automation for native & hybrid mobile apps
    • App Percy Beta
      Visual testing for native & hybrid mobile apps

    Use BrowserStack with your favourite products. See our Integrations ⟶

    • For Teams
    • Enterprise
    • Tools
    • Screenshots
    • Responsive
    • SpeedLab
    • Documentation
    • Support
    • Status
    • Release Notes
    • Open Source
    • Events
    • Champions
  • Live for Teams
  • Pricing
  • Sign in
  • Free Trial
  • Test your websites
  • Live
    Interactive cross browser testing
  • Automate
    Selenium testing at scale
  • Percy
    Visual testing & review
  • Test your mobile apps
  • App Live
    Interactive native & hybrid app testing
  • App Automate
    Test automation for native & hybrid mobile apps
  • App Percy
    Visual testing for native & hybrid mobile apps
  • For Teams
  • Enterprise
  • Tools
  • Screenshots
  • Responsive
  • SpeedLab
  • Documentation
  • Support
  • Status
  • Release Notes
  • Open Source
  • Events
  • Champions
  • Get help
  • Documentation
  • Developer tools
  • Integrations
  • Integration URL
  • Local testing
  • References
  • Features
  • Mobile Features
  • Test on Right Devices
  • Browsers & Devices
  • Security
  • Status
Home Documentation App Automate Espresso Gradle

Gradle Plugin

Documentation for running Espresso test using BrowserStack's Gradle Plugin.

Note: The new major version of Browserstack espresso gradle plugin 3.0.0 is released. User now needs to create a json config file and specify it in the configFilePath as mentioned in the steps below. Also, the command runDebugBuildOnBrowserstack has now been deprecated.

Getting Started

The plugin allows to build your apps and execute the tests on BrowserStack. Github: BrowserStack Gradle Plugin.

Step 1: Add to build.gradle

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

  1. Add the BrowserStack plugin dependencies

    Add the dependency and the lines that defines the plugin task as shown:

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

  2. Add browserStackConfig parameters

    Add the following lines to authenticate user and load configurations from the json configuration file(details about the config file explained in next step):

    browserStackConfig {
        username = "BROWSERSTACK_USERNAME"
        accessKey = "BROWSERSTACK_ACCESS_KEY"
        configFilePath = "path/to/your/json/configFile"
    }
    

    Note: username, accessKey and configFilePath are mandatory for starting tests using gradle plugin for espresso

Step 2: Create an Espresso configuration file

In this step, you need to create JSON text file that contains all espresso related parameters for configuring your test execution on BrowserStack. These parameters include specifying the devices, debugging options, using device features and so on.

1. Select an Operating System
iOS
Mobile
  • iOS
  • Android
Desktop
2. Select a browser
Windows XP
Select a device
iOS
This device is not available in the free plan. Please upgrade to a paid plan.
We now support testing on latest iOS minor versions on BrowserStack App Automate. Please refer our documentation
3. Select a resolution
1024 x 768
Resolution

    Sample configuration file

    {
        "devices": [
          "Google Pixel-7.1"
        ],
        "project": "EspressoGradleTest"
        "deviceLogs": true,
        "networkLogs": true,
        .....
    }
    

    Note: To view the list of all supported parameters for Espresso tests on BrowserStack, visit complete list of API parameters section inside our Espresso Get Started documentation

    Step 3: Execute

    Execute below command to build your app and run your Espresso test

    gradle clean executeDebugTestsOnBrowserstack

    This will execute the following:

    1. Build debug and test apks, 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 apks on BrowserStack server.
    4. Execute Espresso test using the uploaded apps on the devices mentioned in the configuration.

    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
    Note:

    For running tests on a project with no variants, you can simply run following command for uploading and running tests on the debug apk:

    gradle clean execute${buildVariantName}TestsOnBrowserstack

    For projects with productFlavors, replace ${buildVariantName} with your build variant name, for example if your productFlavor name is "phone" and you want to test debug build type of this variant then command will be:

    gradle clean executePhoneDebugTestsOnBrowserstack

    In This Article

    • Getting Started
    • Add to build.gradle
    • Create an Espresso configuration file
    • Execute
    Related Articles

    Espresso Get Started

    Local Testing

    Rest API

    Jenkins

    Products

    • Live
    • Automate
    • Percy
    • App Live
    • App Automate
    • App Percy Beta
    • Screenshots
    • Responsive
    • Enterprise
    • SpeedLab New!

    Platform

    • Browsers & Devices
    • Data Centers
    • Device Features
    • Security

    Solutions

    • Test on iPhone
    • Test on iPad
    • Test on Galaxy
    • Test In IE
    • Android Testing
    • iOS Testing
    • Cross Browser Testing
    • Emulators & Simulators
    • Selenium
    • Cypress
    • Android Emulators
    • Visual Testing

    Resources

    • Test on Right Devices
    • Support
    • Status
    • Release Notes
    • Case Studies
    • Blog
    • Events
    • Test UniversityBeta
    • Champions
    • Mobile Emulators
    • Guide
    • Responsive Design
    • Nightwatch

    Company

    • About Us
    • Customers
    • Careers We're hiring!
    • Open Source
    • Partners
    • Press
    BrowserStack Logo An illustrated of BrowserStack Logo

    Social

    • BrowserStack Twitter Account An illustrated of white twitter Logo
    • BrowserStack FaceBook Account An illustrated of white FaceBook Logo
    • BrowserStack LinkedIn Account An illustrated of white LinkedIn Logo
    • BrowserStack Youtube Channel An illustrated of white youtube Logo
    • BrowserStack Instagram Account An illustrated of white instagram Logo
    BrowserStack Contact Us Icon An illustration of white contact us icon Contact Us

    © 2011-2023 BrowserStack - The Most Reliable Mobile App & Cross Browser Testing Company

    • Terms of Service
    • Privacy Policy
    • Cookie Policy
    • Sitemap