TypeText
似乎不适用于SearchView
。
onView(withId(R.id.yt_search_box))
.perform(typeText("how is the weather?"));
给出错误:
使用ID:../ yt_search_box'在视图'上执行'输入文字(天气怎么样?)'时出错“
答案 0 :(得分:4)
对于遇到此问题的任何人来说,解决方案是为SearchView类型编写一个ViewAction,因为typeText只支持TextEditView
这是我的解决方案:
public final class User {
// These names don't matter since they are private, you could call it `glubustufo`
// They should always be private
private String mName;
private String mEmail;
// ...
// Constructors
// Methods should be public and use the get/set convention where the following
// words are in CamelCase and will be translated to lowerCamelCase in the db.
public String getName() { return mName; }
public void setName(String name) { mName = name; }
public String getEmail() { return mEmail; }
public void setEmail(String email) { mEmail = email; }
// equals, hashCode, toString
}
答案 1 :(得分:4)
@MiguelSlv上面的答案,转换为Kotlin
fun typeSearchViewText(text: String): ViewAction {
return object : ViewAction {
override fun getDescription(): String {
return "Change view text"
}
override fun getConstraints(): Matcher<View> {
return allOf(isDisplayed(), isAssignableFrom(SearchView::class.java))
}
override fun perform(uiController: UiController?, view: View?) {
(view as SearchView).setQuery(text, false)
}
}
}
答案 2 :(得分:0)
您可以使用Resource#getSystem获取视图
Resources.getSystem().getIdentifier("search_src_text",
"id", "android")
onView(withId(Resources.getSystem().getIdentifier("search_src_text",
"id", "android"))).perform(clearText(),typeText("enter the text"))
.perform(pressKey(KeyEvent.KEYCODE_ENTER))
答案 3 :(得分:-1)
这对我有用:
Eigen::ArrayXXf::Map( input_array , 3, 3).sqrt()