Search in sources :

Example 96 with UiSelector

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

the class ShareDialogTest method shareTest.

@Test
public void shareTest() throws InterruptedException, UiObjectNotFoundException {
    UiObject shareBtn = TestHelper.mDevice.findObject(new UiSelector().resourceId("org.mozilla.focus.debug:id/share").enabled(true));
    /* Go to a webpage */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("mozilla");
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));
    /* Select share */
    TestHelper.menuButton.perform(click());
    shareBtn.waitForExists(waitingTime);
    shareBtn.click();
    // For simulators, where apps are not installed, it'll take to message app
    TestHelper.shareMenuHeader.waitForExists(waitingTime);
    assertTrue(TestHelper.shareMenuHeader.exists());
    assertTrue(TestHelper.shareAppList.exists());
    TestHelper.pressBackKey();
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) Test(org.junit.Test)

Example 97 with UiSelector

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

the class SwitchLocaleTest method EnglishSystemLocaleTest.

@Test
public void EnglishSystemLocaleTest() throws InterruptedException, UiObjectNotFoundException {
    UiObject frenchMenuItem = TestHelper.mDevice.findObject(new UiSelector().className("android.widget.TextView").text("Français"));
    UiObject englishMenuItem = TestHelper.mDevice.findObject(new UiSelector().className("android.widget.TextView").text("System default"));
    UiObject frenchLocaleinEn = TestHelper.mDevice.findObject(new UiSelector().className("android.widget.CheckedTextView").text("Français"));
    /* Go to Settings */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    openSettings();
    LanguageSelection.waitForExists(waitingTime);
    /* system locale is in English, check it is now set to system locale */
    LanguageSelection.click();
    sysDefaultLocale.waitForExists(waitingTime);
    Assert.assertTrue(sysDefaultLocale.isChecked());
    /* change locale to non-english in the setting, verify the locale is changed */
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    appViews.scrollIntoView(frenchLocaleinEn);
    Assert.assertTrue(frenchLocaleinEn.isClickable());
    frenchLocaleinEn.click();
    frenchHeading.waitForExists(waitingTime);
    Assert.assertTrue(frenchHeading.exists());
    Assert.assertTrue(frenchMenuItem.exists());
    /* Exit to main and see the UI is in French as well */
    TestHelper.pressBackKey();
    UiObject frenchTitle = TestHelper.mDevice.findObject(new UiSelector().className("android.widget.TextView").text("Navigation privée automatique.\nNaviguez. Effacez. Recommencez."));
    frenchTitle.waitForExists(waitingTime);
    Assert.assertTrue(frenchTitle.exists());
    openMenu();
    Assert.assertEquals(TestHelper.settingsMenuItem.getText(), "Paramètres");
    Assert.assertEquals(TestHelper.HelpItem.getText(), "Aide");
    TestHelper.settingsMenuItem.click();
    /* re-enter settings, change it back to system locale, verify the locale is changed */
    LanguageSelection.click();
    Assert.assertTrue(frenchLocaleinEn.isChecked());
    appViews.scrollToBeginning(10);
    sysDefaultLocale.waitForExists(waitingTime);
    sysDefaultLocale.click();
    LanguageSelection.waitForExists(waitingTime);
    Assert.assertTrue(englishHeading.exists());
    Assert.assertTrue(englishMenuItem.exists());
    TestHelper.pressBackKey();
    UiObject englishTitle = TestHelper.mDevice.findObject(new UiSelector().className("android.widget.TextView").text("Automatic private browsing.\nBrowse. Erase. Repeat."));
    englishTitle.waitForExists(waitingTime);
    Assert.assertTrue(englishTitle.exists());
    TestHelper.menuButton.perform(click());
    Assert.assertEquals(TestHelper.settingsMenuItem.getText(), "Settings");
    Assert.assertEquals(TestHelper.HelpItem.getText(), "Help");
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) UiScrollable(android.support.test.uiautomator.UiScrollable) Test(org.junit.Test)

Example 98 with UiSelector

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

the class SwitchLocaleTest method FrenchLocaleTest.

@Test
public void FrenchLocaleTest() throws InterruptedException, UiObjectNotFoundException {
    UiObject frenchMenuItem = TestHelper.mDevice.findObject(new UiSelector().className("android.widget.TextView").text("Valeur par défaut du système"));
    UiObject englishMenuItem = TestHelper.mDevice.findObject(new UiSelector().className("android.widget.TextView").text("English (United States)"));
    UiObject englishLocaleinFr = TestHelper.mDevice.findObject(new UiSelector().className("android.widget.CheckedTextView").text("English (United States)"));
    /* Go to Settings */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    openSettings();
    LanguageSelection.waitForExists(waitingTime);
    /* system locale is in French, check it is now set to system locale */
    frenchHeading.waitForExists(waitingTime);
    Assert.assertTrue(frenchHeading.exists());
    Assert.assertTrue(frenchMenuItem.exists());
    LanguageSelection.click();
    Assert.assertTrue(sysDefaultLocale.isChecked());
    /* change locale to English in the setting, verify the locale is changed */
    UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
    appViews.scrollIntoView(englishLocaleinFr);
    Assert.assertTrue(englishLocaleinFr.isClickable());
    englishLocaleinFr.click();
    englishHeading.waitForExists(waitingTime);
    Assert.assertTrue(englishHeading.exists());
    Assert.assertTrue(englishMenuItem.exists());
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) UiScrollable(android.support.test.uiautomator.UiScrollable) Test(org.junit.Test)

Example 99 with UiSelector

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

the class WebViewDataTest method DeleteWebViewDataTest.

@Test
public void DeleteWebViewDataTest() throws InterruptedException, UiObjectNotFoundException, IOException {
    // Load website with service worker
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText(webServer.url(TEST_PATH).toString());
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));
    // Assert website is loaded
    final UiObject titleMsg = TestHelper.mDevice.findObject(new UiSelector().description("focus test page").enabled(true));
    titleMsg.waitForExists(waitingTime);
    assertTrue("Website title loaded", titleMsg.exists());
    // Assert cookie is saved
    final UiObject cookieMsg = TestHelper.mDevice.findObject(new UiSelector().description("Cookie saved").enabled(true));
    cookieMsg.waitForExists(waitingTime);
    assertTrue("Cookie is saved", cookieMsg.exists());
    final UiObject serviceWorkerMsg = TestHelper.mDevice.findObject(new UiSelector().description("Service worker installed").enabled(true));
    serviceWorkerMsg.waitForExists(waitingTime);
    assertTrue("Service worker installed", serviceWorkerMsg.exists());
    // Erase browsing session
    TestHelper.floatingEraseButton.perform(click());
    TestHelper.erasedMsg.waitForExists(waitingTime);
    Assert.assertTrue(TestHelper.erasedMsg.exists());
    Assert.assertTrue(TestHelper.inlineAutocompleteEditText.exists());
    TestHelper.waitForIdle();
    // Make sure all resources have been loaded from the web server
    assertPathsHaveBeenRequested(webServer, // Actual URL
    "/copper/truck/destroy?smoke=violet", // Our service worker is installed
    "/copper/truck/service-worker.js");
    // Now let's assert that there are no surprises in the data directory
    final File dataDir = new File(appContext.getApplicationInfo().dataDir);
    assertTrue("App data directory should exist", dataDir.exists());
    final File webViewDirectory = new File(dataDir, "app_webview");
    assertTrue("WebView directory should exist", webViewDirectory.exists());
    assertEquals("WebView directory contains one subdirectory", 1, webViewDirectory.list().length);
    assertEquals("WebView subdirectory is local storage directory", "Local Storage", webViewDirectory.list()[0]);
    assertCacheDirContentsPostErase();
    for (final String name : dataDir.list()) {
        if (WHITELIST_EMPTY_FOLDERS.contains(name)) {
            final File folder = new File(dataDir, name);
            assertTrue(" Check +'" + name + "' is empty folder", folder.isDirectory() && folder.list().length == 0);
            continue;
        }
        assertTrue("Expected file '" + name + "' to be in the app's data dir whitelist", WHITELIST_DATA_DIR_CONTENTS.contains(name));
    }
    assertNoTraces(dataDir);
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) File(java.io.File) Test(org.junit.Test)

Example 100 with UiSelector

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

the class ErrorPagesScreenshots method takeScreenshotsOfErrorPages.

@Test
public void takeScreenshotsOfErrorPages() throws Exception {
    for (ErrorTypes error : ErrorTypes.values()) {
        onView(withId(R.id.urlView)).check(matches(isDisplayed())).check(matches(hasFocus())).perform(click(), replaceText("error:" + error.value), pressImeActionButton());
        assertTrue(TestHelper.webView.waitForExists(waitingTime));
        assertTrue(TestHelper.progressBar.waitUntilGone(waitingTime));
        // Android O has an issue with using Locator.ID
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            UiObject tryAgainBtn = device.findObject(new UiSelector().descriptionContains(getString(R.string.errorpage_refresh)).clickable(true));
            assertTrue(tryAgainBtn.waitForExists(waitingTime));
        } else {
            onWebView().withElement(findElement(Locator.ID, "errorTitle")).perform(webClick());
            onWebView().withElement(findElement(Locator.ID, "errorTryAgain")).perform(webScrollIntoView());
        }
        Screengrab.screenshot(error.name());
        onView(withId(R.id.display_url)).check(matches(isDisplayed())).perform(click());
    }
}
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