androidx.test.espresso.Espresso Java Examples
The following examples show how to use
androidx.test.espresso.Espresso.
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: AuthenticatorActivityTest.java From google-authenticator-android with Apache License 2.0 | 6 votes |
@TargetApi(11) private static void openListViewContextualActionBarAndInvokeItem( AuthenticatorActivity activity, final ListView listView, final int position, final int menuItemId) { ActionMode actionMode = (ActionMode) openListViewContextualActionBar(activity, listView, position); MenuItem menuItem = actionMode.getMenu().findItem(menuItemId); try { onView(withContentDescription(menuItem.getTitle().toString())).perform(click()); } catch (NoMatchingViewException e) { // Might be in the overflow menu Espresso.openActionBarOverflowOrOptionsMenu(activity); onView(withText(menuItem.getTitle().toString())).perform(click()); } }
Example #2
Source File: TrafficPluginTest.java From mapbox-plugins-android with BSD 2-Clause "Simplified" License | 6 votes |
@Before public void beforeTest() { try { Timber.e("@Before: register idle resource"); idlingResource = new OnMapReadyIdlingResource(rule.getActivity()); Espresso.registerIdlingResources(idlingResource); onView(withId(android.R.id.content)).check(matches(isDisplayed())); mapboxMap = idlingResource.getMapboxMap(); trafficPlugin = rule.getActivity().getTrafficPlugin(); } catch (IdlingResourceTimeoutException idlingResourceTimeoutException) { Timber.e("Idling resource timed out. Couldn't not validate if map is ready."); throw new RuntimeException("Could not start executeTrafficTest for " + this.getClass().getSimpleName() + ".\n" + "The ViewHierarchy doesn't contain a view with resource id = R.id.mapView or \n" + "the Activity doesn't contain an instance variable with a name equal to mapboxMap.\n"); } }
Example #3
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 #4
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 #5
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 #6
Source File: URLAutocompleteTest.java From focus-android with Mozilla Public License 2.0 | 6 votes |
@Ignore @Test public void DuplicateACSiteTest() { OpenCustomCompleteDialog(); // Enable URL autocomplete, and tap Custom URL add button addAutoComplete(site); exitToTop(); // Try to add same site again OpenCustomCompleteDialog(); addAutoComplete(site, false); // Espresso cannot detect the "Already exists" popup. Instead, check that it's // still in the same page onView(withId(R.id.domainView)) .check(matches(isDisplayed())); onView(withId(R.id.save)) .check(matches(isDisplayed())); Espresso.pressBack(); Espresso.pressBack(); // Cleanup removeACSite(); Espresso.pressBack(); }
Example #7
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @MediumTest public void testSwipeDownToHide() { Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .perform( DesignViewActions.withCustomConstraints( ViewActions.swipeDown(), ViewMatchers.isDisplayingAtLeast(5))); registerIdlingResourceCallback(); try { Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .check(ViewAssertions.matches(not(ViewMatchers.isDisplayed()))); assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_HIDDEN)); } finally { unregisterIdlingResourceCallback(); } }
Example #8
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @MediumTest public void testSwipeUpToExpand() { Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .perform( DesignViewActions.withCustomConstraints( new GeneralSwipeAction( Swipe.FAST, GeneralLocation.VISIBLE_CENTER, view -> new float[] {view.getWidth() / 2, 0}, Press.FINGER), ViewMatchers.isDisplayingAtLeast(5))); registerIdlingResourceCallback(); try { Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())); assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED)); } finally { unregisterIdlingResourceCallback(); } }
Example #9
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @MediumTest public void testNoDragging() { getBehavior().setDraggable(false); Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) // Drag (and not release) .perform( new DragAction( GeneralLocation.VISIBLE_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER)) // Check that the bottom sheet is NOT in STATE_DRAGGING .check( (view, e) -> { assertThat(view, is(ViewMatchers.isDisplayed())); BottomSheetBehavior<?> behavior = BottomSheetBehavior.from(view); assertThat(behavior.getState(), not(is(BottomSheetBehavior.STATE_DRAGGING))); }); }
Example #10
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @MediumTest public void testHalfExpandedToExpanded() throws Throwable { getBehavior().setFitToContents(false); checkSetState(BottomSheetBehavior.STATE_HALF_EXPANDED, ViewMatchers.isDisplayed()); Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .perform( DesignViewActions.withCustomConstraints( new GeneralSwipeAction( Swipe.FAST, GeneralLocation.VISIBLE_CENTER, view -> new float[] {view.getWidth() / 2, 0}, Press.FINGER), ViewMatchers.isDisplayingAtLeast(5))); registerIdlingResourceCallback(); try { Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())); assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED)); } finally { unregisterIdlingResourceCallback(); } }
Example #11
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @MediumTest public void testCollapsedToExpanded() throws Throwable { getBehavior().setFitToContents(false); checkSetState(BottomSheetBehavior.STATE_COLLAPSED, ViewMatchers.isDisplayed()); Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .perform( DesignViewActions.withCustomConstraints( new GeneralSwipeAction( Swipe.FAST, GeneralLocation.VISIBLE_CENTER, view -> new float[] {view.getWidth() / 2, 0}, Press.FINGER), ViewMatchers.isDisplayingAtLeast(5))); registerIdlingResourceCallback(); try { Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())); assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED)); } finally { unregisterIdlingResourceCallback(); } }
Example #12
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @MediumTest public void testNoSwipeUpToExpand() { getBehavior().setDraggable(false); Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .perform( DesignViewActions.withCustomConstraints( new GeneralSwipeAction( Swipe.FAST, GeneralLocation.VISIBLE_CENTER, view -> new float[] {view.getWidth() / 2, 0}, Press.FINGER), ViewMatchers.isDisplayingAtLeast(5))); Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())); assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED)); }
Example #13
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @MediumTest public void testInvisible() throws Throwable { // Make the bottomsheet invisible activityTestRule.runOnUiThread( () -> { getBottomSheet().setVisibility(View.INVISIBLE); assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED)); }); // Swipe up as if to expand it Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .perform( DesignViewActions.withCustomConstraints( new GeneralSwipeAction( Swipe.FAST, GeneralLocation.VISIBLE_CENTER, view -> new float[] {view.getWidth() / 2, 0}, Press.FINGER), not(ViewMatchers.isDisplayed()))); // Check that the bottom sheet stays the same collapsed state activityTestRule.runOnUiThread( () -> assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED))); }
Example #14
Source File: Sample2Tests.java From PdfViewPager with Apache License 2.0 | 6 votes |
@Test public void swipesPdfToLastPageAndBackWithNoCrashesWhenDownloadIsCompleted() { startActivity(); openActionBarMenu(); onView(withText(R.string.menu_sample2_txt)).perform(click()); onView(withId(R.id.btn_download)).perform(click()); idlingResource = new WaitIdlingResource(System.currentTimeMillis(), 1500); Espresso.registerIdlingResources(idlingResource); try { swipeToLastPage(); swipeToBeginning(); } catch (Exception ex) { fail("Remote PDF crashes when paging"); } }
Example #15
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @MediumTest public void testLayoutWhileDragging() { Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) // Drag (and not release) .perform( new DragAction( GeneralLocation.VISIBLE_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER)) // Check that the bottom sheet is in STATE_DRAGGING .check( (view, e) -> { assertThat(view, is(ViewMatchers.isDisplayed())); BottomSheetBehavior<?> behavior = BottomSheetBehavior.from(view); assertThat(behavior.getState(), is(BottomSheetBehavior.STATE_DRAGGING)); }) // Add a new view .perform(new AddViewAction(R.layout.frame_layout)) // Check that the newly added view is properly laid out .check( (view, e) -> { ViewGroup parent = (ViewGroup) view; assertThat(parent.getChildCount(), is(1)); View child = parent.getChildAt(0); assertThat(ViewCompat.isLaidOut(child), is(true)); }); }
Example #16
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test @MediumTest public void testDynamicContent() throws Throwable { registerIdlingResourceCallback(); try { activityTestRule.runOnUiThread( () -> { ViewGroup.LayoutParams params = getBottomSheet().getLayoutParams(); params.height = ViewGroup.LayoutParams.WRAP_CONTENT; getBottomSheet().setLayoutParams(params); View view = new View(getBottomSheet().getContext()); int size = getBehavior().getPeekHeight() * 2; getBottomSheet().addView(view, new ViewGroup.LayoutParams(size, size)); assertThat(getBottomSheet().getChildCount(), is(1)); // Shrink the content height. ViewGroup.LayoutParams lp = view.getLayoutParams(); lp.height = (int) (size * 0.8); view.setLayoutParams(lp); // Immediately expand the bottom sheet. getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED); }); Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())); assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_EXPANDED)); // Make sure that the bottom sheet is not floating above the bottom. assertThat(getBottomSheet().getBottom(), is(getCoordinatorLayout().getBottom())); } finally { unregisterIdlingResourceCallback(); } }
Example #17
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 #18
Source File: WindowAttachmentTest.java From screenshot-tests-for-android with Apache License 2.0 | 5 votes |
@Test public void testAReallyAttachedViewIsntAttacedAgain() throws Throwable { final View[] view = new View[1]; activityTestRule.getActivity(); InstrumentationRegistry.getInstrumentation() .runOnMainSync( new Runnable() { @Override public void run() { view[0] = new MyView(activityTestRule.getActivity()); activityTestRule.getActivity().setContentView(view[0]); } }); InstrumentationRegistry.getInstrumentation().waitForIdleSync(); // Call some espress method to make sure we're ready: Espresso.onView(withId(android.R.id.content)).perform(click()); mAttachedCalled = 0; mDetachedCalled = 0; WindowAttachment.Detacher detacher = WindowAttachment.dispatchAttach(view[0]); detacher.detach(); assertEquals(0, mAttachedCalled); assertEquals(0, mDetachedCalled); }
Example #19
Source File: BottomSheetDialogFragmentDismissTest.java From material-components-android with Apache License 2.0 | 5 votes |
@After public void tearDown() { if (dialogFragment != null && dialogFragment.getDialog() != null && dialogFragment.getDialog().isShowing()) { // Close the dialog Espresso.pressBack(); } }
Example #20
Source File: BottomSheetBehaviorTouchTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test public void testTouchCoordinatorLayout() { final CoordinatorLayoutActivity activity = activityTestRule.getActivity(); down = false; Espresso.onView(sameInstance((View) activity.mCoordinatorLayout)) .perform(ViewActions.click()) // Click outside the bottom sheet .check( (view, e) -> { assertThat(e, is(nullValue())); assertThat(view, is(notNullValue())); // Check that the touch event fell through to the container assertThat(down, is(true)); }); }
Example #21
Source File: BottomSheetDialogTest.java From material-components-android with Apache License 2.0 | 5 votes |
@After public void tearDown() { if (dialog != null && dialog.isShowing()) { // Close the dialog Espresso.pressBack(); } }
Example #22
Source File: Sample2Tests.java From PdfViewPager with Apache License 2.0 | 5 votes |
@Test public void showsPdfAfterDownload() { startActivity(); openActionBarMenu(); onView(withText(R.string.menu_sample2_txt)).perform(click()); onView(withId(R.id.btn_download)).perform(click()); idlingResource = new WaitIdlingResource(System.currentTimeMillis(), 1500); Espresso.registerIdlingResources(idlingResource); onView(withId(R.id.btn_download)).check(matches(isDisplayed())); onView(withId(R.id.pdfViewPager)).check(matches(isDisplayed())); }
Example #23
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 5 votes |
private void withFabVisibilityChange(boolean shown, Runnable action) { OnVisibilityChangedListener listener = new OnVisibilityChangedListener(shown); CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) activityTestRule.getActivity().mFab.getLayoutParams(); FloatingActionButton.Behavior behavior = (FloatingActionButton.Behavior) lp.getBehavior(); behavior.setInternalAutoHideListener(listener); Espresso.registerIdlingResources(listener); try { action.run(); } finally { Espresso.unregisterIdlingResources(listener); } }
Example #24
Source File: PFLockScreenFragmentAuthTest.java From PFLockScreen-Android with Apache License 2.0 | 5 votes |
@Test public void fragment_can_be_instantiated() { // Launch the activity to make the fragment visible mFragmentTestRule.launchActivity(null); // Then use Espresso to test the Fragment Espresso.onView(withId(R.id.fragment_pf)).check(matches(isDisplayed())); Espresso.onView(withId(R.id.button_finger_print)).check(matches(isDisplayed())); Espresso.onView(withId(R.id.button_delete)).check(matches(not(isDisplayed()))); Espresso.onView(withId(R.id.button_left)).check(matches(isDisplayed())); Espresso.onView(withId(R.id.button_next)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE))); Espresso.onView(withId(R.id.button_left)).check(matches(withText(LEFT_BUTTON))); for (int i = 0; i < CODE_LENGTH; i++) { Espresso.onView(withId(R.id.button_1)).perform(click()); Espresso.onView(withId(R.id.button_finger_print)).check(matches(not(isDisplayed()))); Espresso.onView(withId(R.id.button_delete)).check(matches(isDisplayed())); } for (int i = 0; i < CODE_LENGTH - 1; i++) { Espresso.onView(withId(R.id.button_delete)).perform(click()); Espresso.onView(withId(R.id.button_delete)).check(matches(isDisplayed())); Espresso.onView(withId(R.id.button_finger_print)).check(matches(not(isDisplayed()))); } Espresso.onView(withId(R.id.button_delete)).perform(click()); Espresso.onView(withId(R.id.button_finger_print)).check(matches(isDisplayed())); Espresso.onView(withId(R.id.button_delete)).check(matches(not(isDisplayed()))); Espresso.onView(withId(R.id.button_next)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.INVISIBLE))); }
Example #25
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test @MediumTest public void testDragOutside() { // Swipe up outside of the bottom sheet Espresso.onView(ViewMatchers.withId(R.id.coordinator)) .perform( DesignViewActions.withCustomConstraints( new GeneralSwipeAction( Swipe.FAST, // Just above the bottom sheet view -> new float[] { view.getWidth() / 2, view.getHeight() - getBehavior().getPeekHeight() - 9 }, // Top of the CoordinatorLayout view -> new float[] {view.getWidth() / 2, 1}, Press.FINGER), ViewMatchers.isDisplayed())); registerIdlingResourceCallback(); try { Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .check(ViewAssertions.matches(ViewMatchers.isDisplayed())); // The bottom sheet should remain collapsed assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED)); } finally { unregisterIdlingResourceCallback(); } }
Example #26
Source File: EspressoTestUtils.java From Kore with Apache License 2.0 | 5 votes |
/** * Clears the search query by pressing the X button * @param activity */ public static void clearSearchQueryXButton(Activity activity) { try { onView(withId(R.id.search_close_btn)).perform(click()); } catch (NoMatchingViewException e) { EspressoTestUtils.clickMenuItem(activity, activity.getString(R.string.action_search), R.id.action_search); onView(withId(R.id.search_close_btn)).perform(click()); } Espresso.closeSoftKeyboard(); }
Example #27
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Test @MediumTest public void testInvisibleThenVisible() throws Throwable { activityTestRule.runOnUiThread( () -> { // The bottom sheet is initially invisible getBottomSheet().setVisibility(View.INVISIBLE); // Then it becomes visible when the CoL is touched getCoordinatorLayout() .setOnTouchListener( (view, e) -> { if (e.getAction() == MotionEvent.ACTION_DOWN) { getBottomSheet().setVisibility(View.VISIBLE); return true; } return false; }); assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED)); }); // Drag over the CoL Espresso.onView(ViewMatchers.withId(R.id.coordinator)) // Drag (and not release) .perform( new DragAction(GeneralLocation.BOTTOM_CENTER, GeneralLocation.TOP_CENTER, Press.FINGER)) .check( (view, e) -> { // The bottom sheet should not react to the touch events assertThat(getBottomSheet(), is(ViewMatchers.isDisplayed())); assertThat(getBehavior().getState(), is(BottomSheetBehavior.STATE_COLLAPSED)); }); }
Example #28
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 #29
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 #30
Source File: BottomSheetBehaviorTest.java From material-components-android with Apache License 2.0 | 5 votes |
private void checkSetState(final int state, Matcher<View> matcher) throws Throwable { registerIdlingResourceCallback(); try { activityTestRule.runOnUiThread(() -> getBehavior().setState(state)); Espresso.onView(ViewMatchers.withId(R.id.bottom_sheet)) .check(ViewAssertions.matches(matcher)); assertThat(getBehavior().getState(), is(state)); assertAccessibilityActions(getBehavior(), getBottomSheet()); } finally { unregisterIdlingResourceCallback(); } }