我正在使用 Espresso 来实现我的应用程序的自动测试框架。但是在我设计的一些测试用例中,我发现我的测试总是失败,根本原因不在我的功能实现代码上的测试代码中。根本原因是在android输入法模式下,有时候是中文输入模式,而我输入的文字是英文,那么输入值就会失败。所以我想知道如何将当前的typeText输入法模式从中文切换为英文,或者如何在不手动配置的情况下确保输入法模式为英文? 我相信这是一个重要的要求,因为当我们在我们的应用程序中支持多种语言时,我们需要此功能在测试期间自动切换到所需的语言。 以下是我的代码,如果默认输入模式是英文,没有任何问题。
onView(withId(R.id.entryWordInput))
.perform(typeText(entryWord), closeSoftKeyboard());
onView(withId(R.id.OkButton))
.perform(click());
提前致谢。
最佳答案
使用 Espresso 更改输入模式语言是不可能的。您需要将它与另一个名为 uiautomator
的 Google UI 测试框架一起使用。
请看我在类似测试问题上的回答:Espresso test for Notification to showing up
Espresso UI test framework doesn't see more than actual View. I doubt seriously that you can check any notification with Espresso.
For this purpose use another Googles testing framework
uiautomator
, which is described as:UI Automator is a UI testing framework suitable for cross-app functional UI testing across system and installed apps.
在这里您可以找到如何将它与 Espresso 一起使用: http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html
更多信息:
因此,如果您想更改输入模式的语言,请尝试同时使用 uiautomator
更改 Android 系统偏好设置和使用 Espresso
进行应用测试。
希望对您有所帮助。
关于android - Espresso - 如何将 typeText 切换为英语或其他语言输入模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36382596/