Search in sources :

Example 21 with BySelector

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

the class ZonePickerSettingsTest method testSelectTimeZone.

private void testSelectTimeZone(String region, String timezone, String expectedTimeZoneOffset, String expectedTimeZoneId, boolean assumeOneTimeZoneInRegion) throws Exception {
    mHelper.setIntSetting(SettingsType.GLOBAL, Settings.Global.AUTO_TIME_ZONE, 0);
    SettingsHelper.launchSettingsPage(InstrumentationRegistry.getContext(), Settings.ACTION_DATE_SETTINGS);
    UiObject2 selectTimeZone = wait(SELECTOR_SELECT_TIME_ZONE);
    assertTrue(selectTimeZone.isEnabled());
    selectTimeZone.click();
    wait(By.text("Region")).click();
    // Speed-up the test by searching with the first 2 characters of the region name
    wait(By.res("android", "search_src_text")).setText(region.substring(0, 2));
    // Select region in the list
    selectItemInList(new UiSelector().textContains(region)).click();
    // Only select time zone explicitly if there are more than one time zones in a region
    if (!assumeOneTimeZoneInRegion) {
        wait(By.text("Time zone"));
        selectItemInList(new UiSelector().textContains(timezone)).click();
    }
    mDevice.pressBack();
    // The select button should include the GMT offset in the summary
    BySelector summarySelector = By.res("android:id/summary");
    UiObject2 selectedTimeZone = selectTimeZone.findObject(summarySelector);
    assertUiObjectFound(selectedTimeZone, summarySelector);
    assertTrue("Expect " + expectedTimeZoneOffset + " is shown for " + timezone, selectedTimeZone.getText().startsWith(expectedTimeZoneOffset));
    waitAndAssertTimeGetDefault(expectedTimeZoneId);
    assertEquals("Time zone change in Settings should update persist.sys.timezone", expectedTimeZoneId, SystemProperties.get("persist.sys.timezone"));
}
Also used : BySelector(android.support.test.uiautomator.BySelector) UiSelector(android.support.test.uiautomator.UiSelector) UiObject2(android.support.test.uiautomator.UiObject2)

Example 22 with BySelector

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

the class ExternalSourcesSettingsTest method testAppDetailScreenForAppOp.

private void testAppDetailScreenForAppOp(int appOpMode, int userId) throws Exception {
    final String testAppLabel = getApplicationLabel(mPackageName);
    final BySelector appDetailTitleSelector = By.clazz(TextView.class).res("com.android.settings:id/app_detail_title").text(testAppLabel);
    mAppOpsManager.setMode(OP_REQUEST_INSTALL_PACKAGES, mPackageManager.getPackageUidAsUser(mPackageName, userId), mPackageName, appOpMode);
    mContext.startActivityAsUser(createManageExternalSourcesAppIntent(mPackageName), UserHandle.of(userId));
    mUiDevice.wait(Until.findObject(appDetailTitleSelector), START_ACTIVITY_TIMEOUT);
    findAndVerifySwitchState(appOpMode == MODE_ALLOWED || appOpMode == MODE_DEFAULT);
    mUiDevice.pressBack();
}
Also used : BySelector(android.support.test.uiautomator.BySelector)

Example 23 with BySelector

use of android.support.test.uiautomator.BySelector in project google-services by googlesamples.

the class UiAutomatorTest method disconnectTest.

/**
 * Click the disconnect button, check the app is in the signed-out state.
 */
private void disconnectTest() {
    // Disconnect button (enabled)
    String disconnectText = mContext.getString(R.string.disconnect);
    BySelector disconnectSelector = By.clazz(CLASS_BUTTON).text(disconnectText).enabled(true);
    // Click disconnect button
    assertTrue(mDevice.wait(Until.hasObject(disconnectSelector), UI_TIMEOUT));
    mDevice.findObject(disconnectSelector).click();
    // Check that we get to signed-out state
    String signedOutText = mContext.getString(R.string.signed_out);
    BySelector signedOutTextSelector = By.text(signedOutText);
    assertTrue(mDevice.wait(Until.hasObject(signedOutTextSelector), UI_TIMEOUT));
}
Also used : BySelector(android.support.test.uiautomator.BySelector)

Example 24 with BySelector

use of android.support.test.uiautomator.BySelector in project google-services by googlesamples.

the class UiAutomatorTest method signInTest.

/**
 * Click sign-in button, select account at account selector, accept consent screen, and
 * check that in the end the app is in the signed-in state.
 */
private void signInTest() {
    // Sign-in button (enabled)
    BySelector signInButtonSelector = By.clazz(CLASS_BUTTON).textContains("Sign in").enabled(true);
    // Click Sign-in button (must be enabled)
    assertTrue(mDevice.wait(Until.hasObject(signInButtonSelector), UI_TIMEOUT));
    mDevice.findObject(signInButtonSelector).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
        assertTrue(mDevice.wait(Until.hasObject(okButtonSelector), UI_TIMEOUT));
        mDevice.findObject(okButtonSelector).click();
    }
    // The Google Play Services consent screen accept button
    BySelector acceptButtonSelector = By.res(GMS_PACKAGE, "accept_button");
    // Accept consent screen and click OK button (this also may not appear)
    if (mDevice.wait(Until.hasObject(acceptButtonSelector), UI_TIMEOUT)) {
        mDevice.findObject(acceptButtonSelector).click();
    }
    // Check that the UI shows signed-in state
    assertTrue(isSignedIn());
}
Also used : BySelector(android.support.test.uiautomator.BySelector)

Example 25 with BySelector

use of android.support.test.uiautomator.BySelector in project google-services by googlesamples.

the class UiAutomatorTest method isSignedIn.

/**
 * Checks the UI for text containing "Signed in" to determine if the user is signed in.
 */
private boolean isSignedIn() {
    // Wait until we have an enabled button on screen
    mDevice.wait(Until.hasObject(By.clazz(CLASS_BUTTON).enabled(true)), UI_TIMEOUT);
    String signedInText = mContext.getString(R.string.signed_in_fmt, "");
    BySelector signedInTextSelector = By.textContains(signedInText);
    return mDevice.wait(Until.hasObject(signedInTextSelector), UI_TIMEOUT);
}
Also used : BySelector(android.support.test.uiautomator.BySelector)

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