Writing more complex tests using the UIAutomatorViewer

suggest change

In order to enable writing more complex UI tests the UIAutomatorViewer is needed. The tool located at /tools/ makes a fullscreen screenshot including the layouts of the currently displayed views. See the subsequent picture to get an idea of what is shown:

For the UI tests we are looking for resource-id, content-desc or something else to identify a view and use it inside our tests.

The uiautomatorviewer is executed via terminal.

If we now for instance want to click on the applications button and then open some app and swipe around, this is how the test method can look like:

public void testOpenMyApp() throws Exception {
    // wake up your device

    // switch to launcher (hide the previous application, if some is opened)

    // enter applications menu (timeout=200ms)
    device.wait(Until.hasObject(By.desc(("Apps"))), 200);
    UiObject2 appsButton = device.findObject(By.desc(("Apps")));

    // enter some application (timeout=200ms)
    device.wait(Until.hasObject(By.desc(("MyApplication"))), 200);
    UiObject2 someAppIcon = device.findObject(By.desc(("MyApplication")));

    // do a swipe (steps=20 is 0.1 sec.)
    device.swipe(200, 1200, 1300, 1200, 20);

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents