Search in sources :

Example 91 with UiSelector

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

the class FirstRunScreenshots method takeScreenshotsOfFirstrun.

@Test
public void takeScreenshotsOfFirstrun() throws UiObjectNotFoundException {
    assertTrue(device.findObject(new UiSelector().text(getString(R.string.firstrun_defaultbrowser_title)).enabled(true)).waitForExists(waitingTime));
    Screengrab.screenshot("Onboarding_1_View");
    TestHelper.nextBtn.click();
    assertTrue(device.findObject(new UiSelector().text(getString(R.string.firstrun_search_title)).enabled(true)).waitForExists(waitingTime));
    Screengrab.screenshot("Onboarding_2_View");
    TestHelper.nextBtn.click();
    assertTrue(device.findObject(new UiSelector().text(getString(R.string.firstrun_shortcut_title)).enabled(true)).waitForExists(waitingTime));
    Screengrab.screenshot("Onboarding_3_View");
    TestHelper.nextBtn.click();
    assertTrue(device.findObject(new UiSelector().text(getString(R.string.firstrun_privacy_title)).enabled(true)).waitForExists(waitingTime));
    Screengrab.screenshot("Onboarding_last_View");
}
Also used : UiSelector(android.support.test.uiautomator.UiSelector) Test(org.junit.Test)

Example 92 with UiSelector

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

the class NotificationScreenshots method takeScreenshotOfNotification.

@Test
public void takeScreenshotOfNotification() throws Exception {
    onView(withId(R.id.urlView)).check(matches(isDisplayed())).check(matches(hasFocus())).perform(click(), replaceText(webServer.url("/").toString()), pressImeActionButton());
    onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(containsString(webServer.getHostName()))));
    final UiObject openAction = device.findObject(new UiSelector().descriptionContains(getString(R.string.notification_action_open)).resourceId("android:id/action0").enabled(true));
    device.openNotification();
    try {
        if (!openAction.waitForExists(waitingTime)) {
            // The notification is not expanded. Let's expand it now.
            device.findObject(new UiSelector().text(getString(R.string.app_name))).swipeDown(20);
            assertTrue(openAction.waitForExists(waitingTime));
        }
        Screengrab.screenshot("DeleteHistory_NotificationBar");
    } finally {
        // Close notification tray again
        device.pressBack();
    }
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) Test(org.junit.Test)

Example 93 with UiSelector

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

the class SettingsScreenshots method takeScreenShotsOfSettings.

@Test
public void takeScreenShotsOfSettings() throws Exception {
    openSettings();
    Screengrab.screenshot("Settings_View_Top");
    /* Language List (First page only */
    onView(withText(R.string.preference_language)).perform(click());
    // Cancel button is not translated in some locales, and there are no R.id defined
    // That can be checked in the language list dialog
    UiObject CancelBtn = device.findObject(new UiSelector().resourceId("android:id/button2").enabled(true));
    CancelBtn.waitForExists(waitingTime);
    Screengrab.screenshot("Language_Selection");
    CancelBtn.click();
    onView(withText(R.string.preference_language)).check(matches(isDisplayed()));
    /* Search Engine List */
    onView(withText(R.string.preference_search_engine_default)).perform(click());
    onView(withText(R.string.preference_search_installed_search_engines)).check(matches(isDisplayed()));
    Screengrab.screenshot("SearchEngine_Selection");
    /* Remove Search Engine page */
    openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getContext());
    // wait until dialog fully appears
    device.waitForIdle();
    onView(withText(R.string.preference_search_remove)).check(matches(isDisplayed()));
    Screengrab.screenshot("SearchEngine_Search_Engine_Menu");
    // Menu items don't have ids, so we have to match by text
    onView(withText(R.string.preference_search_remove)).perform(click());
    // wait until dialog fully disappears
    device.waitForIdle();
    assertToolbarMatchesText(R.string.preference_search_remove_title);
    Screengrab.screenshot("SearchEngine_Remove_Search_Engines");
    Espresso.pressBack();
    /* Manual Search Engine page */
    final String addEngineLabel = getString(R.string.preference_search_add2);
    onData(withTitleText(addEngineLabel)).perform(click());
    onView(withId(R.id.edit_engine_name)).check(matches(isEnabled()));
    Screengrab.screenshot("SearchEngine_Add_Search_Engine");
    Espresso.pressBack();
    Espresso.pressBack();
    Espresso.pressBack();
    /* Tap autocomplete menu */
    final String urlAutocompletemenu = getString(R.string.preference_subitem_autocomplete);
    onData(withTitleText(urlAutocompletemenu)).perform(click());
    onView(withText(getString(R.string.preference_autocomplete_custom_summary))).check(matches(isDisplayed()));
    Screengrab.screenshot("Autocomplete_Menu_Item");
    /* Enable Autocomplete, and enter Custom URLs */
    onView(withText(getString(R.string.preference_autocomplete_custom_summary))).perform(click());
    /* Add custom URL */
    final String key = InstrumentationRegistry.getTargetContext().getString(R.string.pref_key_screen_custom_domains);
    onData(withKey(key)).perform(click());
    final String addCustomURLAction = getString(R.string.preference_autocomplete_action_add);
    onView(withText(addCustomURLAction)).check(matches(isDisplayed()));
    Screengrab.screenshot("Autocomplete_Custom_URL_List");
    onView(withText(addCustomURLAction)).perform(click());
    onView(withId(R.id.domainView)).check(matches(isDisplayed()));
    Screengrab.screenshot("Autocomplete_Add_Custom_URL_Dialog");
    onView(withId(R.id.domainView)).perform(typeText("screenshot.com"), closeSoftKeyboard());
    onView(withId(R.id.save)).perform(click());
    onView(withText(addCustomURLAction)).check(matches(isDisplayed()));
    /* Remove menu */
    final String removeMenu = getString(R.string.preference_autocomplete_menu_remove);
    openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getContext());
    // wait until dialog fully appears
    device.waitForIdle();
    onView(withText(removeMenu)).check(matches(isDisplayed()));
    Screengrab.screenshot("Autocomplete_Custom_URL_Remove_Menu_Item");
    onView(withText(removeMenu)).perform(click());
    // wait until dialog fully disappears
    device.waitForIdle();
    /* Remove dialog */
    onView(withText(getString(R.string.preference_autocomplete_title_remove))).check(matches(isDisplayed()));
    Screengrab.screenshot("Autocomplete_Custom_URL_Remove_Dialog");
    Espresso.pressBack();
    onView(withText(addCustomURLAction)).check(matches(isDisplayed()));
    Espresso.pressBack();
    onView(withText(urlAutocompletemenu)).check(matches(isDisplayed()));
    Espresso.pressBack();
    /* scroll down */
    assertTrue(TestHelper.settingsHeading.waitForExists(waitingTime));
    UiScrollable settingsView = new UiScrollable(new UiSelector().scrollable(true));
    settingsView.scrollToEnd(4);
    Screengrab.screenshot("Settings_View_Bottom");
    // "About" screen
    final String aboutLabel = getString(R.string.preference_about, getString(R.string.app_name));
    onData(withTitleText(aboutLabel)).check(matches(isDisplayed())).perform(click());
    onView(allOf(withClassName(endsWith("TextView")), withParent(withId(R.id.toolbar)))).check(matches(isDisplayed())).check(matches(withText(R.string.menu_about)));
    onWebView().withElement(findElement(Locator.ID, "wordmark")).perform(webClick());
    Screengrab.screenshot("About_Page");
    // Leave about page
    device.pressBack();
    // "Your rights" screen
    final String yourRightsLabel = getString(R.string.menu_rights);
    onData(withTitleText(yourRightsLabel)).check(matches(isDisplayed())).perform(click());
    onView(allOf(withClassName(endsWith("TextView")), withParent(withId(R.id.toolbar)))).check(matches(isDisplayed())).check(matches(withText(yourRightsLabel)));
    onWebView().withElement(findElement(Locator.ID, "first")).perform(webClick());
    Screengrab.screenshot("YourRights_Page");
}
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 94 with UiSelector

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

the class AdBlockingTest method AdBlockTest.

@Test
public void AdBlockTest() throws InterruptedException, UiObjectNotFoundException {
    UiObject blockAdTrackerEntry = TestHelper.settingsList.getChild(new UiSelector().className("android.widget.LinearLayout").instance(2));
    UiObject blockAdTrackerValue = blockAdTrackerEntry.getChild(new UiSelector().className("android.widget.Switch"));
    UiObject unBlocked = TestHelper.mDevice.findObject(new UiSelector().className("android.view.View").resourceId("ad_iframe"));
    // Let's go to ads-blocker.com/testing/
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("ads-blocker.com/testing/");
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));
    int dHeight = TestHelper.mDevice.getDisplayHeight();
    int dWidth = TestHelper.mDevice.getDisplayWidth();
    int xScrollPosition = dWidth / 2;
    int yScrollStop = dHeight / 4;
    TestHelper.mDevice.swipe(xScrollPosition, yScrollStop, xScrollPosition, 0, 20);
    unBlocked.waitForExists(waitingTime);
    assertFalse(unBlocked.exists());
    TestHelper.mDevice.swipe(xScrollPosition, dHeight / 2, xScrollPosition, dHeight / 2 + 200, 20);
    /* Go to settings and disable everything */
    TestHelper.menuButton.perform(click());
    TestHelper.browserViewSettingsMenuItem.click();
    TestHelper.settingsHeading.waitForExists(waitingTime);
    blockAdTrackerEntry.click();
    assertTrue(blockAdTrackerValue.getText().equals("OFF"));
    TestHelper.navigateUp.click();
    TestHelper.browserURLbar.waitForExists(waitingTime);
    // Back to the webpage
    TestHelper.browserURLbar.click();
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("ads-blocker.com/testing/");
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));
    TestHelper.mDevice.swipe(xScrollPosition, yScrollStop, xScrollPosition, 0, 20);
    unBlocked.waitForExists(waitingTime);
    assertTrue(unBlocked.exists());
    TestHelper.mDevice.swipe(xScrollPosition, dHeight / 2, xScrollPosition, dHeight / 2 + 200, 20);
    // Let's set it back for future tests
    TestHelper.menuButton.perform(click());
    TestHelper.browserViewSettingsMenuItem.click();
    TestHelper.settingsHeading.waitForExists(waitingTime);
    blockAdTrackerEntry.click();
    assertTrue(blockAdTrackerValue.getText().equals("ON"));
    TestHelper.navigateUp.click();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));
    TestHelper.floatingEraseButton.perform(click());
}
Also used : UiObject(android.support.test.uiautomator.UiObject) UiSelector(android.support.test.uiautomator.UiSelector) Test(org.junit.Test)

Example 95 with UiSelector

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

the class OpenwithDialogTest method OpenTest.

@Test
public void OpenTest() throws InterruptedException, UiObjectNotFoundException {
    UiObject openWithBtn = TestHelper.mDevice.findObject(new UiSelector().resourceId("org.mozilla.focus.debug:id/open_select_browser").enabled(true));
    UiObject openWithTitle = TestHelper.mDevice.findObject(new UiSelector().className("android.widget.TextView").text("Open in…").enabled(true));
    UiObject openWithList = TestHelper.mDevice.findObject(new UiSelector().resourceId("org.mozilla.focus.debug:id/apps").enabled(true));
    /* Go to mozilla page */
    TestHelper.inlineAutocompleteEditText.waitForExists(waitingTime);
    TestHelper.inlineAutocompleteEditText.clearTextField();
    TestHelper.inlineAutocompleteEditText.setText("mozilla");
    TestHelper.hint.waitForExists(waitingTime);
    TestHelper.pressEnterKey();
    assertTrue(TestHelper.webView.waitForExists(waitingTime));
    /* Select Open with from menu, check appearance */
    TestHelper.menuButton.perform(click());
    openWithBtn.waitForExists(waitingTime);
    openWithBtn.click();
    openWithTitle.waitForExists(waitingTime);
    assertTrue(openWithTitle.exists());
    assertTrue(openWithList.exists());
    TestHelper.pressBackKey();
}
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