Appium 大家有没有碰见过 appium 执行查找时特别慢的情况?如何解决的?

wanghao735 · 2018年05月31日 · 最后由 wanghao735 回复于 2018年07月16日 · 2895 次阅读

最近发现 appium 执行时响应特别慢,分钟级别的响应。
日志如下:

2018-05-31 11:46:35:195 - [HTTP] --> POST /wd/hub/session/c4da7699-f33a-4239-bacd-2abb02a3b289/element {"using":"-android uiautomator","value":"new UiSelector().text(\"允许\")"}
2018-05-31 11:46:35:195 - [debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["-android uiautomator","new UiSelector().text(\"允许\")","c4da7699-f33a-4239-bacd-2abb02a3b289"]
2018-05-31 11:46:35:195 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-05-31 11:46:35:195 - [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
2018-05-31 11:46:35:195 - [debug] [BaseDriver] Waiting up to 0 ms for condition
2018-05-31 11:46:35:196 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"new UiSelector().text(\"允许\")","context":"","multiple":false}}
2018-05-31 11:46:35:199 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"new UiSelector().text(\"允许\")","context":"","multiple":false}}
2018-05-31 11:46:35:199 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
2018-05-31 11:46:35:199 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
2018-05-31 11:46:35:199 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'new UiSelector().text("允许")' using 'ANDROID_UIAUTOMATOR' with the contextId: '' multiple: false
2018-05-31 11:46:35:199 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Parsing selector: new UiSelector().text("允许")
2018-05-31 11:46:35:200 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] UiSelector coerce type: class java.lang.String arg: "允许"
2018-05-31 11:46:35:200 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[TEXT=允许]
2018-05-31 11:53:44:015 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
2018-05-31 11:53:44:015 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'new UiSelector().text("允许")' using 'ANDROID_UIAUTOMATOR' with the contextId: '' multiple: false
2018-05-31 11:53:44:015 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Parsing selector: new UiSelector().text("允许")
2018-05-31 11:53:44:015 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] UiSelector coerce type: class java.lang.String arg: "允许"
2018-05-31 11:53:44:015 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[TEXT=允许]
2018-05-31 11:53:44:769 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"value":"No element found","status":7}
2018-05-31 11:53:44:769 - [debug] [AndroidBootstrap] Received command result from bootstrap

可以看见 46 分发出请求,53 分才给出未找到的响应,同时有提示:Failed to locate element. Clearing Accessibility cache and retrying.
多次重启 appium-server 会有时候没有这个问题,但问题出现的比较频繁。

环境:
appium server 1.6.4
client 4.0.0
jdk 1.8
模拟器用的 genymotion 安卓版本 4.3
查找部分代码如下:

String str1 = "new UiSelector().text(" + "\"" + text + "\")";
WebElement el;
try {
    el = driver.findElementByAndroidUIAutomator(str1);
} catch (Exception e) {
    el = null;
}

共收到 7 条回复 时间 点赞

居然一个回复的都没有。。。

换个手机试试呢?

动态页面就很慢

非动态页面,主要是重启 server 端有时候会没有这个问题。很奇怪的。已经升级到最新版的 appium-server,还是一样的问题

界面上是否有动画,可以在开发人员选项中将 animation 都关闭试试。

仅楼主可见

问题解决了。。。我用 macmini 只跑 server 和 genymotion 模拟器,i5 8g 内存,没想到居然是因为内存不足。主要是 genymotion 占了大概 1.5g 内存,重启机器后问题就没了。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册