Search in sources :

Example 1 with SessionManager

use of mozilla.components.browser.session.SessionManager in project Rocket by mozilla-tw.

the class PrivateBrowsingScreenshot method screenshotPrivateBrowsing.

@Test
public void screenshotPrivateBrowsing() {
    // Click private home search field and enter test url
    onView(withId(R.id.pm_home_fake_input)).perform(click());
    // create the idlingResource before the new session is created.
    SessionManager sessionManager = ExtentionKt.app(activityTestRule.getActivity()).getSessionManager();
    loadingIdlingResource = new PrivateSessionLoadedIdlingResource(sessionManager, "screenshotPrivateBrowsing");
    onView(withId(R.id.url_edit)).perform(replaceText(TARGET_URL_SITE), pressImeActionButton());
    onView(withId(R.id.display_url)).check(matches(isDisplayed()));
    // Once the new session is created, we listen when the session completes loading
    IdlingRegistry.getInstance().register(loadingIdlingResource);
    onView(withId(R.id.display_url)).check(matches(withText(TARGET_URL_SITE)));
    IdlingRegistry.getInstance().unregister(loadingIdlingResource);
    // Finish private browsing
    new BottomBarRobot().clickBrowserBottomBarItem(R.id.bottom_bar_delete);
    // Check private browsing is cleared toast is displayed
    MockUIUtils.showToast(activityTestRule.getActivity(), R.string.private_browsing_erase_done);
    AndroidTestUtils.toastContainsText(activityTestRule.getActivity(), R.string.private_browsing_erase_done);
    // Take screenshot
    Screengrab.screenshot(ScreenshotNamingUtils.PRIVATE_ERASING_TOAST);
    // Click private home search field and enter test url again
    onView(withId(R.id.pm_home_fake_input)).perform(click());
    onView(withId(R.id.url_edit)).perform(replaceText(TARGET_URL_SITE), pressImeActionButton());
    onView(withId(R.id.display_url)).check(matches(isDisplayed()));
    // Check if test url is loaded
    IdlingRegistry.getInstance().register(loadingIdlingResource);
    onView(withId(R.id.display_url)).check(matches(withText(TARGET_URL_SITE)));
    IdlingRegistry.getInstance().unregister(loadingIdlingResource);
    // Expand status bar
    uiDevice.openNotification();
    // Check if erasing private browsing notification is displayed
    String notificationText = activityTestRule.getActivity().getResources().getString(R.string.private_browsing_erase_message);
    UiObject notificationObject = uiDevice.findObject(new UiSelector().text(notificationText));
    notificationObject.waitForExists(NOTIFICATION_DISPLAY_DELAY);
    // Take screenshot
    Screengrab.screenshot(ScreenshotNamingUtils.PRIVATE_ERASING_NOTIFICATION);
    // Click notification to close status bar
    try {
        notificationObject.click();
    } catch (UiObjectNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : BottomBarRobot(org.mozilla.focus.autobot.BottomBarRobot) UiObject(androidx.test.uiautomator.UiObject) SessionManager(mozilla.components.browser.session.SessionManager) PrivateSessionLoadedIdlingResource(org.mozilla.focus.helper.PrivateSessionLoadedIdlingResource) UiSelector(androidx.test.uiautomator.UiSelector) UiObjectNotFoundException(androidx.test.uiautomator.UiObjectNotFoundException) Test(org.junit.Test)

Aggregations

UiObject (androidx.test.uiautomator.UiObject)1 UiObjectNotFoundException (androidx.test.uiautomator.UiObjectNotFoundException)1 UiSelector (androidx.test.uiautomator.UiSelector)1 SessionManager (mozilla.components.browser.session.SessionManager)1 Test (org.junit.Test)1 BottomBarRobot (org.mozilla.focus.autobot.BottomBarRobot)1 PrivateSessionLoadedIdlingResource (org.mozilla.focus.helper.PrivateSessionLoadedIdlingResource)1