Java Code Examples for androidx.test.espresso.Espresso#unregisterIdlingResources()

The following examples show how to use androidx.test.espresso.Espresso#unregisterIdlingResources() . 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: EmailPasswordTest.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    if (mActivityResource != null) {
        Espresso.unregisterIdlingResources(mActivityResource);
    }

    // Register Activity as idling resource
    mActivityResource = new BaseActivityIdlingResource(mActivityTestRule.getActivity());
    Espresso.registerIdlingResources(mActivityResource);
}
 
Example 2
Source File: AnonymousTest.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    if (mActivityResource != null) {
        Espresso.unregisterIdlingResources(mActivityResource);
    }

    // Register Activity as idling resource
    mActivityResource = new BaseActivityIdlingResource(mActivityTestRule.getActivity());
    Espresso.registerIdlingResources(mActivityResource);
}
 
Example 3
Source File: MainActivityTest.java    From quickstart-android with Apache License 2.0 5 votes vote down vote up
@After
public void after() {
    // Release intents
    Intents.release();

    // Idling resource
    if (mUploadIdlingResource != null) {
        Espresso.unregisterIdlingResources(mUploadIdlingResource);
    }
}
 
Example 4
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
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 5
Source File: Sample2Tests.java    From PdfViewPager with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() {
    List<IdlingResource> idlingResources = Espresso.getIdlingResources();
    for (IdlingResource resource : idlingResources) {
        Espresso.unregisterIdlingResources(resource);
    }
}
 
Example 6
Source File: ViewPagerActions.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Override
public final void perform(UiController uiController, View view) {
  final ViewPager viewPager = (ViewPager) view;
  // Add a custom tracker listener
  final CustomViewPagerListener customListener = new CustomViewPagerListener();
  viewPager.addOnPageChangeListener(customListener);

  // Note that we're running the following block in a try-finally construct. This
  // is needed since some of the actions are going to throw (expected) exceptions. If that
  // happens, we still need to clean up after ourselves to leave the system (Espresso) in a good
  // state.
  try {
    // Register our listener as idling resource so that Espresso waits until the
    // wrapped action results in the view pager getting to the STATE_IDLE state
    Espresso.registerIdlingResources(customListener);

    uiController.loopMainThreadUntilIdle();

    performScroll((ViewPager) view);

    uiController.loopMainThreadUntilIdle();

    customListener.mNeedsIdle = true;
    uiController.loopMainThreadUntilIdle();
    customListener.mNeedsIdle = false;
  } finally {
    // Unregister our idling resource
    Espresso.unregisterIdlingResources(customListener);
    // And remove our tracker listener from ViewPager
    viewPager.removeOnPageChangeListener(customListener);
  }
}
 
Example 7
Source File: TrafficPluginTest.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@After
public void afterTest() {
  Timber.e("@After: unregister idle resource");
  Espresso.unregisterIdlingResources(idlingResource);
}
 
Example 8
Source File: EmailPasswordTest.java    From quickstart-android with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    if (mActivityResource != null) {
        Espresso.unregisterIdlingResources(mActivityResource);
    }
}
 
Example 9
Source File: AnonymousTest.java    From quickstart-android with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    if (mActivityResource != null) {
        Espresso.unregisterIdlingResources(mActivityResource);
    }
}
 
Example 10
Source File: BottomSheetBehaviorTest.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void unregisterIdlingResourceCallback() {
  if (callback != null) {
    Espresso.unregisterIdlingResources(callback);
    callback = null;
  }
}
 
Example 11
Source File: TabLayoutTest.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
private void testSetScrollPosition(final boolean isLtr) throws Throwable {
  activityTestRule.runOnUiThread(
      () -> activityTestRule.getActivity().setContentView(R.layout.design_tabs_fixed_width));
  final TabLayout tabs = activityTestRule.getActivity().findViewById(R.id.tabs);
  assertEquals(TabLayout.MODE_SCROLLABLE, tabs.getTabMode());

  final TabLayoutScrollIdlingResource idler = new TabLayoutScrollIdlingResource(tabs);
  Espresso.registerIdlingResources(idler);

  // We're going to call setScrollPosition() incrementally, as if scrolling between one tab
  // and the next. Use the middle tab for best results. The positionOffsets should be in the
  // range [0, 1), so the final call will wrap to 0 but use the next tab's position.
  final int middleTab = tabs.getTabCount() / 2;
  final int[] positions = {middleTab, middleTab, middleTab, middleTab, middleTab + 1};
  final float[] positionOffsets = {0f, .25f, .5f, .75f, 0f};

  // Set layout direction
  onView(withId(R.id.tabs))
      .perform(
          setLayoutDirection(
              isLtr ? ViewCompat.LAYOUT_DIRECTION_LTR : ViewCompat.LAYOUT_DIRECTION_RTL));
  // Make sure it's scrolled all the way to the start
  onView(withId(R.id.tabs)).perform(selectTab(0));

  // Perform a series of setScrollPosition() calls
  final AtomicInteger lastScrollX = new AtomicInteger(tabs.getScrollX());
  for (int i = 0; i < positions.length; i++) {
    onView(withId(R.id.tabs))
        .perform(setScrollPosition(positions[i], positionOffsets[i]))
        .check(
            (view, notFoundException) -> {
              if (view == null) {
                throw notFoundException;
              }
              // Verify increasing or decreasing scroll X values
              int sx = view.getScrollX();
              assertTrue(isLtr ? sx > lastScrollX.get() : sx < lastScrollX.get());
              lastScrollX.set(sx);
            });
  }

  Espresso.unregisterIdlingResources(idler);
}
 
Example 12
Source File: MoviesListingActivityTest.java    From MovieGuide with MIT License 4 votes vote down vote up
@After
public void unregisterIdlingResource() {
    if (idlingResource != null) {
        Espresso.unregisterIdlingResources(idlingResource);
    }
}