ericmckean / chromedriver

Automatically exported from code.google.com/p/chromedriver
0 stars 0 forks source link

Remote Android "sendKeys" shouldn't require a local Linux X display #1018

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Issue Description:
If you run ChromeDriver on a headless Linux host (no X or Xvfb) and attempt to 
"sendKeys" to an attached Android device, ChromeDriver dies with:
org.openqa.selenium.WebDriverException: unknown error: an X display is required 
for keycode conversions, consider using Xvfb

The Linux host is only used to automate Android devices, so (IMHO) there's no 
reason ChromeDriver should use the local host's keymap for the *remote* Android 
device.  Instead, it should only fail if Chrome is running on the *local* host.

Steps to reproduce:
1) Setup Linux box w/o X11 or xvfb
2) Attach Android device
3) Run a ChromeDriver test that uses "sendKeys", e.g.:
       https://sites.google.com/a/chromium.org/chromedriver/getting-started
4) Look for error

Background:
The above error is printed by:
http://src.chromium.org/viewvc/chrome/trunk/src/chrome/test/chromedriver/keycode
_text_conversion_x.cc?annotate=242503#l194
which uses the display to call the following xfree86 functions:
   http://cvsweb.xfree86.org/cvsweb/xc/lib/X11/XKBBind.c?annotate=3.21#65
   http://cvsweb.xfree86.org/cvsweb/xc/lib/X11/ModMap.c?annotate=1.6#31
The output is (presumably) something similar to
   $ xvfb-run -a xmodmap -pke
   keycode   8 =
   keycode   9 = Escape NoSymbol Escape
   keycode  10 = 1 exclam 1 exclam
   ...
in:
  http://cvsweb.xfree86.org/cvsweb/xc/programs/xmodmap/exec.c?annotate=1.7#249
Regardless, I don't think ChromeDriver should use the local keymap.

One option is to modify the above ChromeDriver code (or it's caller:
http://src.chromium.org/viewvc/chrome/trunk/src/chrome/test/chromedriver/key_con
verter.cc?view=annotate#l295
) to simply keep going, as illustrated a couple lines down in the above code:
   // Do a best effort and use the raw key we were given.

Another option is to query the remote Android device's keymap:
  http://source.android.com/devices/input/key-character-map-files.html
E.g.:
  $ adb shell cat /system/usr/keylayout/Generic.kl
  key 1     ESCAPE
  key 2     1
  ...
  $ adb shell cat /system/usr/keychars/Virtual.kcm
  key A {
      label:                              'A'
      base:                               'a'
      shift, capslock:                    'A'
  }
  ...

Original issue reported on code.google.com by wrig...@google.com on 15 Jan 2015 at 9:18

GoogleCodeExporter commented 9 years ago

Original comment by samu...@chromium.org on 21 Feb 2015 at 12:18

GoogleCodeExporter commented 9 years ago
I'm also experiencing this issue using the python client and real devices.

Original comment by e...@saucelabs.com on 2 Mar 2015 at 10:32

GoogleCodeExporter commented 9 years ago
+1 also see it on Samsung S4, S5 and Nexus 5 devices.

Original comment by maj....@gmail.com on 3 Mar 2015 at 5:52

GoogleCodeExporter commented 9 years ago
can confirm on moto-g as well

Original comment by e...@indico.io on 5 Mar 2015 at 9:07

GoogleCodeExporter commented 9 years ago
Another way to fix this, in addition to the methods that Todd suggested, is to 
move the keycode conversion into DevTools so that the conversion is done 
according to whatever platform and environment Chrome is running in.

Original comment by samu...@chromium.org on 5 Mar 2015 at 10:05