Skip to content

Common issues (Archived)

codeskyblue edited this page Apr 25, 2024 · 1 revision

Uiautomator started failed.

Reason 1:

app-uiautomator.apk or app-uiautomator-test.apk not installed.

Reason 2:

app-uiautomator.apk and app-uiautomator-test.apk signature not match.

The following command is to run uiautomator manually. You will see details about what's is wrong.

$ adb shell am instrument -w -r -e debug false -e class com.github.uiautomator.stub.Stub \
    com.github.uiautomator.test/androidx.test.runner.AndroidJUnitRunner

com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner

Normal output is

INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=
com.github.uiautomator.stub.Stub:
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: test=testUIAutomatorStub
INSTRUMENTATION_STATUS: class=com.github.uiautomator.stub.Stub
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS_CODE: 1

提示Connection Error

可能是atx-agent没有在运行,可以通过AppetizerIO设备管理里检查atx-agent运行情况。,也可以通过adb命令行:

# 检查是否运行的方法
> adb shell
$ ps | grep atx # 如果看到atx-agent则表示正在运行
# 启动atx-agent
$ /data/local/tmp/atx-agent server -d
# 停止atx-agent
$ /data/local/tmp/atx-agent server --stop

在Android 8以上,黑屏后atxagent连不上

例如华为等设备上,测试时建议保持屏幕常亮(开发者选项)保证后台的atx-agent不被系统放入深度睡眠,同时建议将atx相关组件在设置->电池中不进行电池优化(防止睡眠)相关issue

点击坐标出现偏移

为了提高uiautomator2再有播放器界面不卡死,代码中将默认3000ms中的waitForIdleTimeout改成了0,不过有可能会造成坐标偏移,虽然概率不大。 如果出现这种情况,可以将其调大一点 d.jsonrpc.setConfigurator({"waitForIdleTimeout": 100})

如何停用UiAutomator的守护程序 How to stop UiAutomator process keeper

因为有atx-agent的存在,Uiautomator会被一直守护着,如果退出了就会被重新启动起来。但是Uiautomator又是霸道的,一旦它在运行,手机上的辅助功能、电脑上的uiautomatorviewer 就都不能用了,除非关掉该框架本身的uiautomator。下面就说下两种关闭方法

方法1:

直接打开uiautomator app(init成功后,就会安装上的),点击关闭UIAutomator

方法2:

d.uiautomator.stop()
# d.uiautomator.start()

ATX与Maxim共存AccessibilityService的方法

出现SSLError

尝试安装下面的依赖

pip install pyOpenSSL>=0.13
pip install ndg-httpsclient>=0.3.2

相关issue:https://github.com/openatx/uiautomator2/issues/49

模拟器截图黑屏

原因,minicap不支持模拟器

删除minicap,会自动切换到使用uiautomator中接口截图。 adb shell rm /data/local/tmp/minicap

对于长时间scroll,中间uiautomator2会重启

因为是用的http请求的方式跟com.github.uiautomator通信的,python代码里面写的默认是90s超时,超时之后就会认为com.github.uiautomator 故障了,然而scroll.to这个函数,会一直找下去,直到找到元素位置。然后决定重启。 https://github.com/openatx/uiautomator2/issues/287

实验性功能

  • 远程查看: 手机python -m uiautomator2 init之后,浏览器输入 <device_ip:7912>,会发现一个远程控制功能,延迟非常低噢。^_^
  • 手机USB连接后,自动调用init命令 adbkit-init
  • htmlreport 记录测试过程的测试报告

诊断uiautomator2方法

$ adb forward tcp:9008 tcp:9008
$ curl 127.0.0.1:9008/ping
# expect: pong

$ curl -d '{"jsonrpc":"2.0","method":"deviceInfo","id":1}' 127.0.0.1:9008/jsonrpc/0
# expect JSON output

Hooks

d = u2.connect()

def callback(stage, func_name, args, kwargs, ret):
    print("stage", stage)
    print("call", func_name, args, kwargs)
    print("return", ret)

d.hooks_register(callback)
d.click(0.5, 0.5)
# expect output
# stage: before
# call: click (540, 960) {}
# return: None
# stage: after
# call: click (540, 960) {}
# return: None

Use hooks, you can capture screenshot before or after click, long_click, double_click, swipe

失败时弹出提示框

使用方法

import uiautomator2 as u2
u2.set_fail_prompt(True) # 填写False可以关闭这个功能

d = u2.connect()
d(text="Search").click(timeout=2)

如果Search这个按钮没有找到,会弹出一个tkinter的提示框。 包含 Retry, Skip, Abort按钮,如果没有任何操作30s后自动Abort,也就是抛出异常

目前只有click这一个操作会有提示框。欢迎使用该功能,并提供反馈意见。

Introduced in 2018-12-13 23:17