Search in sources :

Example 16 with UiObject2

use of android.support.test.uiautomator.UiObject2 in project android-testing-templates by googlesamples.

the class UiAutomatorTest method findViewPerformActionAndCheckAssertion.

@Test
public void findViewPerformActionAndCheckAssertion() {
    // Click on Button with content description
    final String btnContentDescription = InstrumentationRegistry.getTargetContext().getString(R.string.content_desc_hello_android_testing);
    mDevice.findObject(By.desc(btnContentDescription)).click();
    // Verify that correct text is displayed
    final String textViewResId = "text_view_rocks";
    UiObject2 androidRocksTextView = mDevice.wait(Until.findObject(By.res(TARGET_PACKAGE, textViewResId)), 500);
    assertThat(androidRocksTextView, notNullValue());
    final String androidTestingRocksText = InstrumentationRegistry.getTargetContext().getString(R.string.android_testing_rocks);
    assertThat(androidRocksTextView.getText(), is(equalTo(androidTestingRocksText)));
}
Also used : UiObject2(android.support.test.uiautomator.UiObject2) LargeTest(android.test.suitebuilder.annotation.LargeTest) Test(org.junit.Test)

Example 17 with UiObject2

use of android.support.test.uiautomator.UiObject2 in project platform_frameworks_base by android.

the class Utils method waitForActivity.

private static UiObject2 waitForActivity(Instrumentation instrumentation, BySelector selector) {
    UiDevice device = UiDevice.getInstance(instrumentation);
    UiObject2 window = device.wait(Until.findObject(selector), WAIT_FOR_ACTIVITY_TIMEOUT);
    if (window == null) {
        throw new RuntimeException(selector.toString() + " has not been started.");
    }
    // Get root object.
    while (window.getParent() != null) {
        window = window.getParent();
    }
    return window;
}
Also used : UiDevice(android.support.test.uiautomator.UiDevice) UiObject2(android.support.test.uiautomator.UiObject2)

Example 18 with UiObject2

use of android.support.test.uiautomator.UiObject2 in project platform_frameworks_base by android.

the class UiBot method assertWindowTitle.

public void assertWindowTitle(String expected) {
    // Turns out the title field on a window does not have
    // an id associated with it at runtime (which confuses the hell out of me)
    // In code we address this via "android.R.id.title".
    UiObject2 o = find(By.text(expected));
    // It's a bit of a conceit that we then *assert* that the title
    // is the value that we used to identify the UiObject2.
    // If the preceeding lookup fails, this'll choke with an NPE.
    // But given the issue described in the comment above, we're
    // going to do it anyway. Because we shouldn't be looking up
    // the uiobject by it's expected content :|
    assertEquals(expected, o.getText());
}
Also used : UiObject2(android.support.test.uiautomator.UiObject2)

Example 19 with UiObject2

use of android.support.test.uiautomator.UiObject2 in project platform_frameworks_base by android.

the class UiBot method findMenuWithName.

UiObject2 findMenuWithName(String label) {
    List<UiObject2> menuItems = mDevice.findObjects(By.clazz("android.widget.LinearLayout"));
    Iterator<UiObject2> it = menuItems.iterator();
    UiObject2 menuItem = null;
    while (it.hasNext()) {
        menuItem = it.next();
        UiObject2 text = menuItem.findObject(By.text(label));
        if (text != null) {
            break;
        }
    }
    return menuItem;
}
Also used : UiObject2(android.support.test.uiautomator.UiObject2)

Example 20 with UiObject2

use of android.support.test.uiautomator.UiObject2 in project android_frameworks_base by AOSPA.

the class UiBot method findMenuWithName.

UiObject2 findMenuWithName(String label) {
    List<UiObject2> menuItems = mDevice.findObjects(By.clazz("android.widget.LinearLayout"));
    Iterator<UiObject2> it = menuItems.iterator();
    UiObject2 menuItem = null;
    while (it.hasNext()) {
        menuItem = it.next();
        UiObject2 text = menuItem.findObject(By.text(label));
        if (text != null) {
            break;
        }
    }
    return menuItem;
}
Also used : UiObject2(android.support.test.uiautomator.UiObject2)

Aggregations

UiObject2 (android.support.test.uiautomator.UiObject2)29 Test (org.junit.Test)5 UiDevice (android.support.test.uiautomator.UiDevice)4 SdkSuppress (android.support.test.filters.SdkSuppress)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)1