android - Espresso 不会在 SearchView 上执行 typeText ViewAction
问题描述
我的代码如下所示:
onView(withId(R.id.search_view)).perform(click());
onView(withId(R.id.search_view)).perform(typeText(search_query));
出于某种原因,即使我看到搜索栏和键盘短暂显示并且目标视图是 SearchView,但我收到此错误:
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
((is displayed on the screen to the user) and (supports input methods or is assignable from class: class android.widget.SearchView))
Target view: "SearchView{id=2131362837, res-name=search_view, visibility=VISIBLE, width=1080, height=126, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@940faa7, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}"
解决方案
您收到运行时错误,因为您尝试执行typeText
不可SearchView
编辑的字段。SearchView只是一个LinearLayout
包含可编辑字段的简单字段,因此您应该将匹配器更改为:
onView(allOf(supportsInputMethods(), isDescendantOfA(withId(R.id.search_view))))
.perform(typeText(search_query));
推荐阅读
- php - Laravel 如果选项值 ==
- c - .c 扩展名与 .C 扩展名
- c# - ASP.NET Core MVC 本地化警告:AcceptLanguageHeaderRequestCultureProvider 返回了以下不受支持的文化
- java-8 - 如何在 JPQL 查询中从 LocalDate 获取月份?
- php - Laravel:主动监听来自外部服务的事件
- mongodb - 左加入 mongodb 不起作用
- bash - 将逗号分隔的数字字符串解析为变量(脚本)bash
- python - AttributeError:“系列”对象没有属性“翻译”
- android - Daily Usagestats files somehow updating the file's name
- c++ - initialization order of thread local variables