• This repository has been archived on 11/Feb/2022
  • Stars
    star
    357
  • Rank 119,149 (Top 3 %)
  • Language
    Groovy
  • License
    Other
  • Created over 10 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Handy commands for testing Android on CI

πŸ›‘ THIS REPOSITORY IS OFFICIALLY NO LONGER UNDER MAINTENANCE since 10/02/2022 πŸ›‘

gradle-android-command-plugin

Build License Bintray

Use gradle tasks to run specific adb commands.

Description

You can use this plugin to do things such as:

  • Find all devices attached and get basic info about them
  • Select the first one that complies with a custom rule
  • Install a specific APK from the available build types + flavours
  • Clear preferences or do something related to the APK to prepare for tests
  • Run monkey for that specific APK on that specific device
  • Uninstall the APK

This is particularly useful for CI servers but could be used to speed up development as well.

Adding to your project

To start using this library, add these lines to the build.gradle of your project:

apply plugin: 'com.android.application'
apply plugin: 'com.novoda.android-command'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.novoda:gradle-android-command-plugin:2.1.0'
    }
}

Simple usage

The plugin creates new tasks that you can use:

  • installDevice<Variant> [com.novoda.gradle.command.InstallDevice] - installs the app on a specific device.
  • uninstallDevice<Variant> [com.novoda.gradle.command.UninstallDevice] - uninstalls the app from a specific device.
  • run<Variant> [com.novoda.gradle.command.Run] - installs and launches the app on a specific device.
  • start<Variant> [com.novoda.gradle.command.Run] - launches an already installed app on a specific device.
  • stop<Variant> [com.novoda.gradle.command.Stop] - Forcibly stops the app on a specific device.
  • monkey<Variant> [com.novoda.gradle.command.Monkey] - installs and runs monkey on a specific device.
  • clearPrefs<Variant> [com.novoda.gradle.command.ClearPreferences] - clears app preferences on a specific device.
  • [enable|disable]SystemAnimations - Enables/Disables system animations on the device.
  • [enable|disable]DemoMode - Enables/Disables demo mode on the device.
  • com.novoda.gradle.command.Files - enables basic file copy via push and pull, wrapping the respective adb calls.

For advanced usage please take a look into the sample project build.gradle file.

Configuration

Command Extension

The plugin provides command extension under the official android extension for configuration.

command {
    // Optional adb and aapt path. By default, $ANDROID_HOME will be used 
    adb '~/full/path/to/adb'
    aapt '~/full/path/to/aapt'
    
    // Optional device id
    // By default, the first device will be used 
    // Can be overridden at any time with `-DdeviceId` command line argument
    // Can be a closure (for lazy evaluation) or just a String.
    deviceId = "DEVICE_SERIAL"
    // or
    deviceId {
        // some lazy script to evaluate deviceId 
    }
    
    // Categorize plugin tasks by task type or by variant names
    sortBySubtasks false
    
    // Additional methods to utilize in custom closures:
    List<Device> devices = devices()        // connected devices 
    List<String> deviceIds = deviceIds()    // connected device ids
    
    // Sub-extensions. More info below ⬇️
    monkey {
        // Configure monkey task
    }
    
    scripts {
        // named scripts for device input automation
    }
    
    demoMode {
        // configure Android Marshmallow's demo mode
    }
    
    install {
        // named install tasks with custom flags
    }
    
    start {
        // named run/start tasks
    }
}

Device class

Current connected devices can be retrieved via devices(). Here are the methods available on a Device object. These can be useful if used in other configurations. Examples can be found in the sample.

Integer sdkVersion()
String androidVersion()
String brand()
String model()
String manufacturer()
String screenDensity()
String country()
String language()
String timezone()
String deviceProperty(String key) // Possible keys: https://developer.android.com/studio/test/monkeyrunner/MonkeyDevice.html#table1

Input Scripting

The plugin provides an extension called scripts which allows to perform simple scripting automation. It wraps adb shell input tool.

Here is an example called autoLogin which will input the test username and password into the sample app.

scripts {
    autoLogin {
        execute {
          2.times {
              text 'bob'
              enter()
          }
          enter()
        }
    }
}

This config will create a gradle task called autoLogin. Running ./gradlew autoLogin will try to input bob then press enter. This will be done 2 times and then another enter will be pressed.

You may have a custom groovy closure to do scripting as you like. The following input methods are available:

text(String value)
tap(int x, int y)
swipe(int startX, int startY, int endX, int endY)
key(int code)
home()
back()
up()
down()
left()
right()
clear()
tab()
enter()
power()
unlock()

Demo Mode

[enable|disable]DemoMode tasks are create to control demo mode on Android Marshmallow (API level 23) devices.

By default these tasks setup the demo mode with most common used default values. And they can be controlled with demoMode DSL.

demoMode {
    battery {
        level '100'
        plugged 'false'
    }
    network {
        wifi 'show'
        level '4'
    }
    clock.hhmm '0810'
    notifications.visible 'false'
}

All possible values can be found in the official Android documentation

Install

installDevice<Variant> tasks are available by default just to install the app. The plugin also supports an install DSL to define custom installation tasks.

customFlags

Here is an extension called fromGooglePlay which will create installFromGooglePlay<Variant> tasks.

install {
    fromGooglePlay {
        description "Installs with flag Play Store"
        customFlags {
            ['-i', 'com.android.vending']
        }
    }
}

Note: customFlags also supports any custom Closure to be lazily evaluated.

More flags can be found in the install section of the official adb document.

Start

start<Variant> and run<Variant> tasks are available by default. Start tasks just start an already installed application. Run tasks first install the app before starting.

Just like the install DSL, it is possible to specify a device id. Doing this will create corresponding start and run tasks.

start {
    amazon {
        deviceId {
            def kindle = devices().find { it.brand() == 'Amazon' }
            if (!kindle) {
                throw new GroovyRuntimeException('No Amazon device found')
            }
            kindle.id
        }
    }
}

This configuration creates startAmazon<Variant> and runAmazon<Variant> tasks.

Snapshots

CI status Download from Bintray

Snapshot builds from develop are automatically deployed to a repository that is not synced with JCenter. To consume a snapshot build add an additional maven repo as follows:

repositories {
    maven {
        url 'https://dl.bintray.com/novoda-oss/snapshots/'
    }
}

You can find the latest snapshot version following this link.

Links

Here are a list of useful links:

  • We always welcome people to contribute new features or bug fixes, here is how
  • For more info on how start working on this project, see this wiki page
  • If you have a problem check the Issues Page first to see if we are working on it
  • For further usage or to delve more deeply checkout the Project Wiki
  • Looking for community help, browse the already asked Stack Overflow Questions or use the tag: support-android-command when posting a new question

More Repositories

1

android-demos

Examples of Android applications
Java
1,987
star
2

bintray-release

A helper for releasing from gradle up to bintray
Groovy
1,852
star
3

bonfire-firebase-sample

An app to discuss your favourite emojis. This is a sample app built with Firebase.
Java
544
star
4

merlin

Observes network connection status & gives callbacks
Java
543
star
5

spikes

Where ideas & concepts are born & incubated
Java
542
star
6

download-manager

A library that handles long-running downloads, handling the network interactions and retrying downloads automatically after failures
Java
484
star
7

gradle-static-analysis-plugin

Easy setup of static analysis tools for Android and Java projects.
Groovy
405
star
8

rxpresso

Easy Espresso UI testing for Android applications using RxJava.
Java
363
star
9

sqlite-provider

Extended SQLite functionality for Android
Java
302
star
10

no-player

Simplified Player wrapper for MediaPlayer and ExoPlayer
Java
180
star
11

simple-chrome-custom-tabs

Easy integration of Chrome Custom Tabs into your project. Just connect it to your activity, and navigate to the external website styling your tab as you wish.
Java
129
star
12

notils

Never again need a .utils. package yur scurvy sea dogs!
Java
122
star
13

gradle-build-properties-plugin

Keep your secrets secret. External build properties support for your Gradle scripts.
Groovy
110
star
14

ios-demos

Examples of ios applications http://www.novoda.com/blog
Swift
95
star
15

accessibilitools

UI tools to help make your Android app accessible.
Java
81
star
16

dojos

This is where the Novoda team do all their hacking
Java
76
star
17

simple-easy-xml-parser

Simple XML Parsing into Domain Objects
Java
69
star
18

sqlite-analyzer

Code generation for Java/Android database access.
Java
65
star
19

spritz

Spritz is an Android library to seamlessly trigger a Lottie animation
Java
62
star
20

espresso-support

Includes custom rules for testing Views in isolation and running tests with Google TalkBack enabled.
Java
60
star
21

novoda

Common things for all Novoda's open source projects
Java
37
star
22

view-pager-adapter

A simple implementation of PagerAdapter that supports Views.
Java
29
star
23

aosp.changelog.to

Generates a change log between different aosp tags. Based on the wonderful work of @alsutton
HTML
15
star
24

droidcon-booth

Novoda will be showing you CI in action at our Droidcon London booth!
Java
14
star
25

landing-strip

Your simple sliding viewpager tab strip: a landing strip without the fluff!
Java
13
star
26

dashboards

The dashboards we have running in our offices!
JavaScript
10
star
27

novoda.github.io

GitHub open source landing page
SCSS
10
star
28

drop-cap

Custom DropCap view without Spans
Java
10
star
29

public-mvn-repo

Novoda Public Maven Central Repository
7
star
30

github-reports

Github reports for a given organisation
Java
5
star
31

ncu

Novoda Craft University
3
star
32

peepz

Java
3
star
33

eslint-config-novoda

JavaScript
3
star
34

storage-path-finder

Library to perform the heavy lifting when attempting to find internal / external paths for primary and secondary storage.
Java
3
star
35

multiplatform-playground

A repository to play and learn about different multi-platform technologies
TypeScript
2
star
36

dashboard-plugins

A collection of plugins for the dashboard
JavaScript
2
star
37

react-native-workshop

JavaScript
1
star
38

dreams

A REST API using Stable Diffusion for Text to Image inference
Shell
1
star
39

github-slack-action

Simple Github Action to post a message in Slack
Shell
1
star