android.support.test.espresso.FailureHandler Java Examples
The following examples show how to use
android.support.test.espresso.FailureHandler.
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: EspScreenshotFailureHandlerTest.java From espresso-macchiato with MIT License | 6 votes |
@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
Source File: EspScreenshotFailureHandlerTest.java From espresso-macchiato with MIT License | 6 votes |
@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
Source File: SuntimesActivityTestBase.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
public static boolean viewIsDisplayed(int viewId, String text) { final boolean[] isDisplayed = {true}; Matcher<View> view = (text != null) ? allOf(withId(viewId), withText(containsString(text))) : withId(viewId); onView(view).withFailureHandler(new FailureHandler() { @Override public void handle(Throwable error, Matcher<View> viewMatcher) { isDisplayed[0] = false; } }).check(matches(isDisplayed())); return isDisplayed[0]; }
Example #4
Source File: SuntimesActivityTestBase.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
/** * @param viewInteraction a ViewInteraction wrapping some view * @return true view is checked, false otherwise */ public static boolean viewIsChecked(ViewInteraction viewInteraction) { final boolean[] isChecked = {true}; viewInteraction.withFailureHandler(new FailureHandler() { @Override public void handle(Throwable error, Matcher<View> viewMatcher) { isChecked[0] = false; } }).check(matches(isChecked())); return isChecked[0]; }
Example #5
Source File: SuntimesActivityTestBase.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
/** * @param spinnerId spinner ID * @param text text * @return true if spinner displays given text */ public static boolean spinnerDisplaysText(int spinnerId, String text) { final boolean[] displaysText = {true}; onView(withId(spinnerId)).withFailureHandler(new FailureHandler() { @Override public void handle(Throwable error, Matcher<View> viewMatcher) { displaysText[0] = false; } }).check(matches(withSpinnerText(text))); return displaysText[0]; }