Testing EditText errors with Espresso on Android : <p>I want to test if an EditText field has an error (set with editText.setError("Cannot be blank!")).</p>

<p><a href="https://i.stack.imgur.com/fipqA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/fipqA.png" alt="EditText field with error"></a></p>

<p>I've created an Espresso test case with the new AndroidStudio 2.2 feature, to record Espresso tests. So the code is pretty much auto-generated. But for now it only checks if the editText is displayed.</p>

<pre><code>@RunWith(AndroidJUnit4.class)
public class CreateNoteActivityTitleCannotBeBlank {

    @Rule
    public ActivityTestRule&lt;CreateNoteActivity&gt; mActivityTestRule = new ActivityTestRule&lt;&gt;(CreateNoteActivity.class);

    @Test
    public void createNoteActivityTitleCannotBeBlank() {
        ViewInteraction floatingActionButton = onView(
                allOf(withId(R.id.fab_add_note),
                        withParent(allOf(withId(R.id.activity_create_note),
                                withParent(withId(android.R.id.content)))),
                        isDisplayed()));
        floatingActionButton.perform(click());

        ViewInteraction editText = onView(
                allOf(withId(R.id.tiet_note_title),
                        childAtPosition(
                                childAtPosition(
                                        withId(R.id.til_title),
                                        0),
                                0),
                        isDisplayed()));
        editText.check(matches(isDisplayed()));

    }

    private static Matcher&lt;View&gt; childAtPosition(
            final Matcher&lt;View&gt; parentMatcher, final int position) {

        return new TypeSafeMatcher&lt;View&gt;() {
            @Override
            public void describeTo(Description description) {
                description.appendText("Child at position " + position + " in parent ");
                parentMatcher.describeTo(description);
            }

            @Override
            public boolean matchesSafely(View view) {
                ViewParent parent = view.getParent();
                return parent instanceof ViewGroup &amp;&amp; parentMatcher.matches(parent)
                        &amp;&amp; view.equals(((ViewGroup) parent).getChildAt(position));
            }
        };
    }
}
</code></pre>

<p>Is there a way to test if the error is displayed?</p>
