Browserstack logo
  • AI Agents
  • Pricing
  • Manual Testing

    Live

    Cross-browser testing

    Testing Toolkit

    Essential manual testing tools

    Accessibility Testing

    Test WCAG compliance

    Website Scanner

    All-in-one website checker

    Test Automation

    Automate

    Browser automation cloud

    Low Code Automation

    Automation without coding

    Accessibility Automation

    Automate WCAG testing

    Percy

    Visual testing & review

    Custom Device Lab

    Tailored test environments

    Management & Optimization

    Test Management

    Plan, track, and manage tests

    Test Management for Jira

    Manage tests inside JIRA

    Test Reporting & Analytics

    Monitor & optimize tests

    Explore BrowserStack for Enterprise

    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 & review

    App Low Code Automation

    AI-driven automated tests

    Custom Device Lab

    Tailored test environments

    Management & Optimization

    Test Management

    Plan, track, and manage tests

    Test Management for Jira

    Manage tests inside JIRA

    Test Reporting & Analytics

    Monitor & optimize tests

    Explore BrowserStack for Enterprise

    control

    • Documentation
    • Support
    • Status
    • Release Notes
    • Open Source
    • Events
    • Meetups
    • BrowserStack Talks
    • Community
  • AI Agents
  • Pricing
  • Sign in
  • Free Trial
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
    • App Automate
    • App Live
    • Accessibility Testing
    • Automate
    • Test Management
    • App Accessibility Testing
    • Low Code Automation
    • Testing Toolkit
    • Percy
    • Custom Device Lab
    • Website Scanner
    • App Percy
    • App Low Code Automation
    • Test Reporting & Analytics
    • Requestly
    • Test Management for Jira
    • Test Companion
    • Load Testing

    WHY BROWSERSTACK

    • Customers
    • Case Studies
    • AI Agents
    • 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 (Beta)

    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

    We are available 24 / 7

    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
    Browserstack logo
    twitter social link facebook social link linkedin social link youtube social link instagram social link discord social link
    Contact Us

    We are available 24 / 7

    © 2026 BrowserStack. All rights reserved.

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