Search in sources :

Example 86 with UiSelector

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

the class UserSettingsTest method launchUserSettings.

private void launchUserSettings() throws Exception {
    launchSettings();
    final UiScrollable settings = new UiScrollable(new UiSelector().packageName(mTargetPackage).scrollable(true));
    final String titleUsersAndAccounts = USER_AND_ACCOUNTS;
    settings.scrollTextIntoView(titleUsersAndAccounts);
    mDevice.findObject(new UiSelector().text(titleUsersAndAccounts)).click();
    mDevice.findObject(new UiSelector().text(USERS)).click();
}
Also used : UiSelector(android.support.test.uiautomator.UiSelector) UiScrollable(android.support.test.uiautomator.UiScrollable)

Example 87 with UiSelector

use of android.support.test.uiautomator.UiSelector in project Rocket by mozilla-tw.

the class DefaultBrowserTest method changeDefaultBrowser_prefSwitched.

@Test
public void changeDefaultBrowser_prefSwitched() {
    // Start MainActivity
    mainActivity.launchActivity(new Intent());
    final MainActivity activity = mainActivity.getActivity();
    if (activity == null) {
        throw new AssertionError("Could start activity");
    }
    final String prefName = activity.getString(R.string.pref_key_default_browser);
    // Click on the menu item
    onView(allOf(withId(R.id.btn_menu), withParent(withId(R.id.home_screen_menu)))).perform(click());
    // Click on Settings
    onView(withId(R.id.menu_preferences)).perform(click());
    // Click on "Default Browser" setting, this will brings up the Android system setting
    onData(allOf(is(instanceOf(Preference.class)), withKey(prefName))).onChildView(withClassName(is(Switch.class.getName()))).perform(click());
    // Open default browser setting
    final UiObject allAppsButton = uiDevice.findObject(new UiSelector().text(SETTING_DEFAULT_BROWSER));
    try {
        allAppsButton.click();
    } catch (UiObjectNotFoundException e) {
        throw new AssertionError("Could find the setting", e);
    }
    // Choose our testing app
    final UiObject browserCandidate = uiDevice.findObject(new UiSelector().text(activity.getString(R.string.app_name)));
    try {
        browserCandidate.click();
    } catch (UiObjectNotFoundException e) {
        throw new AssertionError("Could find the app in default browser", e);
    }
    // Now launch Rocket's setting activity
    settingsActivity.launchActivity(new Intent());
    // Check if the "Default Browser" pref is correctly displayed (switch checked)
    onData(allOf(is(instanceOf(Preference.class)), withKey(prefName))).onChildView(withClassName(is(Switch.class.getName()))).check(matches(isChecked()));
}
Also used : UiObject(android.support.test.uiautomator.UiObject) Preference(android.preference.Preference) UiSelector(android.support.test.uiautomator.UiSelector) Intent(android.content.Intent) UiObjectNotFoundException(android.support.test.uiautomator.UiObjectNotFoundException) Test(org.junit.Test)

Example 88 with UiSelector

use of android.support.test.uiautomator.UiSelector in project focus-android by mozilla-mobile.

the class TypicalUseScenarioTest method TypicalUseTest.

@Test
public void TypicalUseTest() throws InterruptedException, UiObjectNotFoundException {
    UiObject blockAdTrackerEntry = TestHelper.settingsList.getChild(new UiSelector().className("android.widget.LinearLayout").instance(3));
    UiObject blockAdTrackerValue = blockAdTrackerEntry.getChild(new UiSelector().className("android.widget.Switch"));
    UiObject blockAnalyticTrackerEntry = TestHelper.settingsList.getChild(new UiSelector().className("android.widget.LinearLayout").instance(5));
    UiObject blockAnalyticTrackerValue = blockAnalyticTrackerEntry.getChild(new UiSelector().className("android.widget.Switch"));
    UiObject blockSocialTrackerEntry = TestHelper.settingsList.getChild(new UiSelector().className("android.widget.LinearLayout").instance(7));
    UiObject blockSocialTrackerValue = blockSocialTrackerEntry.getChild(new UiSelector().className("android.widget.Switch"));
    // Let's search for something
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("mozilla focus");
    TestHelper.hint.waitForExists(waitingTime);
    assertTrue(TestHelper.hint.getText().equals("Search for mozilla focus"));
    TestHelper.hint.click();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));
    assertTrue(TestHelper.browserURLbar.getText().contains("mozilla"));
    assertTrue(TestHelper.browserURLbar.getText().contains("focus"));
    // Let's delete my history
    TestHelper.floatingEraseButton.perform(click());
    TestHelper.erasedMsg.waitForExists(waitingTime);
    assertTrue(TestHelper.erasedMsg.exists());
    TestHelper.erasedMsg.waitUntilGone(waitingTime);
    // Let's go to an actual URL which is https://
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("https://www.google.com");
    TestHelper.hint.waitForExists(waitingTime);
    assertTrue(TestHelper.hint.getText().equals("Search for https://www.google.com"));
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));
    assertTrue(TestHelper.browserURLbar.getText().contains("https://www.google"));
    // The DOM for lockicon is not detected consistenly, even when it is visible.
    // Disabling the check
    // TestHelper.lockIcon.waitForExists(waitingTime * 2);
    // assertTrue (TestHelper.lockIcon.isEnabled());
    // Let's delete my history again
    TestHelper.floatingEraseButton.perform(click());
    TestHelper.erasedMsg.waitForExists(waitingTime);
    assertTrue(TestHelper.erasedMsg.exists());
    TestHelper.erasedMsg.waitUntilGone(waitingTime);
    // Let's go to an actual URL which is http://
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("http://www.example.com");
    TestHelper.hint.waitForExists(waitingTime);
    assertTrue(TestHelper.hint.getText().equals("Search for http://www.example.com"));
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));
    assertTrue(TestHelper.browserURLbar.getText().contains("http://www.example.com"));
    assertTrue(!TestHelper.lockIcon.exists());
    /* Go to settings and disable everything */
    TestHelper.menuButton.perform(click());
    TestHelper.browserViewSettingsMenuItem.click();
    TestHelper.settingsHeading.waitForExists(waitingTime);
    blockAdTrackerEntry.click();
    blockAnalyticTrackerEntry.click();
    blockSocialTrackerEntry.click();
    assertTrue(blockAdTrackerValue.getText().equals("OFF"));
    assertTrue(blockAnalyticTrackerValue.getText().equals("OFF"));
    assertTrue(blockSocialTrackerValue.getText().equals("OFF"));
    blockAdTrackerEntry.click();
    blockAnalyticTrackerEntry.click();
    blockSocialTrackerEntry.click();
    // Back to the webpage
    TestHelper.pressBackKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));
    assertTrue(TestHelper.browserURLbar.getText().contains("http://www.example.com"));
    assertTrue(!TestHelper.lockIcon.exists());
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) Test(org.junit.Test)

Example 89 with UiSelector

use of android.support.test.uiautomator.UiSelector in project focus-android by mozilla-mobile.

the class TestHelper method waitForWebSiteTitleLoad.

public static void waitForWebSiteTitleLoad() {
    UiObject titleMsg = mDevice.findObject(new UiSelector().description("focus test page").enabled(true));
    assertTrue(webView.waitForExists(waitingTime));
    Assert.assertTrue("Website title loaded", titleMsg.waitForExists(waitingTime));
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector)

Example 90 with UiSelector

use of android.support.test.uiautomator.UiSelector in project focus-android by mozilla-mobile.

the class LocalSessionStorageTest method testLocalAndSessionStorageIsWrittenAndRemoved.

/**
 * Make sure that session storage values are kept and written but removed at the end of a session.
 */
@Test
public void testLocalAndSessionStorageIsWrittenAndRemoved() throws Exception {
    // Go to first website that saves a value in the session/local store.
    goToUrlFromHomeScreen("/sessionStorage_start");
    // Assert website is loaded and values are written.
    final UiObject savedMsg = TestHelper.mDevice.findObject(new UiSelector().description("Values written to storage").enabled(true));
    savedMsg.waitForExists(waitingTime);
    assertTrue("Website loaded and values written to local / session storage", savedMsg.exists());
    // Now load the next website and assert that the values are still in the storage
    goToUrlFromBrowserScreen("/sessionStorage_check");
    {
        // Value is still stored in session storage
        final UiObject sessionStorageMsg = TestHelper.mDevice.findObject(new UiSelector().description(SESSION_STORAGE_HIT).enabled(true));
        sessionStorageMsg.waitForExists(waitingTime);
        assertTrue(sessionStorageMsg.exists());
    }
    {
        // Local storage is empty
        final UiObject localStorageMsg = TestHelper.mDevice.findObject(new UiSelector().description(LOCAL_STORAGE_MISS).enabled(true));
        localStorageMsg.waitForExists(waitingTime);
        assertTrue(localStorageMsg.exists());
    }
    // Let's press the "erase" button and end the session
    TestHelper.floatingEraseButton.perform(click());
    TestHelper.erasedMsg.waitForExists(waitingTime);
    Assert.assertTrue(TestHelper.erasedMsg.exists());
    Assert.assertTrue(TestHelper.inlineAutocompleteEditText.exists());
    // Now go to the website again and make sure that both values are not in the session/local store
    goToUrlFromHomeScreen("/sessionStorage_check");
    {
        // Session storage is empty
        final UiObject sessionStorageMsg = TestHelper.mDevice.findObject(new UiSelector().description("Session storage empty").enabled(true));
        sessionStorageMsg.waitForExists(waitingTime);
        assertTrue(sessionStorageMsg.exists());
    }
    {
        // Local storage is empty
        final UiObject localStorageMsg = TestHelper.mDevice.findObject(new UiSelector().description("Local storage empty").enabled(true));
        localStorageMsg.waitForExists(waitingTime);
        assertTrue(localStorageMsg.exists());
    }
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) Test(org.junit.Test)

Aggregations

UiSelector (android.support.test.uiautomator.UiSelector)125 UiObject (android.support.test.uiautomator.UiObject)103 Test (org.junit.Test)46 UiScrollable (android.support.test.uiautomator.UiScrollable)29 Intent (android.content.Intent)26 SmallTest (android.support.test.filters.SmallTest)18 KeyguardManager (android.app.KeyguardManager)14 UiObjectNotFoundException (android.support.test.uiautomator.UiObjectNotFoundException)9 UiDevice (android.support.test.uiautomator.UiDevice)3 SmallTest (androidx.test.filters.SmallTest)3 Account (android.accounts.Account)2 AccountManager (android.accounts.AccountManager)2 Context (android.content.Context)2 BySelector (android.support.test.uiautomator.BySelector)2 UiObject2 (android.support.test.uiautomator.UiObject2)2 Activity (android.app.Activity)1 Preference (android.preference.Preference)1 ViewInteraction (android.support.test.espresso.ViewInteraction)1 MediumTest (android.support.test.filters.MediumTest)1 RadioButton (android.widget.RadioButton)1