Ich habe ein Fragmant, dass ein CoordinatorLayout
mit zwei Kindern enthält: eine MapView
(Google Maps API) & ein RelativeLayout
, das letzte Layout einige Schaltflächen enthält, die ich mit Espresso
testen möchten.kann nicht Blick in Bodenblech mit Espresso finden
Also hier ist mein 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())
}
Und hier mein Layout ist (ich habe alle Layout bezogenen Parameter für die Sichtbarkeit entfernt):
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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>
ich folgende Fehlermeldung erhalten, wenn mein instrumentierten Test starten :
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)
Ist das, weil mein Knopf in einem unteren Blatt ist? Warum kann ich diese Ansicht nicht finden?
Dies scheint ein Schritt nach oben zu sein, danke, aber ich bekomme den folgenden Fehler: > Fehler beim Ausführen 'einzelner Klick' auf Ansicht 'Animationen oder Übergänge sind auf dem Zielgerät aktiviert. nach dem Ersetzen von 'isDsplayed()' mit dem, was Sie freigegeben haben. – Christopher
@Christopher achten Sie darauf, [Einrichten Ihrer Testumgebung] (https://developer.android.com/training/testing/espresso/setup.html#set-up-environment) auf 'Auf Ihrem Gerät, unter Einstellungen> Entwickleroptionen, Einstellungen deaktivieren: 'und Sie müssen' miteffektiver Sichtbarkeit' verwenden, wenn Ihre Zielansichten nicht auf dem Bildschirm angezeigt werden –