In the attached image above, it is a ListView having TextView (delivery report)
Its status can be 'Sent' or 'Sending' or 'Failed'
I want to check for 'Sent' condition which means assert message sent successfully
As it is a conversation, newer messages will be at the bottom of the listview.
What I've tried is...
// Type the message
ViewInteraction smsEditText = onView(withId(R.id.text_editor)).check(matches(isDisplayed()));
smsEditText.perform(typeText("abcde"));
closeSoftKeyboard();
Thread.sleep(500);
// Click on send Button
ViewInteraction smsSendButton = onView(withId(R.id.composebtnSend)).check(matches(isDisplayed()));
smsSendButton.check(matches(isEnabled()));
smsSendButton.perform(click());
Thread.sleep(3000);
// Assert for msg Sent delivery report
onData(anything()).inAdapterView(withId(R.id.history)).atPosition(2)
.onChildView(withId(R.id.timestamp)).check(matches(withText("Sent .")));
Position should be 'listAdapter.getCount()'
I know matches(withText("Sent . ") doesn't work because it is coming from server and I cannot hardCode delivery timeStamp.
onData(startsWith("Sent .")).inAdapterView(withId(R.id.history)).atPosition(????)
.onChildView(withId(R.id.timestamp)).
How to do this?
Update:
I tried this and stuck at asserting
final int[] count = new int[1];
onView(withId(R.id.history))
.check(matches(new TypeSafeMatcher<View>() {
@Override
protected boolean matchesSafely(View item) {
ListView listView = (ListView) item;
count[0] = listView.getAdapter().getCount();
return true;
}
@Override
public void describeTo(Description description) {
Log.d("ConversationListTest", "describeTo: " + description);
}
}));
onData(containsString("Sent . "))
.inAdapterView(withId(R.id.history))
.atPosition(count[0] - 1)
.onChildView(withId(R.id.timestamp))
.check(matches(isDisplayed()));
Assertion 'isDisplayed()' gives
android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'with id:history'.
Note : not adding 'check(matches(isDisplayed()))' passes my test
What should I use to assert it?