I'm trying to test my company's browser's auto suggest functionality for the Russian language with UIAutomator and am hitting a snag:
There are no KeyEvent.KeyCode_* code for Russian letters and UiDevice.pressKeyCode(KeyEvent.KEYCODE_LANGUAGE_SWITCH)
doesn't appear to help. What documentation I found inside the KeyEvent class seems to suggest that I just need to use the same KeyCodes as the english letters but magically they would be mapped across to the letters of of the other languages. That does not appear to actually happen however as I'm still seeing the English letter show up when I try that.
Normally with Russian I just use UiObject2.setText(...) but that method does not trigger auto suggestions.
I've tried delving into what UiDevice.pressKeyCode is doing and attempting a couple workarounds such as:
KeyEvent eventsб2 = new KeyEvent(SystemClock.currentThreadTimeMillis(), "б", KeyCharacterMap.VIRTUAL_KEYBOARD, 0);
Instrumentation.sendKeySync(eventsб2);
or
KeyEvent[] eventsа = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD).getEvents(new char[] {'a'});
Instrumentation.sendKeySync(eventsа[0]);
But they either don't enter the letter or throw a permission exception regarding needing the INJECT_EVENTS permission. Overall I'm feeling like I'm stumbling in the dark and would love some advice on how to proceed.
I tried this and worked.
/**
* @@Test comment here@@
*
* @throws Exception
*/
@Test
public void culebraGeneratedTest_CyrillicKeyBoardAndSelectSuggestion() throws Exception {
mDevice.pressHome();
mDevice.findObject(By.res("com.android.quicksearchbox:id/search_widget_text").clazz("android.widget.TextView").text(Pattern.compile("")).pkg("com.android.quicksearchbox")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
mDevice.findObject(By.desc("й").clazz("com.android.inputmethod.keyboard.Key").text(Pattern.compile("")).pkg("com.android.inputmethod.latin")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
(new UiScrollable(new UiSelector().resourceId("com.android.quicksearchbox:id/suggestions").index(1).packageName("com.android.quicksearchbox"))).getChildByText(new UiSelector().className("android.widget.RelativeLayout").packageName("com.android.quicksearchbox"), "йемен", true).click();
}
I have to admit that I don't know Russian or what I was selecting on the Cyrillic keyboard, so bear with me.
To generate this test I used CulebraTester as it seems to be an interesting use case for the tool.
The steps were:
You will be able to create a similar test using AndroidViewClient/culebra in python but because this tool is based on the information obtained from uiautomator dump
it won't be able to detect the letters on the keyboard, but you can also touch them using DIPs
vc.dump(window=-1)
vc.findViewByIdOrRaise("com.android.quicksearchbox:id/search_widget_text").touch()
vc.sleep(_s)
vc.dump(window=-1)
device.touchDip(15.33, 393.33, 0)
but this is not as device independent as the first solution.
Hope this helps you.