浓缩咖啡-如何将typeText切换为英语或其他语言输入模式 [英] Espresso - how to switch typeText to English or other languages input mode

查看:136
本文介绍了浓缩咖啡-如何将typeText切换为英语或其他语言输入模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Espresso来实现我的应用程序的自动测试框架.但是在我设计的一些测试用例中,我发现测试始终失败,并且根本原因不在功能实现代码上的测试代码中.根本原因是在android输入法模式下,有时是在中文输入模式下,而我的输入文本是英文,那么输入值将失败.因此,我想知道如何将当前的typeText输入法模式从中文切换为英语,或者如何确保没有手动配置的输入法模式为英语? 我认为这是一项重要的要求,因为当我们在应用程序中支持多种语言时,我们需要此功能才能在测试过程中自动切换到所需的语言. 以下是我的代码,如果默认输入模式为英语,则没有任何问题.

I'm using Espresso to implement my application's autotest framework. But in some test-cases I've designed, I found my test always fail, and the root cause is not in my testing codes on feature implementation codes. The root cause is in the android input methods mode, sometimes, it's in Chinese input mode, and my input text is English, then the input value will fail. So I want to know how can I switch the current typeText input method mode from Chinese to English, or how could I ensure the input method mode is English without manual configuration? I believe this is an important requirement because when we support multiple languages in our applications, we need this feature to auto-switch to the needed language during testing. The following is my codes, it has no any problem if the default input mode is English.

    onView(withId(R.id.entryWordInput))
        .perform(typeText(entryWord), closeSoftKeyboard());
    onView(withId(R.id.OkButton))
        .perform(click());

谢谢.

推荐答案

使用Espresso更改输入模式语言是不可能的.您需要将其与另一个名为uiautomator的Google UI测试框架一起使用.

Using Espresso to change an input mode language is impossible. You need to use it with another Google UI testing framework called uiautomator.

请查看我在类似测试问题上的回答:浓缩咖啡测试通知出现

Please take a look at my answer at a similar test issue: Espresso test for Notification to showing up

Espresso UI测试框架所看到的并不比实际的视图多.我怀疑 认真对待,您可以使用Espresso查看任何通知.

Espresso UI test framework doesn't see more than actual View. I doubt seriously that you can check any notification with Espresso.

为此,请使用另一个Google的测试框架uiautomator, 描述为:

For this purpose use another Googles testing framework uiautomator, which is described as:

UI Automator是一个UI测试框架,适用于跨系统和已安装应用的跨应用功能UI测试.

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

Here you would find how to use it with Espresso: http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html

文档(II): http://developer.android.com/intl/es/training/testing/ui-testing/uiautomator-testing.html

还访问: Android测试:UIAutomator vs Espresso

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

So if you want to change language of input mode try to use both uiautomator to change Android System Preferences and Espresso for app tests.

希望有帮助.

这篇关于浓缩咖啡-如何将typeText切换为英语或其他语言输入模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆