This repository contains the source code for BrowserStack's Gradle plugin.
This plugin consists of two types of tasks:
- Builds, uploads and starts Espresso tests on BrowserStack AppAutomate.
- Builds and uploads apk to BrowserStack AppLive for manual testing.
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"
browserStackConfig {
username = "<browserstack_username>"
accessKey = "<browserstack_access_key>"
configFilePath = '<path/to/your/json/configFile>'
}
{
"devices": [
"Google Pixel-7.1"
],
"deviceLogs": true,
"networkLogs": true,
"project": "Awesome gradle plugin build",
"shards": {
"numberOfShards": 3
}
}
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
Builds, uploads and start Espresso tests on BrowserStack AppAutomate.
gradle clean execute${buildVariantName}TestsOnBrowserstack
For running tests on a project with no variants, you can simply run following command for uploading and running tests on debug apk:
gradle clean executeDebugTestsOnBrowserstack
And 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
username: String
accessKey: String
configFilePath: String # Filepath that has capabilities specifed to run the build
Note: username, accessKey and configFilePath are mandatory parameters. Visit https://www.browserstack.com/app-automate/espresso/get-started to get started with Espresso Tests on BrowserStack and also to know more about the above mentioned parameters.
Note: List of supported devices and be found here (basic auth required). For example :
curl -u "$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY" https://api-cloud.browserstack.com/app-automate/devices.json
Note: You can also set the values of username and accessKey in environment variables with names BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY, respectively. If you do this, then there is no need to set this parameters in browserStackConfig block.
- Build debug and test apks, as dependencies are declared on
assemble${buildvariantName}
andassemble${buildvariantName}AndroidTest
tasks. - Find the latest apks in the app directory recursively.
- Upload both the apks on BrowserStack AppAutomate platform.
- Execute Espresso test using the uploaded apps on the devices mentioned.
gradle clean upload${buildVariantName}ToBrowserstackAppLive
For running tests on a project with no variants, you can simply run following command for uploading debug apk:
gradle clean uploadDebugToBrowserstackAppLive
And for projects with productFlavors, replace ${buildVariantName} with your build variant name, for example if your productFlavor name is "phone" and you want to upload debug build type of this variant then command will be gradle clean uploadPhoneDebugToBrowserstackAppLive.
username: String
accessKey: String
Note: username and accessKey are mandatory parameters.
- Build debug and test apks, as dependencies are declared on
assemble${buildvariantName}
. - Find the latest apk in the app directory recursively.
- Upload the apk on BrowserStack AppLive platform.
Note: You can also set the values of username and accessKey in environment variables with names BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY, respectively. If you do this, then there is no need to set these parameters in browserStackConfig block.
Note: You can also see all possible tasks by running "gradle tasks -all"
Build the plugin
gradle clean build
To install the plugin into local maven repo
mvn install:install-file -Dfile=build/libs/browserstack-gradle-plugin-VERSION.jar -DgroupId=com.browserstack -DartifactId=gradle -Dversion=VERSION -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true