We learnt how to use UI Automator Viewer in PREVIOUS POST to locate and get properties details of android native software app's any element.Now we need to learn what are the different ways to locate elements of android software app and how to. UI Automator Viewer is a GUI tool that comes with Android SDK which is used to inspect UI components of an Android Application and view the properties associated. We can find it in Android SDK “tools” folder with file name 'uiautomatorviewer.bat' on Windows. This will open UI Automator Viewer window as displayed below. Sdkmanager -list if you see some local repositories are getting download, That means everything is.
In this document
- uiautomator API
The 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.
For more information on testing with the uiautomator
framework, see UI Testing.
Syntax
To run your testcases on the target device, you can use the adb shell
command to invoke the uiautomator
tool. The syntax is:
Here’s an example:
Command-line Options
Ui Automator Viewer Download
The following table describes the subcommands and options for uiautomator
.
Table 1. Command-line options for uiautomator
Subcommand | Option | Description |
---|---|---|
runtest | <JARS> | Required. The <JARS> 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. |
-c <CLASSES> | Required (API 17 or lower).The <CLASSES> argument is a list of test classes or test methods in <JARS> to run. Each class or method must be fully qualified with the package name, in one of these formats:
Note:This argument is not required for API 18 and higher. If not specified, all test cases in | |
--nohup | Runs the test to completion on the device even if its parent process is terminated (for example, if the device is disconnected). | |
-e <NAME> <VALUE> | Specify other name-value pairs to be passed to test classes. May be repeated. Note: The | |
-e debug [true|false] | Wait for debugger to connect before starting. | |
dump [file] | 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 /storage/sdcard0/window_dump.xml . | |
-e outputFormat simple | -s | Enables less verbose JUnit style output. | |
events | Prints out accessibility events to the console until the connection to the device is terminated |
uiautomator API
The uiautomator
API is bundled in the uiautomator.jar
file under the <android-sdk>/platforms/
directory. The API includes these key classes, interfaces, and exceptions that allow you to capture and manipulate UI components on the target app:
Download Ui Automator Viewer For Mac
Classes
Class | Description |
---|---|
com.android.uiautomator.core.UiCollection | 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. |
com.android.uiautomator.core.UiDevice | 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. |
com.android.uiautomator.core.UiObject | Represents a user interface (UI) element. |
com.android.uiautomator.core.UiScrollable | Provides support for searching for items in a scrollable UI container. |
com.android.uiautomator.core.UiSelector | Represents a query for one or more target UI elements on a device screen. |
com.android.uiautomator.core.Configurator | Allows you to set key parameters for running uiautomator tests. |
Interfaces
Interface | Description |
---|---|
com.android.uiautomator.core.UiWatcher | Represents a conditional watcher on the target device. |
com.android.uiautomator.testrunner.IAutomationSupport | Provides auxiliary support for running test cases. |
com.android.uiautomator.testrunner.UiAutomatorTestCase | Defines an environment for running multiple tests. All uiautomator test cases should extend this class. |
Exceptions
Ui Automator Viewer Free Download
Exception | Description |
---|---|
com.android.uiautomator.core.UiObjectNotFoundException | Indicates when a a UiSelector could not be matched to any UI element displayed. |