Search in sources :

Example 1 with ScreenshotIdlingResource

use of org.mozilla.focus.helper.ScreenshotIdlingResource in project Rocket by mozilla-tw.

the class MyShotScreenshot method screenshotMyShot.

@Test
public void screenshotMyShot() {
    // Browsing a web page
    onView(allOf(withId(R.id.home_fragment_fake_input), isDisplayed())).perform(click());
    onView(allOf(withId(R.id.url_edit), isDisplayed())).perform(replaceText(TARGET_URL_SITE), pressImeActionButton());
    IdlingRegistry.getInstance().register(sessionLoadedIdlingResource);
    onView(allOf(withId(R.id.display_url), isDisplayed())).check(matches(withText(TARGET_URL_SITE)));
    IdlingRegistry.getInstance().unregister(sessionLoadedIdlingResource);
    MockUIUtils.showToast(activityTestRule.getActivity(), R.string.screenshot_failed);
    AndroidTestUtils.toastContainsText(activityTestRule.getActivity(), R.string.screenshot_failed);
    Screengrab.screenshot(ScreenshotNamingUtils.SCREENSHOT_FAILED_TO_CAPTURE);
    SystemClock.sleep(MockUIUtils.SHORT_DELAY);
    final ScreenCaptureDialogFragment capturingFragment = ScreenCaptureDialogFragment.newInstance();
    capturingFragment.show(activityTestRule.getActivity().getBrowserFragment().getChildFragmentManager(), "capturingFragment");
    SystemClock.sleep(MockUIUtils.SHORT_DELAY);
    onView(withText(R.string.screenshot_illustration)).check(matches(isDisplayed()));
    Screengrab.screenshot(ScreenshotNamingUtils.SCREENSHOT_CAPTURING);
    capturingFragment.dismiss(false);
    screenshotIdlingResource = new ScreenshotIdlingResource(activityTestRule.getActivity());
    // Click screen capture button
    new BottomBarRobot().clickBrowserBottomBarItem(R.id.bottom_bar_capture);
    IdlingRegistry.getInstance().register(screenshotIdlingResource);
    // Open browser menu
    AndroidTestUtils.tapBrowserMenuButton();
    IdlingRegistry.getInstance().unregister(screenshotIdlingResource);
    // Click my shot and take a screenshot of panel and toast
    onView(allOf(withId(R.id.menu_screenshots), isDisplayed())).perform(click());
    Screengrab.screenshot(ScreenshotNamingUtils.SCREENSHOT_PANEL_AND_SAVED);
    // Click the first item in my shots panel
    // Since "index=0" in ScreenshotItemAdapter is always date label, the first screenshot item will start from "index=1".
    onView(withId(R.id.screenshot_grid_recycler_view)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click()));
    // Check if screenshot is displayed
    onView(withId(R.id.screenshot_viewer_image)).check(matches(isDisplayed()));
    // Click the info button and take a screenshot
    onView(withId(R.id.screenshot_viewer_btn_info)).perform(click());
    Screengrab.screenshot(ScreenshotNamingUtils.SCREENSHOT_INFO);
    onView(withText(R.string.action_ok)).inRoot(isDialog()).perform(click());
    // Click the delete button and take a screenshot
    onView(withId(R.id.screenshot_viewer_btn_delete)).perform(click());
    onView(withText(R.string.browsing_history_menu_delete)).check(matches(isDisplayed()));
    Screengrab.screenshot(ScreenshotNamingUtils.SCREENSHOT_DELETE);
    // Click delete button and take a screenshot of toast
    onView(allOf(withText(R.string.browsing_history_menu_delete), isDisplayed())).perform(click());
    Screengrab.screenshot(ScreenshotNamingUtils.SCREENSHOT_DELETED);
    onView(withId(R.id.screenshots)).check(matches(isDisplayed()));
}
Also used : ScreenCaptureDialogFragment(org.mozilla.focus.fragment.ScreenCaptureDialogFragment) ScreenshotIdlingResource(org.mozilla.focus.helper.ScreenshotIdlingResource) BottomBarRobot(org.mozilla.focus.autobot.BottomBarRobot) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 BottomBarRobot (org.mozilla.focus.autobot.BottomBarRobot)1 ScreenCaptureDialogFragment (org.mozilla.focus.fragment.ScreenCaptureDialogFragment)1 ScreenshotIdlingResource (org.mozilla.focus.helper.ScreenshotIdlingResource)1