README.md
1# UIAutomator Snippet Example
2
3This example shows you how to create snippets that control the UI of a device
4across system and multiple app views using UIAutomator. Unlike Espresso-based
5UI automation, it does not require access to app source code.
6
7This snippet is written as a [standalone snippet](../ex1_standalone_app/README.md)
8and does not target another app. In particular, it doesn't need to target the
9app under test, so it doesn't need its classpath or to be signed with the same
10key.
11
12See the [Espresso snippet tutorial](../ex2_espresso/README.md) for more
13information about the app this example automates.
14
15## Running the example code
16
17This folder contains a fully working example of a snippet apk that uses
18UIAutomator to automate a simple app.
19
201. Compile the main app and automation. The main app of ex2 (espresso) is used
21 as the app to automate. Unlike espresso, the uiautomator test does not
22 depend on this apk and does not use its source or classpath, so you must
23 compile and install the app separately.
24
25 ./gradlew examples:ex2_espresso:assembleDebug examples:ex4_uiautomator:assembleDebug
26
271. Install the apks on your phone
28
29 adb install -r ./examples/ex2_espresso/build/outputs/apk/debug/ex2_espresso-main-debug.apk
30 adb install -r ./examples/ex4_uiautomator/build/outputs/apk/debug/ex4_uiautomator-debug.apk
31
321. Use `snippet_shell` from mobly to trigger `pushMainButton()`:
33
34 snippet_shell.py com.google.android.mobly.snippet.example4
35
36 >>> print(s.help())
37 Known methods:
38 pushMainButton(boolean) returns void // Pushes the main app button, and checks the label if this is the first time.
39 startMainActivity() returns void // Opens the main activity of the app
40 uiautomatorDump() returns String // Perform a UIAutomator dump
41
42 >>> s.startMainActivity()
43 >>> s.pushMainButton(True)
44
451. Press ctrl+d to exit the shell and terminate the app.
46