Search in sources :

Example 1 with BySelector

use of android.support.test.uiautomator.BySelector in project quickstart-android by firebase.

the class UiAutomatorTest method testLaunchDialog.

@Test
public void testLaunchDialog() {
    // Floating action button
    BySelector fabSelector = By.res(APP_PACKAGE, "invite_button");
    // Click floating action button
    Assert.assertTrue(mDevice.wait(Until.hasObject(fabSelector), UI_TIMEOUT));
    mDevice.findObject(fabSelector).click();
    // Radio button in the account picker dialog
    BySelector firstAccountSelector = By.clazz(CLASS_CHECKED_TEXT_VIEW);
    // Wait for account picker (may not appear)
    if (mDevice.wait(Until.hasObject(firstAccountSelector), UI_TIMEOUT)) {
        // Click first account
        mDevice.findObjects(firstAccountSelector).get(0).click();
        // Button with the text "OK" (enabled)
        BySelector okButtonSelector = By.clazz(CLASS_BUTTON).text("OK").enabled(true);
        // Click OK on account picker
        Assert.assertTrue(mDevice.wait(Until.hasObject(okButtonSelector), UI_TIMEOUT));
        mDevice.findObject(okButtonSelector).click();
    }
    // Check that we can see the title and message
    String titleText = mContext.getString(R.string.invitation_title);
    String messageText = mContext.getString(R.string.invitation_message);
    BySelector titleTextSelector = By.text(titleText);
    BySelector messageTextSelector = By.text(messageText);
    assertTrue(mDevice.wait(Until.hasObject(titleTextSelector), UI_TIMEOUT));
    assertTrue(mDevice.wait(Until.hasObject(messageTextSelector), UI_TIMEOUT));
    // Back out of the dialog
    mDevice.pressBack();
}
Also used : BySelector(android.support.test.uiautomator.BySelector) Test(org.junit.Test)

Example 2 with BySelector

use of android.support.test.uiautomator.BySelector in project android_packages_apps_Settings by LineageOS.

the class ExternalSourcesSettingsTest method testManageExternalSourcesList.

@Test
public void testManageExternalSourcesList() throws Exception {
    final String testAppLabel = getApplicationLabel(mPackageName);
    mContext.startActivity(createManageExternalSourcesListIntent());
    final BySelector preferenceListSelector = By.clazz(ListView.class).res("android:id/list");
    final UiObject2 preferenceList = mUiDevice.wait(Until.findObject(preferenceListSelector), START_ACTIVITY_TIMEOUT);
    assertNotNull("App list not shown", preferenceList);
    final BySelector appLabelTextViewSelector = By.clazz(TextView.class).res("android:id/title").text(testAppLabel);
    List<UiObject2> listOfMatchingTextViews;
    do {
        listOfMatchingTextViews = preferenceList.findObjects(appLabelTextViewSelector);
    // assuming the number of profiles will be sufficiently small so that all the entries
    // for the same package will fit in one screen at some time during the scroll.
    } while (listOfMatchingTextViews.size() != mProfiles.size() && preferenceList.scroll(Direction.DOWN, 0.2f));
    assertEquals("Test app not listed for each profile", mProfiles.size(), listOfMatchingTextViews.size());
    for (UiObject2 matchingObject : listOfMatchingTextViews) {
        matchingObject.click();
        findAndVerifySwitchState(true);
        mUiDevice.pressBack();
    }
}
Also used : BySelector(android.support.test.uiautomator.BySelector) ListView(android.widget.ListView) UiObject2(android.support.test.uiautomator.UiObject2) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 3 with BySelector

use of android.support.test.uiautomator.BySelector in project android_packages_apps_Settings by LineageOS.

the class ExternalSourcesSettingsTest method findAndVerifySwitchState.

private UiObject2 findAndVerifySwitchState(boolean checked) {
    final BySelector switchSelector = By.clazz(Switch.class).res("android:id/switch_widget");
    final UiObject2 switchPref = mUiDevice.wait(Until.findObject(switchSelector), START_ACTIVITY_TIMEOUT);
    assertNotNull("Switch not shown", switchPref);
    assertTrue("Switch in invalid state", switchPref.isChecked() == checked);
    return switchPref;
}
Also used : BySelector(android.support.test.uiautomator.BySelector) Switch(android.widget.Switch) UiObject2(android.support.test.uiautomator.UiObject2)

Example 4 with BySelector

use of android.support.test.uiautomator.BySelector in project android_packages_apps_Settings by omnirom.

the class ExternalSourcesSettingsTest method testManageExternalSourcesList.

@Test
public void testManageExternalSourcesList() throws Exception {
    final String testAppLabel = getApplicationLabel(mPackageName);
    mContext.startActivity(createManageExternalSourcesListIntent());
    final BySelector preferenceListSelector = By.clazz(ListView.class).res("android:id/list");
    final UiObject2 preferenceList = mUiDevice.wait(Until.findObject(preferenceListSelector), START_ACTIVITY_TIMEOUT);
    assertNotNull("App list not shown", preferenceList);
    final BySelector appLabelTextViewSelector = By.clazz(TextView.class).res("android:id/title").text(testAppLabel);
    List<UiObject2> listOfMatchingTextViews;
    do {
        listOfMatchingTextViews = preferenceList.findObjects(appLabelTextViewSelector);
    // assuming the number of profiles will be sufficiently small so that all the entries
    // for the same package will fit in one screen at some time during the scroll.
    } while (listOfMatchingTextViews.size() != mProfiles.size() && preferenceList.scroll(Direction.DOWN, 0.2f));
    assertEquals("Test app not listed for each profile", mProfiles.size(), listOfMatchingTextViews.size());
    for (UiObject2 matchingObject : listOfMatchingTextViews) {
        matchingObject.click();
        findAndVerifySwitchState(true);
        mUiDevice.pressBack();
    }
}
Also used : BySelector(android.support.test.uiautomator.BySelector) ListView(android.widget.ListView) UiObject2(android.support.test.uiautomator.UiObject2) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest)

Example 5 with BySelector

use of android.support.test.uiautomator.BySelector in project android_packages_apps_Settings by omnirom.

the class ExternalSourcesSettingsTest method findAndVerifySwitchState.

private UiObject2 findAndVerifySwitchState(boolean checked) {
    final BySelector switchSelector = By.clazz(Switch.class).res("android:id/switch_widget");
    final UiObject2 switchPref = mUiDevice.wait(Until.findObject(switchSelector), START_ACTIVITY_TIMEOUT);
    assertNotNull("Switch not shown", switchPref);
    assertTrue("Switch in invalid state", switchPref.isChecked() == checked);
    return switchPref;
}
Also used : BySelector(android.support.test.uiautomator.BySelector) Switch(android.widget.Switch) UiObject2(android.support.test.uiautomator.UiObject2)

Aggregations

BySelector (android.support.test.uiautomator.BySelector)37 UiObject2 (android.support.test.uiautomator.UiObject2)18 MediumTest (android.test.suitebuilder.annotation.MediumTest)10 Suppress (android.test.suitebuilder.annotation.Suppress)8 ListView (android.widget.ListView)8 Test (org.junit.Test)8 Switch (android.widget.Switch)7 LargeTest (android.support.test.filters.LargeTest)6 UiSelector (android.support.test.uiautomator.UiSelector)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)1