blob: e478564aab444a562c74f2bc886daee18a0ad455 [file] [log] [blame] [view]
Alexander Dorokhineb1b8b502016-11-10 13:52:59 -08001# Getting Started with Snippets for Mobly
2
3Mobly Snippet Lib is a library for triggering device-side code from host-side
4[Mobly](http://github.com/google/mobly) tests. This tutorial teaches you how to
5use the snippet lib to trigger custom device-side actions.
6
Alexander Dorokhinea113c042016-12-05 15:07:55 -08007Note: Mobly and the snippet lib are not official Google products.
8
Alexander Dorokhineb1b8b502016-11-10 13:52:59 -08009
10## Prerequisites
Alexander Dorokhinea113c042016-12-05 15:07:55 -080011
12- These examples and tutorials assume basic familiarity with the Mobly
13 framework, so please follow the
14 [Mobly tutorial](http://github.com/google/mobly) before doing this one.
Alexander Dorokhineb1b8b502016-11-10 13:52:59 -080015- You should know how to create an Android app and build it with gradle. If
16 not, follow the
17 [Android app tutorial](https://developer.android.com/training/basics/firstapp/index.html).
18
Alexander Dorokhineb1b8b502016-11-10 13:52:59 -080019
Alexander Dorokhinea113c042016-12-05 15:07:55 -080020## Overview
Alexander Dorokhineb1b8b502016-11-10 13:52:59 -080021
Alexander Dorokhinea113c042016-12-05 15:07:55 -080022The Mobly Snippet Lib allows you to write Java methods that run on Android
23devices, and trigger the methods from inside a Mobly test case. The Java methods
24invoked this way are called `snippets`.
Alexander Dorokhineb1b8b502016-11-10 13:52:59 -080025
Alexander Dorokhinea113c042016-12-05 15:07:55 -080026The `snippet` code can either be written in its own standalone apk, or as a
27[product flavor](https://developer.android.com/studio/build/build-variants.html#product-flavors)
28of an existing apk. This allows you to write snippets that instrument or
29automate another app.
Alexander Dorokhineb1b8b502016-11-10 13:52:59 -080030
Alexander Dorokhinea113c042016-12-05 15:07:55 -080031Under the hood, the snippet lib starts a web server which listens for requests
32to trigger snippets. It locates the corrsponding methods by reflection, runs
33them, and returns results over the tcp socket. All common built-in variable
34types are supported as arguments.
Alexander Dorokhineb1b8b502016-11-10 13:52:59 -080035
Alexander Dorokhineb1b8b502016-11-10 13:52:59 -080036
Alexander Dorokhinea113c042016-12-05 15:07:55 -080037## Usage
Alexander Dorokhineb1b8b502016-11-10 13:52:59 -080038
Alexander Dorokhine0d913002016-12-08 11:15:59 -080039The [examples/](examples/) folder contains examples of how to use the
Alexander Dorokhinea113c042016-12-05 15:07:55 -080040mobly snippet lib along with detailed tutorials.
Alexander Dorokhineb1b8b502016-11-10 13:52:59 -080041
adorokhine787e6a72017-01-10 18:19:50 -080042* [ex1_standalone_app](examples/ex1_standalone_app): Basic example of a
43 snippet which is compiled into its own standalone apk.
44* [ex2_espresso](examples/ex2_espresso): Example of a snippet which
45 instruments a main app to drive its UI using
Alexander Dorokhinea113c042016-12-05 15:07:55 -080046 [Espresso](https://google.github.io/android-testing-support-library/docs/espresso/).