--
You received this message because you are subscribed to the Google Groups "Android Testing Support Library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-testing-suppo...@googlegroups.com.
To post to this group, send email to android-testing...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-testing-support-library/7eeb2422-b2f6-41d3-9ff6-2ad1cf5df056%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
@Testpublic void testAtPositionInTableMatcher() {onView(atPositionInTable(0,0)).check(matches(withText("0,0")));onView(atPositionInTable(0,1)).check(matches(withText("0,1")));onView(atPositionInTable(1,0)).check(matches(withText("1,0")));onView(atPositionInTable(1,1)).check(matches(withText("1,1")));onView(atPositionInTable(1,2)).check(doesNotExist());}
static Matcher<View> atPositionInTable(final int x, final int y) {return new TypeSafeMatcher<View>(){@Overridepublic void describeTo(Description description) {description.appendText("is at position # " + x + " , " + y);}@Overridepublic boolean matchesSafely(View view) {ViewParent viewParent = view.getParent();if (!(viewParent instanceof TableRow)) {return false;}TableRow row = (TableRow) viewParent;TableLayout table = (TableLayout) row.getParent();if (table.indexOfChild(row) != y)return false;if (row.indexOfChild(view) == x)return true;elsereturn false;}};}
Hey Ewan,TableRows are Views. You can create your custom matcher to do something like atPositionInTable(x,y). Check out the hasSibling matcher for exampleand the custom matcher sample---Also, if you Google your problem:the first result has a working matcher :)
On 21 October 2015 at 16:11, Ewan <ew...@telesense.co.uk> wrote:
Hi,I wondered if anyone has ideas about using Espresso on tables. The views in each TableRow may well have shared ids; so if, for instance, you wanted to test the string in a TextView in the third column of the first row of the table, I don't think there's an easy way to do this. The TableRows aren't views themselves, is there another approach than to tag each view in the table with a composite object which encapsulated row and column info and then write appropriate Matcher<View> instances to match given 'cells' in the table (yuk..)?Any thoughts?Cheers
Ewan
--
You received this message because you are subscribed to the Google Groups "Android Testing Support Library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-testing-support-library+unsubscribe@googlegroups.com.
To post to this group, send email to android-testing-support-lib...@googlegroups.com.