Java Code Examples for androidx.test.espresso.Espresso#pressBack()
The following examples show how to use
androidx.test.espresso.Espresso#pressBack() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoPubInterstitialTest.java From prebid-mobile-android with Apache License 2.0 | 6 votes |
@Test public void testMoPubInterstitialWithoutAutoRefresh() throws Exception { onView(withId(R.id.adTypeSpinner)).perform(click()); onData(allOf(is(instanceOf(String.class)), is("Interstitial"))).perform(click()); onView(withId(R.id.adServerSpinner)).perform(click()); onData(allOf(is(instanceOf(String.class)), is("MoPub"))).perform(click()); onView(withId(R.id.autoRefreshInput)).perform(typeText("0")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); String currentActivityName = TestUtil.getCurrentActivity().getClass().getName(); if ("com.mopub.mobileads.MoPubActivity".equals(currentActivityName)) { onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); Thread.sleep(30000); assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); } else if ("org.prebid.mobile.app.DemoActivity".equals(currentActivityName)) { assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but MoPub interstitial not loaded and show successfully"); } else { fail("Demo app not working properly"); } }
Example 2
Source File: DFPInterstitialTest.java From prebid-mobile-android with Apache License 2.0 | 6 votes |
@Test public void testDFPInterstitialWithoutAutoRefresh() throws Exception { onView(withId(R.id.adTypeSpinner)).perform(click()); onData(allOf(is(instanceOf(String.class)), is("Interstitial"))).perform(click()); onView(withId(R.id.autoRefreshInput)).perform(typeText("0")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); String activityName = TestUtil.getCurrentActivity().getClass().getName(); if ("com.google.android.gms.ads.AdActivity".equals(activityName)) { onWebView().check(webMatches(getCurrentUrl(), containsString("pubads.g.doubleclick.net/gampad/ads"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); Thread.sleep(30000); assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); } else if ("org.prebid.mobile.app.DemoActivity".equals(activityName)) { assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but DFP interstitial not loaded and show successfully"); } else { fail("Demo app not working properly."); } }
Example 3
Source File: URLAutocompleteTest.java From focus-android with Mozilla Public License 2.0 | 6 votes |
@Ignore @Test // add custom autocompletion site, but disable autocomplete public void DisableCCwithSiteTest() throws UiObjectNotFoundException { OpenCustomCompleteDialog(); addAutoComplete(site); Espresso.pressBack(); toggleCustomAC(); // Custom autocomplete is now off Espresso.pressBack(); Espresso.pressBack(); Espresso.pressBack(); checkACOff(site.substring(0, 3)); // Now enable autocomplete OpenCustomCompleteDialog(); toggleCustomAC(); // Custom autocomplete is now on Espresso.pressBack(); Espresso.pressBack(); Espresso.pressBack(); // Check autocompletion checkACOn(site); // Cleanup OpenCustomCompleteDialog(); removeACSite(); }
Example 4
Source File: DFPInterstitialTest.java From prebid-mobile-android with Apache License 2.0 | 5 votes |
@Test public void testDFPInterstitialWithAutoRefresh() throws Exception { onView(withId(R.id.adTypeSpinner)).perform(click()); onData(allOf(is(instanceOf(String.class)), is("Interstitial"))).perform(click()); onView(withId(R.id.autoRefreshInput)).perform(typeText("30000")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); String activityName = TestUtil.getCurrentActivity().getClass().getName(); if ("com.google.android.gms.ads.AdActivity".equals(activityName)) { onWebView().check(webMatches(getCurrentUrl(), containsString("pubads.g.doubleclick.net/gampad/ads"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); Thread.sleep(30000); activityName = TestUtil.getCurrentActivity().getClass().getName(); if ("com.google.android.gms.ads.AdActivity".equals(activityName)) { onWebView().check(webMatches(getCurrentUrl(), containsString("pubads.g.doubleclick.net/gampad/ads"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); assertEquals("Auto refresh not happening", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); ((DemoActivity) TestUtil.getCurrentActivity()).stopAutoRefresh(); Thread.sleep(30000); assertEquals("Auto refresh didn't stop", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); } else if ("org.prebid.mobile.app.DemoActivity".equals(activityName)) { assertEquals("Auto refresh not happening", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but DFP interstitial not loaded and show successfully"); } else { fail("Demo app not working properly."); } } else if ("org.prebid.mobile.app.DemoActivity".equals(activityName)) { assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but DFP interstitial not loaded and show successfully"); } else { fail("Demo app not working properly."); } }
Example 5
Source File: MoPubInterstitialTest.java From prebid-mobile-android with Apache License 2.0 | 5 votes |
@Test public void testMoPubInterstitialWithAutoRefresh() throws Exception { onView(withId(R.id.adTypeSpinner)).perform(click()); onData(allOf(is(instanceOf(String.class)), is("Interstitial"))).perform(click()); onView(withId(R.id.adServerSpinner)).perform(click()); onData(allOf(is(instanceOf(String.class)), is("MoPub"))).perform(click()); onView(withId(R.id.autoRefreshInput)).perform(typeText("30000")); onView(withId(R.id.showAd)).perform(click()); Thread.sleep(10000); String activityName = TestUtil.getCurrentActivity().getClass().getName(); if ("com.mopub.mobileads.MoPubActivity".equals(activityName)) { onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); assertEquals(1, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); Thread.sleep(30000); activityName = TestUtil.getCurrentActivity().getClass().getName(); if ("com.mopub.mobileads.MoPubActivity".equals(activityName)) { onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com"))); onWebView().check(webContent(containingTextInBody("ucTag.renderAd"))); Espresso.pressBack(); assertEquals("Auto refresh not happening", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); ((DemoActivity) TestUtil.getCurrentActivity()).stopAutoRefresh(); Thread.sleep(30000); assertEquals("Auto refresh didn't stop", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); } else if ("org.prebid.mobile.app.DemoActivity".equals(activityName)) { assertEquals("Auto refresh not happening", 2, ((DemoActivity) TestUtil.getCurrentActivity()).refreshCount); assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but MoPub interstitial not loaded and show successfully"); } else { fail("Demo app not working properly"); } } else if ("org.prebid.mobile.app.DemoActivity".equals(activityName)) { assertEquals(ResultCode.SUCCESS, ((DemoActivity) TestUtil.getCurrentActivity()).resultCode); fail("Prebid Demand was fetched successfully, but MoPub interstitial not loaded and show successfully"); } else { fail("Demo app not working properly"); } }
Example 6
Source File: BarricadeActivityTest.java From Barricade with Apache License 2.0 | 5 votes |
@Test public void verifyResponsesForEndpoints() { int endpointCount = 0; Map<String, BarricadeResponseSet> hashMap = barricade.getConfig(); for (String endpoint : hashMap.keySet()) { int responseCount = 0; onView(withId(R.id.endpoint_rv)).perform(RecyclerViewActions.actionOnItemAtPosition(endpointCount, click())); for (BarricadeResponse response : hashMap.get(endpoint).responses) { onView(withRecyclerView(com.mutualmobile.barricade.R.id.endpoint_responses_rv).atPosition(responseCount)).check( matches(hasDescendant(withText(response.responseFileName)))); responseCount++; } Espresso.pressBack(); } }
Example 7
Source File: RestoreSearchQueryListFragmentTest.java From Kore with Apache License 2.0 | 5 votes |
/** * Test if search query is restored when user returns to list fragment from * detail fragment when device is rotated while on detail fragment * * UI interaction flow tested: * 1. Enter search query * 2. Click on list item * 3. Rotate device * 4. Press back * 5. Result: search query entered at 1. should be restored in search field */ @Test public void searchClickRotateBackTest() { EspressoTestUtils.clearSearchQuery(mActivityRule.getActivity()); EspressoTestUtils.enterSearchQuery(mActivityRule.getActivity(), SEARCH_QUERY); EspressoTestUtils.clickRecyclerViewItem(0, R.id.list); EspressoTestUtils.rotateDevice(mActivityRule.getActivity()); Espresso.pressBack(); EspressoTestUtils.checkTextInSearchQuery(SEARCH_QUERY); EspressoTestUtils.checkListMatchesSearchQuery(SEARCH_QUERY, SEARCH_QUERY_LIST_SIZE, R.id.list); }
Example 8
Source File: MusicActivityTests.java From Kore with Apache License 2.0 | 5 votes |
/** * Test if navigation icon is changed to an arrow when selecting a list item * * UI interaction flow tested: * 1. Click on list item * 2. Press back * 3. Result: navigation icon should be a hamburger */ @Test public void showHamburgerWhenSelectingListItemAndReturn() { EspressoTestUtils.clickRecyclerViewItem(ArtistTestData.title, R.id.list); Espresso.pressBack(); assertFalse(getActivity().getDrawerIndicatorIsArrow()); }
Example 9
Source File: CustomTabTest.java From focus-android with Mozilla Public License 2.0 | 4 votes |
@Test public void testCustomTabUI() { try { startWebServer(); // Launch activity with custom tabs intent activityTestRule.launchActivity(createCustomTabIntent()); // Wait for website to load Context appContext = InstrumentationRegistry.getInstrumentation() .getTargetContext() .getApplicationContext(); if (!AppConstants.INSTANCE.isGeckoBuild()) { onWebView() .withElement(findElement(Locator.ID, TEST_PAGE_HEADER_ID)) .check(webMatches(getText(), equalTo(TEST_PAGE_HEADER_TEXT))); } // Verify action button is visible onView(withContentDescription(ACTION_BUTTON_DESCRIPTION)) .check(matches(isDisplayed())); // Open menu onView(withId(R.id.menuView)) .perform(click()); // Verify share action is visible onView(withId(R.id.share)) .check(matches(isDisplayed())); // Verify custom menu item is visible onView(withText(MENU_ITEM_LABEL)) .check(matches(isDisplayed())); // Close the menu again Espresso.pressBack(); // Verify close button is visible - Click it to close custom tab. onView(withId(R.id.customtab_close)) .check(matches(isDisplayed())) .perform(click()); } finally { stopWebServer(); } }
Example 10
Source File: LogInScreenInteractor.java From edx-app-android with Apache License 2.0 | 4 votes |
public LandingScreenInteractor navigateBack() { Espresso.pressBack(); return new LandingScreenInteractor(); }
Example 11
Source File: RestoreSearchQueryListFragmentTest.java From Kore with Apache License 2.0 | 3 votes |
/** * Test if after restoring search query the search query is cleared * when user presses back again. * * UI interaction flow tested * 1. Enter search query * 2. Click on list item * 3. Return to list * 4. Press back * 7. Result: search query should be cleared, collapsed, and list should show everything */ @Test public void searchClickBackBackTest() { EspressoTestUtils.enterSearchQuery(mActivityRule.getActivity(), SEARCH_QUERY); EspressoTestUtils.clickRecyclerViewItem(0, R.id.list); Espresso.pressBack(); Espresso.pressBack(); EspressoTestUtils.checkSearchMenuCollapsed(); EspressoTestUtils.checkListMatchesSearchQuery("", COMPLETE_LIST_SIZE, R.id.list); }
Example 12
Source File: RestoreSearchQueryListFragmentTest.java From Kore with Apache License 2.0 | 3 votes |
/** * Test if saved search query is cleared when user clears the * search query view * * UI interaction flow tested * 1. Enter search query * 2. Click on list item * 3. Return to list * 4. Clear search query * 5. Click on list item * 6. Return to list * 7. Result: search query should be empty and collapsed */ @Test public void searchClickBackClearSearchClickBackTest() { EspressoTestUtils.enterSearchQuery(mActivityRule.getActivity(), SEARCH_QUERY); EspressoTestUtils.clickRecyclerViewItem(0, R.id.list); Espresso.pressBack(); EspressoTestUtils.clearSearchQuery(mActivityRule.getActivity()); EspressoTestUtils.clickRecyclerViewItem(0, R.id.list); Espresso.pressBack(); EspressoTestUtils.checkSearchMenuCollapsed(); }
Example 13
Source File: MusicActivityTests.java From Kore with Apache License 2.0 | 3 votes |
/** * Test if navigation icon is restored to an hamburger when selecting a list item * and rotating the device and returning to the list * * UI interaction flow tested: * 1. Click on list item * 2. Rotate device * 3. Press back * 4. Result: navigation icon should be a hamburger */ @Test public void restoreHamburgerOnConfigurationChangeOnReturn() { EspressoTestUtils.clickRecyclerViewItem(ArtistTestData.title, R.id.list); rotateDevice(getActivity()); Espresso.pressBack(); assertTrue(EspressoTestUtils.getActivity() instanceof MusicActivity); assertFalse(((MusicActivity) EspressoTestUtils.getActivity()).getDrawerIndicatorIsArrow()); }
Example 14
Source File: RestoreSearchQueryViewPagerTest.java From Kore with Apache License 2.0 | 3 votes |
/** * Test if search query is restored when user returns to list fragment from * detail fragment when device is rotated while on detail fragment * * UI interaction flow tested: * 1. Enter search query * 2. Click on list item * 3. Rotate device * 4. Press back * 5. Result: search query entered at 1. should be restored in search field */ @Test public void searchClickRotateBackTest() { EspressoTestUtils.enterSearchQuery(mActivityRule.getActivity(), ARTIST_SEARCH_QUERY); EspressoTestUtils.clickRecyclerViewItem(ARTIST_MATCHING_SEARCH_QUERY, R.id.list); EspressoTestUtils.rotateDevice(mActivityRule.getActivity()); Espresso.pressBack(); EspressoTestUtils.checkTextInSearchQuery(ARTIST_SEARCH_QUERY); EspressoTestUtils.checkListMatchesSearchQuery(ARTIST_SEARCH_QUERY, ARTIST_SEARCH_QUERY_LIST_SIZE, R.id.list); }
Example 15
Source File: TVShowsActivityTests.java From Kore with Apache License 2.0 | 3 votes |
/** * Test if navigation icon is restored to an hamburger when selecting a list item * and rotating the device and returning to the list * * UI interaction flow tested: * 1. Click on list item * 2. Rotate device * 3. Press back * 4. Result: navigation icon should be a hamburger */ @Test public void restoreHamburgerOnConfigurationChangeOnReturn() { clickRecyclerViewItem(0, R.id.list); rotateDevice(getActivity()); Espresso.pressBack(); assertTrue(EspressoTestUtils.getActivity() instanceof TVShowsActivity); assertFalse(((TVShowsActivity) EspressoTestUtils.getActivity()).getDrawerIndicatorIsArrow()); }
Example 16
Source File: RestoreSearchQueryListFragmentTest.java From Kore with Apache License 2.0 | 3 votes |
/** * Test if pressing back clears a previous search * * UI interaction flow tested * 1. Enter search query * 2. Press back * 3. Result: search query should be cleared, collapsed, and list should show everything */ @Test public void searchBackTest() { EspressoTestUtils.enterSearchQuery(mActivityRule.getActivity(), SEARCH_QUERY); Espresso.pressBack(); EspressoTestUtils.checkSearchMenuCollapsed(); EspressoTestUtils.checkListMatchesSearchQuery("", COMPLETE_LIST_SIZE, R.id.list); }
Example 17
Source File: RestoreSearchQueryListFragmentTest.java From Kore with Apache License 2.0 | 3 votes |
/** * Test if after restoring the search query pressing home button up clears a previous search * * UI interaction flow tested * 1. Enter search query * 2. Click on list item * 3. Press back * 4. Press home button * 5. Result: search query should be cleared, collapsed, and list should show everything */ @Test public void searchClickBackUpTest() { EspressoTestUtils.enterSearchQuery(mActivityRule.getActivity(), SEARCH_QUERY); EspressoTestUtils.clickRecyclerViewItem(0, R.id.list); Espresso.pressBack(); EspressoTestUtils.clickToolbarCollapseButton(); EspressoTestUtils.checkSearchMenuCollapsed(); EspressoTestUtils.checkListMatchesSearchQuery("", COMPLETE_LIST_SIZE, R.id.list); }
Example 18
Source File: MoviesActivityTests.java From Kore with Apache License 2.0 | 3 votes |
/** * Test if navigation icon is restored to an hamburger when selecting a list item * and rotating the device and returning to the list * * UI interaction flow tested: * 1. Click on list item * 2. Rotate device * 3. Press back * 4. Result: navigation icon should be a hamburger */ @Test public void restoreHamburgerOnConfigurationChangeOnReturn() { clickRecyclerViewItem(0, R.id.list); rotateDevice(getActivity()); Espresso.pressBack(); assertTrue(EspressoTestUtils.getActivity() instanceof MoviesActivity); assertFalse(((MoviesActivity) EspressoTestUtils.getActivity()).getDrawerIndicatorIsArrow()); }
Example 19
Source File: AddonsActivityTests.java From Kore with Apache License 2.0 | 3 votes |
/** * Test if navigation icon is changed to an arrow when selecting a list item * * UI interaction flow tested: * 1. Click on list item * 2. Press back * 3. Result: navigation icon should be a hamburger */ @Test public void showHamburgerWhenSelectingListItemAndReturn() { clickRecyclerViewItem(0, R.id.list); Espresso.pressBack(); assertFalse(getActivity().getDrawerIndicatorIsArrow()); }
Example 20
Source File: MoviesActivityTests.java From Kore with Apache License 2.0 | 3 votes |
/** * Test if navigation icon is changed to an arrow when selecting a list item * * UI interaction flow tested: * 1. Click on list item * 2. Press back * 3. Result: navigation icon should be a hamburger */ @Test public void showHamburgerWhenSelectingListItemAndReturn() { clickRecyclerViewItem(0, R.id.list); Espresso.pressBack(); assertFalse(getActivity().getDrawerIndicatorIsArrow()); }