I have a Fragmant that contains a CoordinatorLayout with two children: a MapView (Google Maps API) & a RelativeLayout, this last layout contains some buttons that I want to test using Espresso.
So here's my test:
@Test
fun randomButtonTest() {
try {
Thread.sleep(2000)
} catch (e: InterruptedException) {
e.printStackTrace()
}
// Find the button and perform a click
val appCompatImageButton = onView(
allOf(withId(R.id.random_poi), withContentDescription("Random Point of Interest"),
withParent(withId(R.id.design_bottom_sheet)),
isDisplayed()))
appCompatImageButton.perform(click())
}
And here is my layout (I have removed all layout related parameters for visibility):
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:app="http://ift.tt/GEGVYd"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"/>
<RelativeLayout
android:id="@+id/design_bottom_sheet"
app:behavior_hideable="true"
app:layout_behavior="@string/bottom_sheet_behavior">
<ImageButton
android:id="@+id/up_arrow" />
<ImageButton
android:id="@+id/random_poi"
android:contentDescription="@string/random_poi"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
I get the following error when launching my instrumented test:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with id: kade.com.accio:id/random_poi and with content description: is "Random Point of Interest" and has parent matching: with id: kade.com.accio:id/design_bottom_sheet and is displayed on the screen to the user)
Is that because my button is in a bottom sheet? Why can't I find this view?
Aucun commentaire:
Enregistrer un commentaire