xiaocong / uiautomator

Python wrapper of Android uiautomator test tool.
MIT License
2.03k stars 638 forks source link

httplib.BadStatusLine: '' on Android L with uiautomator 1.4 #67

Open mayujsw opened 10 years ago

mayujsw commented 10 years ago

we met badstatusline error when trying uiautomator 1.4:

per the UIautomatior v1.4 steps: Run the jsonrcp server on Android device

$ adb shell uiautomator runtest  uiautomator-stub.jar bundle.jar -c com.github.uiautomatorstub.Stub
$ adb forward tcp:9008 tcp:9008 # tcp forward

How to use

Next is a python example using jsonrpclib. Before you run it, make sure install jsonrpclib via pip install jsonrpclib.

import jsonrpclib
server = jsonrpclib.Server('http://localhost:9008/jsonrpc/0')

server.wakeUp()
server.pressKey("home")
server.pressKey("back")

we met error on step "sever.wakeup()" as below:
==========================
HOST$ python
Python 2.7.3 (default, Feb 27 2014, 19:58:35) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import jsonrpclib
>>> server = jsonrpclib.Server('http://localhost:9008/jsonrpc/0')
>>> server.pressKey("home")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py", line 274, in __call__
    return self.__send(self.__name, args)
  File "/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py", line 224, in _request
    response = self._run_request(request)
  File "/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py", line 242, in _run_request
    verbose=self.__verbose
  File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1294, in single_request
    response = h.getresponse(buffering=True)
  File "/usr/lib/python2.7/httplib.py", line 1030, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 407, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 371, in _read_status
    raise BadStatusLine(line)
httplib.BadStatusLine: ''

BTW, sdcard is inserted during these steps, as i saw this error may be related to sd-card as recorded in other threads.....
xiaocong commented 10 years ago

Could you please run below command?

$ curl -d '{"jsonrpc":"2.0","method":"ping","id":"1234"}' -H 'Content-type: application/json' http://localhost:9008/jsonrpc/0

If the output is {"jsonrpc":"2.0","id":"1234","result":"pong"}, the server is ok, else the server is not up.

mayujsw commented 10 years ago

hi xiaocong,

Thanks much for your quick reply, but we still met error as below for your command: HOST$curl -d '{"jsonrpc":"2.0","method":"ping","id":"1234"}' -H 'Content-type: application/json' http://localhost:9008/jsonrpc/0 curl: (52) Empty reply from server

mayujsw commented 10 years ago

and here is the output on the android device my@mm:~/Documents/L/out/host/linux-x86/bin$ ./adb shell root@device:/ # uiautomator runtest bundle.jar uiautomator-stub.jar -c com.g> INSTRUMENTATION_STATUS: numtests=1 INSTRUMENTATION_STATUS: stream= com.github.uiautomatorstub.Stub: INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner INSTRUMENTATION_STATUS: test=testUIAutomatorStub INSTRUMENTATION_STATUS: class=com.github.uiautomatorstub.Stub INSTRUMENTATION_STATUS: current=1 INSTRUMENTATION_STATUS_CODE: 1 INSTRUMENTATION_RESULT: shortMsg=java.lang.Error INSTRUMENTATION_RESULT: longMsg=java.io.IOException: open failed: ENOENT (No such file or directory) INSTRUMENTATION_CODE: 0

mayujsw commented 10 years ago

we tried on Nexus7 with android L, not sure whether anyone make it workable now ...

xiaocong commented 10 years ago

I can reproduce it. Likely NanoHttpd failed to open temp file. I am looking at it. Thank you.

mayujsw commented 10 years ago

Great to know, thanks :)

xiaocong commented 10 years ago

Please update to v0.1.32 and check if it's fixed. Thx

mayujsw commented 10 years ago

Thanks for your quick update, we'll give a try tomorrow morning :)

mayujsw commented 10 years ago

It's OK now, thanks xiaocong !

mayujsw commented 10 years ago

after we do adb reboot, it can not work anymore, reporting "Connection reset by peer" as below

server.pressKey("home") Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py", line 274, in call return self.send(self.name, args) File "/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py", line 224, in _request response = self._run_request(request) File "/usr/local/lib/python2.7/dist-packages/jsonrpclib/jsonrpc.py", line 242, in _run_request verbose=self.__verbose File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request return self.single_request(host, handler, request_body, verbose) File "/usr/lib/python2.7/xmlrpclib.py", line 1294, in single_request response = h.getresponse(buffering=True) File "/usr/lib/python2.7/httplib.py", line 1030, in getresponse response.begin() File "/usr/lib/python2.7/httplib.py", line 407, in begin version, status, reason = self._read_status() File "/usr/lib/python2.7/httplib.py", line 365, in _read_status line = self.fp.readline() File "/usr/lib/python2.7/socket.py", line 447, in readline data = self._sock.recv(self._rbufsize) socket.error: [Errno 104] Connection reset by peer

xiaocong commented 10 years ago

Could you please capture device logcat? Thank you.

mayujsw commented 10 years ago

OK, wait for a min

mayujsw commented 10 years ago

D/AndroidRuntime( 5451): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<< D/AndroidRuntime( 5451): CheckJNI is OFF E/memtrack( 5451): Couldn't load memtrack module (No such file or directory) E/android.os.Debug( 5451): failed to load memtrack module: -2 V/Fingerprint-JNI( 5451): FingerprintManager JNI ready. D/AndroidRuntime( 5451): Calling main entry com.android.commands.uiautomator.Launcher I/wpa_supplicant( 3936): wlan0: CTRL-EVENT-SCAN-STARTED I/wpa_supplicant( 3936): wlan0: CTRL-EVENT-SCAN-STARTED E/UiAutomatorTestRunner( 5451): uncaught exception E/UiAutomatorTestRunner( 5451): java.lang.Error: java.io.IOException: open failed: ENOENT (No such file or directory) E/UiAutomatorTestRunner( 5451): at fi.iki.elonen.NanoHTTPD$HTTPSession.getTmpBucket(NanoHTTPD.java:1238) E/UiAutomatorTestRunner( 5451): at fi.iki.elonen.NanoHTTPD$HTTPSession.parseBody(NanoHTTPD.java:952) E/UiAutomatorTestRunner( 5451): at fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:288) E/UiAutomatorTestRunner( 5451): at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:920) E/UiAutomatorTestRunner( 5451): at fi.iki.elonen.NanoHTTPD$1$1.run(NanoHTTPD.java:175) E/UiAutomatorTestRunner( 5451): at java.lang.Thread.run(Thread.java:818) E/UiAutomatorTestRunner( 5451): Caused by: java.io.IOException: open failed: ENOENT (No such file or directory) E/UiAutomatorTestRunner( 5451): at java.io.File.createNewFile(File.java:941) E/UiAutomatorTestRunner( 5451): at java.io.File.createTempFile(File.java:1006) E/UiAutomatorTestRunner( 5451): at fi.iki.elonen.NanoHTTPD$DefaultTempFile.(NanoHTTPD.java:512) E/UiAutomatorTestRunner( 5451): at fi.iki.elonen.NanoHTTPD$DefaultTempFileManager.createTempFile(NanoHTTPD.java:484) E/UiAutomatorTestRunner( 5451): at fi.iki.elonen.NanoHTTPD$HTTPSession.getTmpBucket(NanoHTTPD.java:1235) E/UiAutomatorTestRunner( 5451): ... 5 more E/UiAutomatorTestRunner( 5451): Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) E/UiAutomatorTestRunner( 5451): at libcore.io.Posix.open(Native Method) E/UiAutomatorTestRunner( 5451): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:182) E/UiAutomatorTestRunner( 5451): at java.io.File.createNewFile(File.java:934) E/UiAutomatorTestRunner( 5451): ... 9 more I/AndroidRuntime( 5451): VM exiting with result code -1.

mayujsw commented 10 years ago

and we find that each time we reboot the android, it could only work again after we re-push the 2 jar files, and re-run "adb shell uiautomator runtest bundle.jar uiautomator-stub.jar -c com.github.uiautomatorstub.Stub" . While on KitKat, we do not need these step, uiautomator can be always workable no matter reboot or not...

xiaocong commented 10 years ago

Very strange... Python wrapper should have done all the same steps automatically. Please help double check if the uiautomator's version in your working environment is 0.1.32.

mayujsw commented 10 years ago

yes, we download from here : https://pypi.python.org/pypi/uiautomator/0.1.32

mayujsw commented 10 years ago

From usage perspective, the difference vs. KitKat now is that we need to push 2 JAR files/run these 2 jar through uiautomator everytime we boot up android ..

mayujsw commented 10 years ago

Just tried on Nexus7 Android L, also met connect reset by peer error

xiaocong commented 10 years ago

logcat please.

mayujsw commented 10 years ago

The first time, it works as below :

d.info {u'displayRotation': 1, u'displaySizeDpY': 600, u'displaySizeDpX': 960, u'displayWidth': 1920, u'productName': u'razor', u'currentPackageName': u'com.android.launcher', u'sdkInt': 20, u'displayHeight': 1104, u'naturalOrientation': False}

Then we reboot, try again, it does not work anymore, logcat is attached below as well:

d.info Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/uiautomator/init.py", line 519, in info return self.server.jsonrpc.deviceInfo() File "/usr/local/lib/python2.7/dist-packages/uiautomator/init.py", line 400, in wrapper server.start() File "/usr/local/lib/python2.7/dist-packages/uiautomator/init.py", line 440, in start raise IOError("RPC server not started!") IOError: RPC server not started!

logcat:

henrydeng commented 10 years ago

the change in 0.1.32 version of below codes may lead to fail to push jar package to mobile. I remove this change and the server will be ok

xiaocong commented 10 years ago

Thank @henrydeng. Do you know how it fails?