use of org.mozilla.focus.helper.PrivateSessionLoadedIdlingResource 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();
}
}
Aggregations