blob: 38ba177c9c33b16a3e5960a266ad35597100b8b4 [file] [log] [blame]
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>Heres 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} frameworks 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>