Java Code Examples for android.support.test.espresso.FailureHandler

The following are top voted examples for showing how to use android.support.test.espresso.FailureHandler. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: espresso-macchiato   File: EspScreenshotFailureHandlerTest.java   View source code 6 votes vote down vote up
@Test
public void testForCoverage() {
    espScreenshotFailureHandler.delegate = new FailureHandler() {
        @Override
        public void handle(Throwable error, Matcher<View> viewMatcher) {
            // avoid that exception is thrown by default failure handler
        }
    };

    espScreenshotFailureHandler.handle(new TestException(), isRoot());
    File screenshot = new File(InstrumentationRegistry.getTargetContext().getFilesDir(), "test-screenshots/Failed-EspScreenshotFailureHandlerTest.testForCoverage.png");
    assertThat(screenshot.exists(), is(true));

    //noinspection ResultOfMethodCallIgnored
    screenshot.delete();
}
 
Example 2
Project: espresso-macchiato   File: EspScreenshotFailureHandlerTest.java   View source code 6 votes vote down vote up
@Test
public void testScreenshotFailure() {
    espScreenshotFailureHandler.delegate = new FailureHandler() {
        @Override
        public void handle(Throwable error, Matcher<View> viewMatcher) {
            // avoid that exception is thrown by default failure handler
            wasDelegateCalled = true;
        }
    };

    InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            espScreenshotFailureHandler.handle(new TestException(), isRoot());
        }
    });

    assertTrue(wasDelegateCalled);
}
 
Example 3
Project: spotify-tv   File: FailureScreenshotRule.java   View source code 5 votes vote down vote up
public void setupFailureHandler(Description description) {
    final String testClassName = description.getClassName();
    final String testMethodName = description.getMethodName();
    final Context context = InstrumentationRegistry.getTargetContext();
    Espresso.setFailureHandler(new FailureHandler() {
        @Override
        public void handle(Throwable throwable, Matcher<View> matcher) {
            SpoonScreenshotAction.perform("espresso_assertion_failed", testClassName, testMethodName);
            new DefaultFailureHandler(context).handle(throwable, matcher);
        }
    });
}
 
Example 4
Project: SecretSauce   File: SpoonTestRule.java   View source code 5 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description) {
    Espresso.setFailureHandler(new FailureHandler() {
        @Override
        public void handle(Throwable error, Matcher<View> viewMatcher) {
            Spoon.screenshot(SpoonTestRule.this.getActivity(), error.getClass().getSimpleName(), description.getClassName(), description.getMethodName());
            new DefaultFailureHandler(SpoonTestRule.this.getActivity()).handle(error, viewMatcher);
        }
    });
    return super.apply(base, description);
}
 
Example 5
Project: Ironhide   File: CustomFailureHandlerTest.java   View source code 5 votes vote down vote up
/** 
 * Replaces NoMatchingViewException with MySpecialException (to be caught in the test)
 */
@Override
public void onFailure(FailureHandler delegate, Throwable error, Matcher<View> viewMatcher) {
    try {
        delegate.handle(error, viewMatcher);
    } catch (NoMatchingViewException e) {
        throw new MySpecialException(e);
    }
}
 
Example 6
Project: BBQTimer   File: CustomMatchers.java   View source code 5 votes vote down vote up
/**
 * <b>Modifies the given ViewInteraction</b> to have a no-op FailureHandler. Use this, e.g.,
 * to perform an action on a View if it's visible and not complain if it isn't.
 *
 * @return the modified ViewInteraction
 */
static ViewInteraction ignoringFailures(@NonNull ViewInteraction interaction) {
    return interaction.withFailureHandler(new FailureHandler() {
        @Override
        public void handle(Throwable error, Matcher<View> viewMatcher) {
        }
    });
}
 
Example 7
Project: Ironhide   File: BaseInstrumentTestCase.java   View source code 4 votes vote down vote up
/** @see android.support.test.espresso.Espresso#setFailureHandler(android.support.test.espresso.FailureHandler) */
protected void onFailure(FailureHandler delegate, Throwable error, Matcher<View> viewMatcher) {
    delegate.handle(error, viewMatcher);
}