gpt4 book ai didi

android - 如何使用 espresso 在 SearchView 上键入文本

转载 作者:太空狗 更新时间:2023-10-29 16:11:13 25 4
gpt4 key购买 nike

TypeText 似乎不适用于 SearchView

onView(withId(R.id.yt_search_box))
.perform(typeText("how is the weather?"));

给出错误:

Error performing 'type text(how is the weather?)' on view 'with id:../yt_search_box'

最佳答案

对于任何遇到这个问题的人来说,解决方案是为 SearchView 类型编写一个 ViewAction,因为 typeText 仅支持 TextEditView

这是我的解决方案:

public static ViewAction typeSearchViewText(final String text){
return new ViewAction(){
@Override
public Matcher<View> getConstraints() {
//Ensure that only apply if it is a SearchView and if it is visible.
return allOf(isDisplayed(), isAssignableFrom(SearchView.class));
}

@Override
public String getDescription() {
return "Change view text";
}

@Override
public void perform(UiController uiController, View view) {
((SearchView) view).setQuery(text,false);
}
};
}

关于android - 如何使用 espresso 在 SearchView 上键入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48037060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com