Search in sources :

Example 6 with SessionLoadedIdlingResource

use of org.mozilla.focus.helper.SessionLoadedIdlingResource 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 7 with SessionLoadedIdlingResource

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

the class DownloadTest method browsePageAndDownload.

private void browsePageAndDownload() {
    // Start the activity
    activityRule.launchActivity(new Intent());
    final SessionLoadedIdlingResource sessionLoadedIdlingResource = new SessionLoadedIdlingResource(activityRule.getActivity());
    // Click and prepare to enter the URL
    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 page loading completes
    IdlingRegistry.getInstance().register(sessionLoadedIdlingResource);
    // Find the element in HTML with id "download" after the page is loaded
    onWebView().withElement(findElement(Locator.ID, HTML_ELEMENT_ID_DOWNLOAD)).perform(webClick());
    // Unregister session loaded idling resource
    IdlingRegistry.getInstance().unregister(sessionLoadedIdlingResource);
}
Also used : SessionLoadedIdlingResource(org.mozilla.focus.helper.SessionLoadedIdlingResource) Intent(android.content.Intent)

Example 8 with SessionLoadedIdlingResource

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

the class ScreenNavigatorTest method assertNewPageLoaded.

private void assertNewPageLoaded(ScreenNavigatorWrapper navigator, String url) {
    final SessionLoadedIdlingResource loadingIdlingResource = new SessionLoadedIdlingResource(activityTestRule.getActivity());
    navigator.showBrowserScreen(url);
    IdlingRegistry.getInstance().register(loadingIdlingResource);
    onView(withId(R.id.display_url)).check(matches(isDisplayed()));
    onView(withId(R.id.display_url)).check(matches(isDisplayed())).check(matches(withText(url)));
    Assert.assertEquals(true, navigator.isBrowserInForeground());
    IdlingRegistry.getInstance().unregister(loadingIdlingResource);
}
Also used : SessionLoadedIdlingResource(org.mozilla.focus.helper.SessionLoadedIdlingResource)

Example 9 with SessionLoadedIdlingResource

use of org.mozilla.focus.helper.SessionLoadedIdlingResource 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 10 with SessionLoadedIdlingResource

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

the class BrowsingHistoryTest method browsingWebsiteThenTapTheFirstHistoryItem_browsingHistoryRecordCorrectly.

@Test
public void browsingWebsiteThenTapTheFirstHistoryItem_browsingHistoryRecordCorrectly() {
    activityTestRule.launchActivity(new Intent());
    // loadingIdlingResource needs to be initialized here cause activity only exist till above line is called.
    loadingIdlingResource = new SessionLoadedIdlingResource(activityTestRule.getActivity());
    final String targerUrl = webServer.url(TEST_PATH).toString();
    // Click search field
    onView(withId(R.id.home_fragment_fake_input)).perform(click());
    // Enter target url
    onView(allOf(withId(R.id.url_edit), isDisplayed())).perform(replaceText(targerUrl), pressImeActionButton());
    // Check if target url is loaded
    IdlingRegistry.getInstance().register(loadingIdlingResource);
    onView(allOf(withId(R.id.display_url), isDisplayed())).check(matches(withText(targerUrl)));
    // Open menu
    onView(allOf(withId(R.id.btn_menu), isDisplayed())).perform(click());
    // Open history panel
    onView(allOf(withId(R.id.menu_history), isDisplayed())).perform(click());
    // Click the first item in history panel
    onView(ViewMatchers.withId(R.id.browsing_history_recycler_view)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click()));
    // Check if this history record is target url and loaded again
    onView(allOf(withId(R.id.display_url), isDisplayed())).check(matches(withText(targerUrl)));
}
Also used : SessionLoadedIdlingResource(org.mozilla.focus.helper.SessionLoadedIdlingResource) Intent(android.content.Intent) Test(org.junit.Test)

Aggregations

SessionLoadedIdlingResource (org.mozilla.focus.helper.SessionLoadedIdlingResource)19 Intent (android.content.Intent)11 Test (org.junit.Test)10 BottomBarRobot (org.mozilla.focus.autobot.BottomBarRobot)4 Before (org.junit.Before)3 SearchEngine (org.mozilla.focus.search.SearchEngine)3 FalconScreenshotStrategy (tools.fastlane.screengrab.FalconScreenshotStrategy)2 DisplayMetrics (android.util.DisplayMetrics)1 FlakyTest (androidx.test.filters.FlakyTest)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 BeforeTestTask (org.mozilla.focus.helper.BeforeTestTask)1 Site (org.mozilla.focus.history.model.Site)1 SessionManager (org.mozilla.rocket.tabs.SessionManager)1