Search in sources :

Example 1 with BottomBarRobot

use of org.mozilla.focus.autobot.BottomBarRobot 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)

Example 2 with BottomBarRobot

use of org.mozilla.focus.autobot.BottomBarRobot in project Rocket by mozilla-tw.

the class MenuShareLinkTest method loadTestWebsiteAndShareLinkInMenu.

private void loadTestWebsiteAndShareLinkInMenu() {
    sessionLoadedIdlingResource = new SessionLoadedIdlingResource(intentsTestRule.getActivity());
    // Click home search field
    onView(withId(R.id.home_fragment_fake_input)).perform(click());
    // Enter URL and load the page
    onView(withId(R.id.url_edit)).perform(replaceText(webServer.url(TEST_PATH).toString()), pressImeActionButton());
    // Waiting for the page is loaded
    IdlingRegistry.getInstance().register(sessionLoadedIdlingResource);
    // Tap menu -> share link
    AndroidTestUtils.tapBrowserMenuButton();
    new BottomBarRobot().clickMenuBottomBarItem(R.id.bottom_bar_share);
    IdlingRegistry.getInstance().unregister(sessionLoadedIdlingResource);
}
Also used : BottomBarRobot(org.mozilla.focus.autobot.BottomBarRobot) SessionLoadedIdlingResource(org.mozilla.focus.helper.SessionLoadedIdlingResource)

Example 3 with BottomBarRobot

use of org.mozilla.focus.autobot.BottomBarRobot in project Rocket by mozilla-tw.

the class NavigationTest method browsingWebsiteBackAndForward_backAndFrowardToWebsite.

/**
 * Test case no: TC_0013
 * Test case name: Navigation and back and forth to previous site
 * Steps:
 * 1. Launch Rocket
 * 2. Visit a website_1
 * 3. Visit a website_2
 * 4. Press Back button
 * 5. check website_1 is displayed
 * 6. open menu to click next button
 * 7. check website_2 is displayed
 */
@FlakyTest
@Test
public void browsingWebsiteBackAndForward_backAndFrowardToWebsite() {
    final SessionLoadedIdlingResource loadingIdlingResource = new SessionLoadedIdlingResource(activityTestRule.getActivity());
    // Click search field
    onView(withId(R.id.home_fragment_fake_input)).perform(click());
    // Enter site 1 url
    onView(withId(R.id.url_edit)).check(matches(isDisplayed()));
    onView(withId(R.id.url_edit)).perform(typeText(TARGET_URL_SITE_1));
    onView(withId(R.id.url_edit)).perform(pressKey(KeyEvent.KEYCODE_ENTER));
    // Check if site 1 url is loaded
    IdlingRegistry.getInstance().register(loadingIdlingResource);
    onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(TARGET_URL_SITE_1)));
    IdlingRegistry.getInstance().unregister(loadingIdlingResource);
    // Click search button and clear existing text in search field
    onView(withId(R.id.bottom_bar_search)).perform(click());
    onView(withId(R.id.url_edit)).perform(clearText());
    // Enter site 2 url
    onView(withId(R.id.url_edit)).perform(typeText(TARGET_URL_SITE_2));
    onView(withId(R.id.url_edit)).perform(pressKey(KeyEvent.KEYCODE_ENTER));
    // Check if site 2 url is loaded
    IdlingRegistry.getInstance().register(loadingIdlingResource);
    onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(TARGET_URL_SITE_2)));
    IdlingRegistry.getInstance().unregister(loadingIdlingResource);
    // Press back and check if go back to site 1
    Espresso.pressBack();
    IdlingRegistry.getInstance().register(loadingIdlingResource);
    onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(TARGET_URL_SITE_1)));
    IdlingRegistry.getInstance().unregister(loadingIdlingResource);
    // Open menu and click next button
    AndroidTestUtils.tapBrowserMenuButton();
    new BottomBarRobot().clickMenuBottomBarItem(R.id.bottom_bar_next);
    // Check if site 2 is loaded again
    IdlingRegistry.getInstance().register(loadingIdlingResource);
    onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(TARGET_URL_SITE_2)));
    IdlingRegistry.getInstance().unregister(loadingIdlingResource);
    // Press back and check if site 1 is loading again
    Espresso.pressBack();
    IdlingRegistry.getInstance().register(loadingIdlingResource);
    onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(TARGET_URL_SITE_1)));
    IdlingRegistry.getInstance().unregister(loadingIdlingResource);
}
Also used : BottomBarRobot(org.mozilla.focus.autobot.BottomBarRobot) SessionLoadedIdlingResource(org.mozilla.focus.helper.SessionLoadedIdlingResource) FlakyTest(androidx.test.filters.FlakyTest) FlakyTest(androidx.test.filters.FlakyTest) Test(org.junit.Test)

Example 4 with BottomBarRobot

use of org.mozilla.focus.autobot.BottomBarRobot in project Rocket by mozilla-tw.

the class BookmarksTest method browsingPageAndBookmarkPage.

private String browsingPageAndBookmarkPage() {
    final String targetUrl = webServer.url(TEST_SITE_1).toString();
    sessionLoadedIdlingResource = new SessionLoadedIdlingResource(activityTestRule.getActivity());
    // Visit a website A
    AndroidTestUtils.tapHomeSearchField();
    AndroidTestUtils.typeTextInSearchFieldAndGo(targetUrl);
    // Check if target url is loaded
    IdlingRegistry.getInstance().register(sessionLoadedIdlingResource);
    AndroidTestUtils.urlBarContainsText(targetUrl);
    IdlingRegistry.getInstance().unregister(sessionLoadedIdlingResource);
    // Tap browser menu button
    AndroidTestUtils.tapBrowserMenuButton();
    // Tap bookmark button
    new BottomBarRobot().clickMenuBottomBarItem(R.id.bottom_bar_bookmark);
    return targetUrl;
}
Also used : BottomBarRobot(org.mozilla.focus.autobot.BottomBarRobot) SessionLoadedIdlingResource(org.mozilla.focus.helper.SessionLoadedIdlingResource) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 5 with BottomBarRobot

use of org.mozilla.focus.autobot.BottomBarRobot 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

BottomBarRobot (org.mozilla.focus.autobot.BottomBarRobot)8 Test (org.junit.Test)6 SessionLoadedIdlingResource (org.mozilla.focus.helper.SessionLoadedIdlingResource)4 FlakyTest (androidx.test.filters.FlakyTest)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 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 ScreenCaptureDialogFragment (org.mozilla.focus.fragment.ScreenCaptureDialogFragment)1 PrivateSessionLoadedIdlingResource (org.mozilla.focus.helper.PrivateSessionLoadedIdlingResource)1 ScreenshotIdlingResource (org.mozilla.focus.helper.ScreenshotIdlingResource)1 SearchEngine (org.mozilla.focus.search.SearchEngine)1