找到視圖底部片我有一個包含CoordinatorLayout
有兩個孩子一個Fragmant:一個MapView
(谷歌地圖API)&一個RelativeLayout
,這最後的佈局包含一些按鈕,我想用Espresso
測試。無法與咖啡
因此,這裏是我的測試:
@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())
}
這裏是我的佈局(我已刪除的知名度所有的佈局相關的參數):
推出我的儀器測試時,我得到以下錯誤:
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)
是因爲我的按鈕位於底部工作表?爲什麼我找不到這個觀點?
這似乎是一個步驟上,謝謝,但我得到了以下錯誤: >錯誤執行「一次點擊」視圖上「動畫或者在目標設備上啓用轉換。 用您共享的內容替換'isDsplayed()'後。 – Christopher
@Christopher確保遵循[設置您的測試環境](https://developer.android.com/training/testing/espresso/setup.html#set-up-environment)到'在您的設備上,在設置>開發人員選項,禁用設置:',並且當您的目標視圖在屏幕上不可見時,您需要使用'withEffectiveVisibility' –