Issue
I am trying to write a Expresso Test on Android to validate the TextView content. When I read the text from resources as below it works
@Test
public void changeText_newActivity() {
onView(withId(R.id.mainContent)).check(matches(withText("Hello World!")));
}
The above is the test using espresso Below is the code on android activity where it works
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mainContent"
android:text="@string/hello_world"
/>
But When I replace the text using hardcoded text instead of referencing to the resources the test fails and getting the error unable to find the view in the view hierarchy
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mainContent"
android:text="Hello world!"
/>
Below is the error when I run the test
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with text: is "Hello world!"
Appreciated your help in advance.
Solution
Code "Hello world!"
^
Test "Hello World!"
See the difference? W and w are not the same.
Espresso rightfully cannot find such a view, because there is none mathing.
Answered By - azizbekian
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.