Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 525
Clock ZHONG Avatar asked Apr 03 '16 07:04

Clock ZHONG


1 Answers

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.

like image 127
piotrek1543 Avatar answered Sep 18 '22 17:09

piotrek1543