summaryrefslogtreecommitdiffstats
path: root/docs/html/tools/help/uiautomator/index.jd
blob: 38ba177c9c33b16a3e5960a266ad35597100b8b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
page.title=uiautomator
parent.title=Tools
parent.link=index.html
@jd:body

<div id="qv-wrapper">
  <div id="qv">
     <h2>In this document</h2>
  <ul>
     <li><a href="#syntax">Syntax</a></li>
     <li><a href="#options">Options</a></li>
     <lI><a href="#api">uiautomator API</a>
        <ul>
        <li><a href="#classes">Classes</a></li>
        <li><a href="#interfaces">Interfaces</a></li>
        <li><a href="#exceptions">Exceptions</a></li>
        </ul>
     </lI>
  </ul>
  </div>
</div>

<p>The {@code uiautomator} testing framework lets you test your user interface (UI) efficiently by creating automated functional UI testcases that can be run against your app on one or more devices.</p>
<p>For more information on testing with the {@code uiautomator} framework, see <a href="{@docRoot}tools/testing/testing_ui.html">UI Testing</a>.</p>

<h2 id="syntax">Syntax</h2>
<p>To run your testcases on the target device, you can use the {@code adb shell} command to invoke the {@code uiautomator} tool.  The syntax is:
<pre>
adb shell uiautomator runtest &lt;jar&gt; -c &lt;test_class_or_method&gt; [options]
</pre>
</p>
<p>Here’s an example:</p>
<pre>adb shell uiautomator runtest LaunchSettings.jar -c com.uia.example.my.LaunchSettings</pre>

<h2 id="options">Command-line Options</h2>
<p>The following table describes the subcommands and options for {@code uiautomator}.</p>

<p class="table-caption" id="table1">
<strong>Table 1.</strong> Command-line options for {@code uiautomator}</p>
<table>
<tr>
  <th>Subcommand</th>
  <th>Option</th>
  <th>Description</th>
</tr>

<tr>
<td rowspan="6"><code>runtest</code></td>
<td><nobr>{@code &lt;jar&gt;}</nobr></td>
<td><strong>Required</strong>. The {@code &lt;jar&gt;} argument is the name of one or more JAR files that you deployed to the target device which contain your uiautomator testcases. You can list more than one JAR file by using a space as a separator.</td>
</tr>

<tr>
<td><nobr><code>-c &lt;test_class_or_method&gt; </code></nobr></td>
<td><strong>Required</strong>. The {@code &lt;test_class_or_method&gt;} argument is a list of one or more specific test classes or test methods from the JARs that you want {@code uiautomator} to run. <p>Each class or method must be fully qualified with the package name, in one of these formats:
<ul>
<li>{@code package_name.class_name}</li>
<li>{@code package_name.class_name#method_name}</li>
</ul>
You can list multiple classes or methods by using a space as a separator.</p></td>
</tr>

<tr>
<td><nobr><code>--nohup</code></nobr></td>
<td>Runs the test to completion on the device even if its parent process is terminated (for example, if the device is disconnected).</td>
</tr>

<tr>
<td><nobr><code>-e &lt;NAME&gt; &lt;VALUE&gt;</code></nobr></td>
<td><p>Specify other name-value pairs to be passed to test classes. May be repeated.</p><p class="note"><strong>Note: </strong>The {@code -e} options cannot be combined; you must prefix each option with a separate {@code -e} flag. </p></td>
</tr>

<tr>
<td><nobr><code>-e debug [true|false]</code></nobr></td>
<td>Wait for debugger to connect before starting.</td>
</tr>

<tr>
<td><nobr><code>-e runner [CLASS]</code></nobr></td>
<td>Use the specified test runner class instead. If unspecified, the {@code uiautomator} framework’s  default runner will be used.</td>
</tr>

<tr>
<td><code>dump</code></td>
<td><code>[file]</code></td>
<td>Generate an XML file with a dump of the current UI hierarchy. If a filepath is not specified, by default, the generated dump file is stored on the device in this location {@code /storage/sdcard0/window_dump.xml}.</td>
</tr>

<tr>
<td><code>events</code></td>
<td>&nbsp;</td>
<td>Prints out accessibility events to the console until the connection to the device is terminated</td>
</tr>
</table>

<h2 id="api">uiautomator API</h2>
<p>The {@code uiautomator} API is bundled in the {@code uiautomator.jar} file under the {@code &lt;android-sdk&gt;/platforms/} directory.  The API includes these key classes, interfaces, and exceptions that allow you to capture and manipulate UI components on the target app:</p>

<h3 id="classes">Classes</h3>
<table>
<tr>
  <th>Class</th>
  <th>Description</th>
</tr>

<tr>
<td><nobr><a href="{@docRoot}tools/help/uiautomator/UiCollection.html">{@code com.android.uiautomator.core.UiCollection}</a></nobr></td>
<td>Used to enumerate a container's user interface (UI) elements for the purpose of counting, or targeting a sub elements by a child's text or description.</td>
</tr>

<tr>
<td><nobr><a href="{@docRoot}tools/help/uiautomator/UiDevice.html">{@code com.android.uiautomator.core.UiDevice}</a></nobr></td>
<td>Provides access to state information about the device. You can also use this class to simulate user actions on the device, such as pressing the d-pad hardware button or pressing the Home and Menu buttons.</td>
</tr>

<tr>
<td><nobr><a href="{@docRoot}tools/help/uiautomator/UiObject.html">{@code com.android.uiautomator.core.UiObject}</a></nobr></td>
<td>Represents a user interface (UI) element.</td>
</tr>

<tr>
<td><nobr><a href="{@docRoot}tools/help/uiautomator/UiScrollable.html">{@code com.android.uiautomator.core.UiScrollable}</a></nobr></td>
<td>Provides support for searching for items in a scrollable UI container.</td>
</tr>

<tr>
<td><nobr><a href="{@docRoot}tools/help/uiautomator/UiSelector.html">{@code com.android.uiautomator.core.UiSelector}</a></nobr></td>
<td>Represents a query for one or more target UI elements on a device screen. </td>
</tr>

</table>

<h3 id="interfaces">Interfaces</h3>

<table>
<tr>
  <th>Interface</th>
  <th>Description</th>
</tr>

<tr>
<td><nobr><a href="{@docRoot}tools/help/uiautomator/UiWatcher.html">{@code com.android.uiautomator.core.UiWatcher}</a></nobr></td>
<td>Represents a conditional watcher on the target device.</td>
</tr>

<tr>
<td><nobr><a href="{@docRoot}tools/help/uiautomator/IAutomationSupport.html">{@code com.android.uiautomator.testrunner.IAutomationSupport}</a></nobr></td>
<td>Provides auxiliary support for running test cases.</td>
</tr>

<tr>
<td><nobr><a href="{@docRoot}tools/help/uiautomator/UiAutomatorTestCase.html">{@code com.android.uiautomator.testrunner.UiAutomatorTestCase}</a></nobr></td>
<td>Defines an environment for running multiple tests. All {@code uiautomator} test cases should extend this class.</td>
</tr>

</table>

<h3 id="exceptions">Exceptions</h3>

<table>
<tr>
  <th>Exception</th>
  <th>Description</th>
</tr>

<tr>
<td><nobr><a href="{@docRoot}tools/help/uiautomator/UiObjectNotFoundException.html">{@code com.android.uiautomator.core.UiObjectNotFoundException}</a></nobr></td>
<td>Indicates when a a <a href="{@docRoot}tools/help/uiautomator/UiSelector.html">{@code UiSelector}</a> could not be matched to any UI element displayed.</td>
</tr>

</table>