-
-
Save dongdaqing/a400da0337e7636b5811 to your computer and use it in GitHub Desktop.
Revisions
-
cpeppas revised this gist
Oct 17, 2014 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,11 @@ public boolean matchesSafely(View view) { Usage: import static com.octo.android.sample.espresso.test.CustomMatchers.withResourceName; ...//Your TestEspressoClass public void testActionBarTitleForScreenOneActivity() { onView(allOf(isDescendantOfA(withResourceName("android:id/action_bar_container")), withText("My Activity"))) .check(matches(isDisplayed())); -
cpeppas created this gist
Oct 17, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ import android.view.View; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; import static org.hamcrest.Matchers.is; public class CustomMatchers { public static Matcher<View> withResourceName(String resourceName) { return withResourceName(is(resourceName)); } public static Matcher<View> withResourceName(final Matcher<String> resourceNameMatcher) { return new TypeSafeMatcher<View>() { @Override public void describeTo(Description description) { description.appendText("with resource name: "); resourceNameMatcher.describeTo(description); } @Override public boolean matchesSafely(View view) { int id = view.getId(); return id != View.NO_ID && id != 0 && view.getResources() != null && resourceNameMatcher.matches(view.getResources().getResourceName(id)); } }; } } Usage: public void testActionBarTitleForScreenOneActivity() { onView(allOf(isDescendantOfA(withResourceName("android:id/action_bar_container")), withText("My Activity"))) .check(matches(isDisplayed())); }