I can input the text into a dialog with adb shell input text "blahblah"
just fine. The text shows up and... sits there.
I can send a tap at coords of the OK button, to actually have the text take effect in whatever dialog I entered it - if I guess the screen orientation right, adapt to the current resolution, adapt to the current keyboard variant and so on. Terribly clunky.
Is there some magic character or keycode or some other neat way to have the shell perform the equivalent of pressing the "OK"?
In the above screenshot, it's the green ->|
icon in the lower right. It sometimes changes with the exact field used, but the meaning is always the same: close the keyboard and proceed.
The specific value XX is as follows Use the command “ADB shell input keyevent < key value >” Can be automated. For example, “ADB shell input keyevent 3” can press the home key.] Execution screen off and screen on: ADB shell input keyevent 26
I believe that you're looking for adb shell input keyevent 66. The keyevent is using for pressing the virtual keyboard keys, and code 66 is for ENTER key. You can find here list of codes. EDIT The mapping between the keys and the codes can be found at /system/usr/keylayout/qwerty.kl.
As soon as you execute an ‘adb shell’ command on the command terminal, it sends a signal to your Android device and triggers the remote shell command console. Thus ADB shell commands let you control your Android device.
Unfortunately it seems like app devs need to build in Enter Key (keycode 66) listener support for the text field because ADB, and therefore Appium or anything else, cannot hit OK, Done, Continue, Search, or any of the IME_ACTION s. I believe that you're looking for adb shell input keyevent 66.
I believe that you're looking for adb shell input keyevent 66
.
The keyevent
is using for pressing the virtual keyboard keys, and code 66 is for ENTER
key.
You can find here list of codes.
EDIT
The mapping between the keys and the codes can be found at /system/usr/keylayout/qwerty.kl
. You can do adb shell cat /system/usr/keylayout/qwerty.kl
and see the codes you need.
You can use AndroidViewClient/culebra and forget about orientation, different screen sizes, etc.
As an example, let's say we want to enter text and press OK in this dialog (part of Api Demos)
just run
culebra -uGo myscript.py
when the window is displayed, click on the entry, type the text, then click OK and this script will be automatically generated
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2016 Diego Torres Milano
Created on 2016-06-10 by Culebra v11.5.8
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
|/ \_/ \_/ \_/ \ o \
\_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''
import re
import sys
import os
try:
sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient
TAG = 'CULEBRA'
_s = 5
_v = '--verbose' in sys.argv
kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True}
vc = ViewClient(device, serialno, **kwargs2)
#vc.dump(window='-1') # FIXME: seems not needed
vc.dump(window=-1)
vc.findViewByIdOrRaise("com.example.android.apis:id/username_edit").setText(u"hello culebra!")
vc.sleep(_s)
vc.dump(window=-1)
vc.findViewWithTextOrRaise(u'OK').touch()
when run, it will set the text to hello culebra!
and touch OK. You can then adapt the generated script to your needs.
CulebraTester is a new implementation of culebra as a service that runs on the device under test. It's now under closed beta testing but if you are interested in participating you can find the opt-in form at culebra.dtmilano.com (check under Support).
One of its features is to be able to detect the virtual keyboard and treat it the same as other Views.
This screenshot illustrates the test generated after touching A, b, c, and Next (which is what your are looking for).
The generated test is like this
/**
* @@Test comment here@@
*
* @throws Exception
*/
@Test
public void culebraGeneratedTest() throws Exception {
mDevice.findObject(By.clazz(Pattern.compile(".*")).desc("A").pkg("com.android.inputmethod.latin")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
mDevice.findObject(By.clazz(Pattern.compile(".*")).desc("b").pkg("com.android.inputmethod.latin")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
mDevice.findObject(By.clazz(Pattern.compile(".*")).desc("c").pkg("com.android.inputmethod.latin")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
mDevice.findObject(By.clazz(Pattern.compile(".*")).desc("Next").pkg("com.android.inputmethod.latin")).clickAndWait(Until.newWindow(), DEFAULT_TIMEOUT);
}
and you can compile, install and run as any other UiAutomator test.
As an additional example, this screenshot show how as you hover the virtual keyboard Views in the tree they are highlighted in the device representation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With