Browserstack logo
  • Live for Teams
  • Pricing
  • Manual Testing

    Live

    Cross-browser testing

    Bug Capture

    Report & resolve bugs faster

    Accessibility Testing

    Test WCAG compliance

    Requestly

    HTTP interceptor & mocking

    Test Automation

    Automate

    Browser automation grid

    Automate TurboScale

    Automation on your Cloud

    Accessibility Automation

    Automate WCAG testing

    Percy

    Visual testing & review

    Low Code Automation

    Automation without coding

    Management & Optimization

    Test Management

    Unify & track all test cases

    Test Reporting & Analytics

    Monitor & optimize all tests

    Empower teams with BrowserStack for Enterprise →

    Tools: SpeedLab , Screenshots , Responsive

    Manual Testing

    App Live

    Real device testing

    App Accessibility Testing

    Test WCAG compliance

    Test Automation

    App Automate

    Real device automation cloud

    App Percy

    Visual testing for mobile apps

    Management & Optimization

    Test Management

    Unify & track all test cases

    Test Reporting & Analytics

    Monitor & optimize all tests

    Empower teams with BrowserStack for Enterprise →

    • Documentation
    • Support
    • Status
    • Release Notes
    • Open Source
    • Events
    • Meetups
    • Champions
  • Live for Teams
  • Pricing
  • Sign in
  • Free Trial
  • Manual Testing
  • Live
    Manual cross-browser testing
  • Accessibility Testing
    Super app to find & report issues
  • Test Automation
  • Automate
    Browser automation grid
  • Percy
    Visual testing & review
  • Management & Optimization
  • Test Management
    Unify & track all test cases
  • Test Reporting & Analytics
    Monitor & optimize all tests
  • For Teams
  • Enterprise
  • Manual Testing
  • App Live
    Manual real device testing
  • App Accessibility Testing
    Test WCAG compliance
  • Test Automation
  • App Automate
    Real device automation cloud
  • App Percy
    Visual testing for mobile apps
  • Management & Optimization
  • Test Management
    Unify & track all test cases
  • Test Reporting & Analytics
    Monitor & optimize all tests
  • For Teams
  • Enterprise
  • Documentation
  • Support
  • Status
  • Release Notes
  • Open Source
  • Events
  • Champions
  • 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 passing regular expressions in device and OS version capabilities on BrowserStack App Automate. Please refer to our documentation. 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}DebugTestsOnBrowserstack

      For projects with productFlavors, replace ${buildVariantName} with your build variant (i.e. "product flavours") 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
      • Automate TurboScale
      • Percy
      • App Live
      • App Automate
      • App Percy
      • Test Management
      • Test Reporting & Analytics
      • Accessibility Testing
      • Accessibility Automation
      • App Accessibility Testing
      • Low Code Automation
      • Bug Capture
      • Requestly

      WHY BROWSERSTACK

      • Customers
      • Case Studies
      • Browsers & Devices
      • Enterprise
      • Data Centers
      • Real Device Features
      • Security

      RESOURCES

      • Support
      • Status
      • Release Notes
      • Blog
      • Events
      • Community
      • Meetups
      • Champions
      • Guide
      • Partners
      • Find a partner
      • Trust Center
      • Test University

      COMPANY

      • About Us
      • Careers
      • Open Source
      • Press
      • Newsletter
      Browserstack logo
      SOCIAL
      twitter social link facebook social link linkedin social link youtube social link instagram social link discord social link
      Contact Us

      More Resources

      Cross Browser Testing Selenium Testing Test Management Emulators vs Real Device Mobile App Testing

      Test on Device

      Test on iPad Test on Galaxy Test In IE Test on Android Test on iOS Mobile Emulators Test on Right Devices

      Tools

      SpeedLab Screenshots Responsive Nightwatch.js
      discord social link
      Contact Us

      © 2025 BrowserStack. All rights reserved.

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