tm1*_*701 3 android android-espresso
Espresso如何点击长选项菜单中尚未显示的(选项)菜单项?
打开选项菜单很简单:
openActionBarOverflowOrOptionsMenu( getInstrumentation().getTargetContext());
Run Code Online (Sandbox Code Playgroud)
我试过例如scrollTo,但它没有成功:
onView( withText("Option menu item text")).perform( scrollTo(), click());
onView( withText( R.id.optionMenuId)).perform( scrollTo(), click());
onView( withId( is( R.id.appOptionMenu))).perform( swipeDown()); // where SwipeDown is a simple utility method on GeneralSwipeAction.
onData( anything()).inAdapterView( withId(R.id.wpeOptionMenu)).atPosition( 12).perform(click()); // I guess because it is not an adapter
Run Code Online (Sandbox Code Playgroud)
你有一个很好的解决方案吗?
ActionBar溢出菜单是一个包含ListView的PopUpWindow.
scrollTo()仅适用于ScrollView的后代,因此在此处不起作用.
因为您想要的视图位于AdapterView中,所以您需要使用onData.
数据对象是AdapterView,类型为MenuItem,您希望匹配Menu项的标题.像这样的东西:
onData(allOf(instanceOf(MenuItem.class), withTitle(title))).perform(click());
static MenuItemTitleMatcher withTitle(String title) {
return new MenuItemTitleMatcher(title);
}
class MenuItemTitleMatcher extends BaseMatcher<Object> {
private final String title;
public MenuItemTitleMatcher(String title) { this.title = title; }
@Override public boolean matches(Object o) {
if (o instanceof MenuItem) {
return ((MenuItem) o).getTitle().equals(title);
}
return false;
}
@Override public void describeTo(Description description) { }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1690 次 |
| 最近记录: |