Skip to content

Instantly share code, notes, and snippets.

@engincancan
Created July 21, 2016 05:56
Show Gist options
  • Save engincancan/7e6b0b056dd77f9c562f460075e77e13 to your computer and use it in GitHub Desktop.
Save engincancan/7e6b0b056dd77f9c562f460075e77e13 to your computer and use it in GitHub Desktop.
EspressoCustomFailureHandler.java
//
//Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
//Espresso.setFailureHandler(new CustomFailureHandler(instrumentation));
public class CustomFailureHandler implements FailureHandler {
private final FailureHandler delegate;
public CustomFailureHandler(@NonNull Instrumentation instrumentation) {
delegate = new DefaultFailureHandler(instrumentation.getTargetContext());
}
@Override
public void handle(final Throwable error, final Matcher<View> viewMatcher) {
// Log anything you want here
// Then delegate the error handling to the default handler which will throw an exception
delegate.handle(error, viewMatcher);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment