openatx / uiautomator2

Android Uiautomator2 Python Wrapper
MIT License
6.68k stars 1.42k forks source link

关于uiautomator2.UiaError #2

Closed 5368 closed 7 years ago

5368 commented 7 years ago

uiautomator2.UiaError: ('http://192.168.168.111:7912/jsonrpc/0', '{"params": {}, "jsonrpc": "2.0", "id": "0cb0b4a2b27f2377e139075a549b60bf", "method": "deviceInfo"}', 502, u'', 'HTTP Return code is not 200') 对于这个异常是否有超时设置? 是否有重启ATX-Agent的函数?

codeskyblue commented 7 years ago

你把 /sdcard/atx-agent.log 最后面中记录的错误发出来看看。这个错误说明 uiautomator 异常退出了

5368 commented 7 years ago

atx-agent.log ----------------------------------------------

2017/10/22 10:57:41 main.go:653: Ignore SIGUP
2017/10/22 10:57:41 main.go:657: Kill server
2017/10/22 10:57:41 main.go:663: Get http://127.0.0.1:7912/stop: dial tcp 127.0.0.1:7912: getsockopt: connection refused
Listen on http://192.168.168.111:7912
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner
    at com.android.commands.am.Am.runInstrument(Am.java:1093)
    at com.android.commands.am.Am.onRun(Am.java:371)
    at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
    at com.android.commands.am.Am.main(Am.java:100)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:332)
2017/10/22 10:57:42 uiautomator.go:39: uiautomator quit: exit status 1
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner
    at com.android.commands.am.Am.runInstrument(Am.java:1093)
    at com.android.commands.am.Am.onRun(Am.java:371)
    at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
    at com.android.commands.am.Am.main(Am.java:100)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:332)
2017/10/22 10:57:46 uiautomator.go:39: uiautomator quit: exit status 1
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner
    at com.android.commands.am.Am.runInstrument(Am.java:1093)
    at com.android.commands.am.Am.onRun(Am.java:371)
    at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
    at com.android.commands.am.Am.main(Am.java:100)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:332)
2017/10/22 10:57:49 uiautomator.go:39: uiautomator quit: exit status 1
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner
    at com.android.commands.am.Am.runInstrument(Am.java:1093)
    at com.android.commands.am.Am.onRun(Am.java:371)
    at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
    at com.android.commands.am.Am.main(Am.java:100)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:332)
2017/10/22 10:57:53 uiautomator.go:39: uiautomator quit: exit status 1
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner
    at com.android.commands.am.Am.runInstrument(Am.java:1093)
    at com.android.commands.am.Am.onRun(Am.java:371)
    at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
    at com.android.commands.am.Am.main(Am.java:100)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:332)
2017/10/22 10:57:56 uiautomator.go:39: uiautomator quit: exit status 1
2017/10/22 10:57:58 uiautomator.go:46: uiautomator can not started
2017/10/22 10:58:15 reverseproxy.go:316: http: proxy error: dial tcp 127.0.0.1:9008: getsockopt: connection refused
---------------------------------
8-10分钟没有操作,就会出现这个错误,我暂时使用了判断是否能读出d.info,如果不能则重启com.github.uiautomator来解决,就是等待UiaError这个时间有点长
#
        try:
            print d.info['naturalOrientation']
            return True
        except:
            os.system('adb shell am start com.github.uiautomator/.MainActivity')
            #d.press("home")
            time.sleep(1)
            return True
codeskyblue commented 7 years ago

你这个是具体什么型号的手机,最好能给个手机的链接

5368 commented 7 years ago

小米4c MIUI 8.5.2.0 Android 6.0.1 骁龙801

codeskyblue commented 7 years ago

QQ加我聊下具体问题 646890627

5368 commented 7 years ago

我使用的场景是定时执行操作[每十分钟] 下次执行时就会链接不上,如果一直有交互的话不会出现这个问题. 我明天回去再加你的号 ------------------ 问题已解决 [手机开启节能模式导致进程被杀死导致] ------------------

5368 commented 7 years ago

这个真的挺不错,感谢你的分享!

5368 commented 7 years ago

lenovo A688T/Android 4.4 python -m uiautomator2 init atx-agent install错误

------------------ 问题已解决 [手动atx-agent安装解决] ------------------

错误提示: jet@debian:~/wtm$ python -m uiautomator2 init 2017-10-24 06:12:01,004 - main.py:251 - INFO - Device(T4CQGE6HQS55EYTO) initialing ... 2017-10-24 06:12:01,172 - main.py:159 - INFO - apk already installed, skip 2017-10-24 06:12:01,172 - main.py:175 - INFO - atx-agent is installing, please be patient Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "main", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/usr/local/lib/python2.7/dist-packages/uiautomator2/main.py", line 276, in main() File "/usr/local/lib/python2.7/dist-packages/uiautomator2/main.py", line 272, in main fire.Fire(MyFire) File "/usr/local/lib/python2.7/dist-packages/fire/core.py", line 127, in Fire component_trace = _Fire(component, args, context, name) File "/usr/local/lib/python2.7/dist-packages/fire/core.py", line 366, in _Fire component, remaining_args) File "/usr/local/lib/python2.7/dist-packages/fire/core.py", line 542, in _CallCallable result = fn(*varargs, **kwargs) File "/usr/local/lib/python2.7/dist-packages/uiautomator2/main.py", line 256, in init ins.install_atx_agent(agent_version) File "/usr/local/lib/python2.7/dist-packages/uiautomator2/main.py", line 195, in install_atx_agent raise Exception("arch(%s) need to be supported yet, please report an issue in github" % abis) Exception: arch() need to be supported yet, please report an issue in github

5368 commented 7 years ago

bug吗?

 File "t1.py", line 108, in wtm
    if self.wx():
  File "t1.py", line 60, in wx
    if self.d(text=u"确定").wait(timeout=1):
  File "/usr/local/lib/python2.7/dist-packages/uiautomator2/__init__.py", line 588, in wait
    return self.jsonrpc.waitForExists(self.selector, int(timeout*1000))
  File "/usr/local/lib/python2.7/dist-packages/uiautomator2/__init__.py", line 149, in __call__
    return self.server.jsonrpc_call(self.method, params)
  File "/usr/local/lib/python2.7/dist-packages/uiautomator2/__init__.py", line 183, in jsonrpc_call
    raise err
JsonRpcError: -32001 Server error: None
5368 commented 7 years ago

关机后链接不上[python -m uiautomator2 init解决] {机型:Xiaomi 4C/Android 6.0.1,lenovo A688T/Android 4.4}

链接正常后停10分钟还会连不上[再次打开com.github.uiautomator可解决]
{机型:Xiaomi 4C/Android 6.0.1}

_原由是手机上开启节电导致app限制运行.

这个问题算以解决_

----------------------------- 关机连不上提示: jet@debian:~wtm$ python tt.py Traceback (most recent call last): File "tt.py", line 13, in print d.info File "/usr/local/lib/python2.7/dist-packages/uiautomator2/init.py", line 330, in getattr return getattr(self._default_session, attr) File "/usr/local/lib/python2.7/dist-packages/uiautomator2/init.py", line 506, in info return self.jsonrpc.deviceInfo() File "/usr/local/lib/python2.7/dist-packages/uiautomator2/init.py", line 149, in call return self.server.jsonrpc_call(self.method, params) File "/usr/local/lib/python2.7/dist-packages/uiautomator2/init.py", line 168, in jsonrpc_call data=data) File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 555, in post return self.request('POST', url, data=data, json=json, kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 508, in request resp = self.send(prep, send_kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 618, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 508, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.168.111', port=7912): Max retries exceeded with url: /jsonrpc/0 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x9df26ec>: Failed to establish a new connection: [Errno 111] Connection refused',)) jet@debian:~wtm$ python -m uiautomator2 init 2017-10-24 13:24:13,673 - main.py:251 - INFO - Device(c9b1535a) initialing ... 2017-10-24 13:24:13,951 - main.py:159 - INFO - apk already installed, skip 2017-10-24 13:24:13,951 - main.py:175 - INFO - atx-agent is installing, please be patient 2017-10-24 13:24:14,112 - main.py:178 - INFO - atx-agent already installed, skip 2017-10-24 13:24:14,868 - main.py:224 - INFO - atx-agent output: server started, listening on 192.168.168.111:7912 2017-10-24 13:24:14,869 - main.py:228 - INFO - success

codeskyblue commented 7 years ago

增加了一个d.healthcheck()方法,用来重启uiautomator2,你的问题我暂时复线不了,你每次运行测试的时候,跑下这个方法,看看好使不

5368 commented 7 years ago

麻烦你了! 这个错误呢? 是不是我写错了?

if self.d(text=u"确定").wait(timeout=1): File "/usr/local/lib/python2.7/dist-packages/uiautomator2/init.py", line 588, in wait return self.jsonrpc.waitForExists(self.selector, int(timeout*1000)) File "/usr/local/lib/python2.7/dist-packages/uiautomator2/init.py", line 149, in call return self.server.jsonrpc_call(self.method, params) File "/usr/local/lib/python2.7/dist-packages/uiautomator2/init.py", line 183, in jsonrpc_call raise err JsonRpcError: -32001 Server error: None

codeskyblue commented 7 years ago

这个提示的信息不是很全,我代码里面新增加了更详细的输出信息,你下次遇到问题的时候,重新贴出来看看

5368 commented 7 years ago

好的谢谢!

5368 commented 7 years ago

链接正常后停10分钟还会连不上[再次打开com.github.uiautomator可解决] {机型:Xiaomi 4C/Android 6.0.1}

原由**是手机上开启节电导致app限制运行.

这个问题算以解决**

codeskyblue commented 7 years ago

这都被你发现了

codeskyblue commented 7 years ago

healthcheck() 这个函数,重新做了调整,先启动com.github.uiautomator然后返回桌面,等待uiautomator连接恢复 每次开始测试时运行一下healthcheck()这个函数就好了