android - Espresso - 如何将 typeText 切换为英语或其他语言输入模式

标签 android android-testing ui-testing android-espresso

我正在使用 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

更多信息:

另请访问: Android Testing: UIAutomator vs Espresso

因此,如果您想更改输入模式的语言,请尝试同时使用 uiautomator 更改 Android 系统偏好设置和使用 Espresso 进行应用测试。

希望对您有所帮助。

关于android - Espresso - 如何将 typeText 切换为英语或其他语言输入模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36382596/

相关文章:

android - 是否可以使用 espresso 截屏并测试像素值?

coded-ui-tests - AAA 是编码 UI 测试的好习惯吗?

android - 自动检测链接抖动

java - 从 Android 设备 : Gutmann or others? 安全删除数据

android - Robolectric Android- 在 editTextField 上测试输入

ui-testing - UI 测试 xCode 7.3 - 无法在控制台 : (could not build Objective-C module 'po app' ) 中打印变量(即 'Bolts' )

android - 如何在 Android 测试用例中使用 jUnit 测试滑动/滑动事件

java - 通过 HDMI 或 USB 连接在 android 上接收音频和视频

android - 如何在 Android Studio 中运行所有风格的 Android 测试

android - 如何使用 Robolectric 测试 IntentService?