Dav*_*ord 5 unicode android-espresso
这是匹配文本字段并输入变量的简单命令name
。
private final String name = "foo";
onView(withId(R.id.editTextName)).perform(typeText(name));
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中使用“ foo”可以正常工作。然而:
private final String name = "á";
private final String name = "\u00E1";
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,该onView
行均会失败,归咎于无法在上一个活动的视图中找到视图:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: <myappid>:id/listViewAccounts
Run Code Online (Sandbox Code Playgroud)
Espresso似乎无法处理Unicode字符,如果要求输入Unicode字符,它将失败。它在带有“英语(美国)Android键盘(AOSP)”或“英语(美国)示例软键盘”的AVD上运行。后者还会使双字母变平,这可能是Espresso输入速度有多快的另一个问题。
有人遇到过吗?是Espresso,还是使用的键盘,还是其他?
我将Android软键盘更改为可以长按a
获取的US International键盘á
,但是Espresso同样失败。
更新:
使用á
确实会将其保留在堆栈跟踪中(但\u00E1
不会):
java.lang.RuntimeException: Failed to get key events for string á (i.e. current IME does not understand how to translate the string into key events). As a workaround, you can use replaceText action to set the text directly in the EditText field.
这样做可能值得,尽管它与实际用户交互的方式略有脱节。
onView(withId(R.id.editTextName)).perform(replaceText(name));
Run Code Online (Sandbox Code Playgroud)
切换typeText()
为replaceText()
允许输入其他字符。我不确定这是一个理想的解决方案,因为按键上可能存在未触发的事件,但是如果您只想测试这些字符串在内部是如何处理的,那么它可能没问题。
Espresso 明确建议解决方法。
归档时间: |
|
查看次数: |
832 次 |
最近记录: |