Support Center

Using Gradle Plugin with Testdroid Cloud Devices

Last Updated: Oct 19, 2016 09:07AM CEST

In case you are using Gradle Plugin with Android Studio (or some other development tool/environment), you can use our Testdroid Gradle Plugin that takes care of automatically uploading your latest builds into Testdroid Cloud.

However, it is worth mentioning that the Android Studio isn't the only development environment where Gradle is used a lot and integrated as a default build system. For example, many of Testdroid users are also using continuous integration environments/tools (e.g. TeamCity) that integrate nicely with Gradle and naturally these instructions are very relevant for them as well.
 

Step #1: Install and Configure Testdroid Gradle Plugin

The installation of any Gradle compatible plugin is very easy and straightforward. In fact, all you need to do is to add few configuration lines in your gradle.build file and the system will take care of the rest. When doing this, you typically have two different gradle.build files - one specific for Project and one for Module. To make it easier to adopt these configurations for variety of different projects, you should modify the Module specific gradle.build file.

This file can be further modified with different setups for Testdroid Cloud, but the basic three required configurations are as follows: First of all, you need apply the Testdroid plugin:
 

apply plugin: 'testdroid'

Applying a plugin to the project allows the plugin to extend the project's capabilities. For example, this allows adding tasks to projects (compile and upload the latest APK to Testdroid Cloud).

Next one is to configure your Testdroid credentials and Testdroid Cloud setups:

testdroid {
    username 'username@email.com'
    password 'password'
    deviceGroup 'MyTestDevices'
    mode "FULL_RUN"
}

Place your login credentials for username and password. Also, set up the device group that against you want to run your APK. For example, MyTestDevices is the demo user specific device group (not available as a default device group) and includes 8 pre-selected devices. We'll take a look at this device group later in this post.

For the next thing, set dependency for classpath and in this case it should be com.testdroid:gradle:1.3.0. Our Gradle plugin naturally evolves and develops over time, so please check the latest version from here. For the dependency configuration, please use the following line as part of the buildscript -> dependencies:

buildscript {

    repositories {
        ...
    }

    dependencies {
        classpath 'com.testdroid:gradle:1.3.0'
    }
}

Congratulations! You've now successfully configured Testdroid Cloud devices to your Gradle build environment and all your builds can be nicely pushed to our devices for testing.
 

Step #2: Running Tests on Testdroid Cloud Devices

With above configuration your application and possible instrumentation package are uploaded automatically into Testdroid Cloud and test run is launched using device from group 'MyTestDevices'. In case you want to add more advanced options for test run creation, execution and so on, please check the 'Bonus' chapter at the end of this post.

There are basically two quick ways to get your app (and instrumentation app) up and running on Testdroid Cloud. You can either do it from command line by going to a project specific path (e.g. /Users/vvhelppi/AndroidStudioProjects/MyApplication2) and executing the following command:

./gradlew testdroidUpload

or using the Android Studio's Gradle Projects view and double-clicking testdroidUpload under Tasks (app -> verification):

Now, the project will be compiled, all dependencies will be fetched (done only once on the first time) and app + possible instrumentation package will be uploaded to Testdroid Cloud. The Run log should look something like this:

Step #3: All Done - Let's Review the Results!

In case you are new to Testdroid Cloud, take a look at this guide to walk you through some basic things and steps how to use it. With Testdroid Cloud, you get all details of your test run, such as logs, screenshots, performance stats and much more - and all this are conveniently shown in our easy-to-use UI.

In example above, we ran empty Android Studio app project on 8 devices. The Test Execution time is minuscule as there isn't much logic in empty app. Also, the App Crawler run targeted for this sort of app basically checks whether app can be appropriately launched and stopped - and use those as test cases.

Bonus! Advanced Configuration Parameters

To get all out of this awesome "development tool - real device" combination you might want to consider further modifying and configuring your test runs. We've done this easy as part of the gradle.build configuration illustrated above, and the following additional parameters can be used:

testdroid {
    username  "account@email.com" // Username
    password "password"   // Password
    deviceGroup "MyTestDevices"   // Device group for execution

    cloudUrl = 'https://cloud.testdroid.com' // Optional - Used for PrivateCloud configs
    projectName "Project 1"       // Optional - Default: create a new project
    mode "FULL_RUN"     // FULL_RUN / APP_CRAWLER / UI_AUTOMATOR
    testRunName "Custom test run name"  // Optional - default: build variant name

    deviceLanguageCode "en-US"  // Optional - locale <ISO 63>_<ISO 3166> default: en-US

    hookUrl "http://localhost:9080" // Optional - call back URL after test run has finished

    scheduler "PARALLEL"  // Optional - PARALLEL or SERIAL default: PARALLEL

    testScreenshotDir = "/sdcard/abc" // Optional - custom screenshot folder 

    // AppCrawler configuration - set application credentials
    appCrawlerConfig{
        applicationPassword = "appPassword2"
        applicationUserName = "appUsername2"
    }

    // Optional - Custom settings for test execution
    fullRunConfig {
        instrumentationRunner =  "com.android.testRunner"
        withAnnotation = "com.my.annotation"
        withOutAnnotation = "com.my.not.annotation"
        limitationType = "CLASS"
        limitationValue = "foo.bar"
        instrumentationAPKPath = "/tmp/mytestapp.apk"     
    }

    // Optional
    uiAutomatorTestConfig {
        uiAutomatorTestClasses = "foo.class"
        uiAutomatorJarPath = "tmp/uitests.jar"
    }
}

Contact Us

support@bitbar.com
http://assets2.desk.com/
false
bitbar
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete