我有下面的咖啡測試:咖啡:調用openActionBarOverflowOrOptionsMenu()在菜單中打開的第一個項目
openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getTargetContext());
// if I Thread.sleep() here, I can see that the MenuItem has been clicked already
onView(withText("Sign in")) //<= click on the MenuItem
.perform(click());
onView(withId(R.id.signupButton)) //<= click the signup button in my UI
.perform(click());
第一行那裏打開溢出菜單,並在同一時間點擊第一項(其中恰好是簽名項目)。所以測試失敗,因爲它找不到MenuItem視圖。有什麼我做錯了嗎?我正在使用模擬器API 22,編譯targetSdk 24並使用espresso 2.2.1。
我想你正在測試類中使用ActivityTest規則。請嘗試使用'openActionBarOverflowOrOptionsMenu(mActivityRule.getActivity());' – piotrek1543
同樣的問題:-( – mbonnin