Espresso - how to switch typeText to English or other languages input mode

有些话、适合烂在心里 提交于 2020-05-14 22:44:31

问题


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());

Thanks in advance.


回答1:


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 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.

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

More information:
  • Documentation(I): https://google.github.io/android-testing-support-library/docs/uiautomator/index.html

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

Visit also: Android Testing: UIAutomator vs 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.

Hope it helps.



来源:https://stackoverflow.com/questions/36382596/espresso-how-to-switch-typetext-to-english-or-other-languages-input-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!