Appium appium+Pythom 运行脚本很很很慢!!

李晔 · 2018年04月13日 · 最后由 saii 回复于 2021年04月16日 · 3118 次阅读

具体表现:
1、click 要等个 20 多秒才点击,send_keys 动作甚至要 1 份多钟!简直了无语了!!
2.、登录的时候不会,就是登录进去之后就变慢了!
3、真机和模拟器都是如此!
4、排除是 xpath 问题,用其他选择器也是如此!

我的环境是 Python3.5+appium1.7.1,我就纳闷了!运行其他 app 都不会这样,是不是和 appium 交互有关系??我又不会看日志...

代码:

appium 日志(只截取了登录进去后的):
[HTTP] --> POST /wd/hub/session/a606c76b-ca83-4692-a8b3-5a0feaa910d1/element {"sessionId":"a606c76b-ca83-4692-a8b3-5a0feaa910d1","value":"//android.widget.TextView[@text='']","using":"xpath"}
[MJSONWP] Calling AppiumDriver.findElement() with args: ["xpath","//android.widget.TextView[@text='']","a606c76b-ca83-4692-a8b3-5a0feaa910d1"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 20000 ms for condition
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.TextView[@text='']","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.TextView[@text='']","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//android.widget.TextView[@text='']' using 'XPATH' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//android.widget.TextView[@text='']' using 'XPATH' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}
[AndroidBootstrap] Received command result from bootstrap
[BaseDriver] Waited for 214 ms so far
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.TextView[@text='']","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.TextView[@text='']","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//android.widget.TextView[@text='']' using 'XPATH' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[CLASS=android.widget.TextView, INSTANCE=46]
[AndroidBootstrap] Received command result from bootstrap
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"7"}}
[MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"7"}
[HTTP] <-- POST /wd/hub/session/a606c76b-ca83-4692-a8b3-5a0feaa910d1/element 200 11026 ms - 87
[HTTP] --> POST /wd/hub/session/a606c76b-ca83-4692-a8b3-5a0feaa910d1/element/7/click {"sessionId":"a606c76b-ca83-4692-a8b3-5a0feaa910d1","id":"7"}
[MJSONWP] Calling AppiumDriver.click() with args: ["7","a606c76b-ca83-4692-a8b3-5a0feaa910d1"]
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"7"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"7"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/a606c76b-ca83-4692-a8b3-5a0feaa910d1/element/7/click 200 10303 ms - 76
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[HTTP] --> POST /wd/hub/session/a606c76b-ca83-4692-a8b3-5a0feaa910d1/element {"sessionId":"a606c76b-ca83-4692-a8b3-5a0feaa910d1","value":"text(\"朋友圈\")","using":"-android uiautomator"}
[MJSONWP] Calling AppiumDriver.findElement() with args: ["-android uiautomator","text(\"朋友圈\")","a606c76b-ca83-4692-a8b3-5a0feaa910d1"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 20000 ms for condition
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"text(\"朋友圈\")","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"text(\"朋友圈\")","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'text("朋友圈")' using 'ANDROID_UIAUTOMATOR' with the contextId: '' multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Parsing selector: text("朋友圈")
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] UiSelector coerce type: class java.lang.String arg: "朋友圈"
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[TEXT=朋友圈]
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":{"ELEMENT":"8"}}
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"8"}
[HTTP] <-- POST /wd/hub/session/a606c76b-ca83-4692-a8b3-5a0feaa910d1/element 200 10051 ms - 87
[HTTP] --> POST /wd/hub/session/a606c76b-ca83-4692-a8b3-5a0feaa910d1/element/8/click {"sessionId":"a606c76b-ca83-4692-a8b3-5a0feaa910d1","id":"8"}
[MJSONWP] Calling AppiumDriver.click() with args: ["8","a606c76b-ca83-4692-a8b3-5a0feaa910d1"]
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"element:click","params":{"elementId":"8"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"element:click","params":{"elementId":"8"}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: click
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/a606c76b-ca83-4692-a8b3-5a0feaa910d1/element/8/click 200 10177 ms - 76
[BaseDriver] Shutting down because we waited 60 seconds for a command
[AndroidDriver] Shutting down Android driver
[Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability'
[Appium] Removing session a606c76b-ca83-4692-a8b3-5a0feaa910d1 from our master session list
[ADB] Getting connected devices...
[ADB] 2 device(s) connected
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","127.0.0.1:62025","shell","am","force-stop","cn.lehealth.lemovt"]
[ADB] Pressing the HOME button
[ADB] Getting connected devices...
[ADB] 2 device(s) connected
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","127.0.0.1:62025","shell","input","keyevent",3]
[AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Closed client connection
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: numtests=1

[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=.

[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner

[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: test=testRunServer

[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap

[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: current=1

[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS_CODE: 0

[AndroidBootstrap] Received command result from bootstrap
[UiAutomator] Shutting down UiAutomator
[UiAutomator] Moving to state 'stopping'
[UiAutomator] UiAutomator shut down normally
[UiAutomator] Moving to state 'stopped'
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Getting connected devices...
[ADB] 2 device(s) connected
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","127.0.0.1:62025","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[UiAutomator] Moving to state 'stopped'
[Logcat] Stopping logcat capture
[ADB] Getting connected devices...
[ADB] 2 device(s) connected
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","127.0.0.1:62025","shell","am","force-stop","io.appium.unlock"]
[AndroidDriver] Not cleaning generated files. Add clearSystemFiles capability if wanted.

共收到 23 条回复 时间 点赞

我又不会看日志...

速度是挺慢的,我老大不满意速度,都不知道怎么改进

Hi大少 回复

你有我这么慢??send_keys 动作几分钟才输入啊!!这合理吗?问题我运行其他 APP 又不会这样!我真的是摸不着头脑了...

简单看了下日志
在 click 时执行 20 秒
findElemnt 用了 10 秒 找到 elemnet 之后 click 用了 10 秒
我之前测试好像没有这么慢,回头看一下我这边的测试日志
先 mark 一下

我用换了 uiautomator2 跑也是一样,现在是不是可以排除是测试工具的问题了??难道是 APP 的问题??我问了开发我们 APP 是用 JavaScript+ 原生来开发的!!有关系吗??

李晔 回复

有 uiautomator2 的日志吗?

李晔 回复

是不是设置了 implicitWaitMs 这个属性为 20000ms?

李晔 回复

在你的日志中有 [BaseDriver] Waiting up to 20000 ms for condition 这里是 20000ms 在我的日志里是 0 秒 不确定是不是这里引起的

仅楼主可见
李晔 #10 · 2018年04月18日 Author
武松 回复

大神能具体点吗??我刚接触 app 自动化!很多地方不懂!!

李晔 #11 · 2018年04月18日 Author

implicitWaitMs?什么来的?在哪设置!uiautomator2 的日志没有!也不知道在哪里!它又不像 appium 一样有个服务端可以看!!

和那 20000ms 没有关系 又看了一下日志对比

findElement 的时候 定位元素失败进行了重试

我这边测试时用的命令是:

el = self.driver.find_element_by_accessibility_id('Graphics')
el.click()

这两个命令执行的速度是很快的
或者你尝试一下换一下 find_element 的内容?

李晔 回复

我这边尝试执行了

self.driver.find_element_by_android_uiautomator('text(\"NFC\")').click()

其日志返回和你的查找朋友圈 text 一样 但是时间我这边用时是 165ms
所以我也不确定是什么原因了从日志里目前看不太出来~

李晔 #14 · 2018年04月18日 Author

所以我也快崩溃了!!都不知道什么原因!!!

这个问题怎么样了 我也是很慢很慢。查找不到时提示我重试,分钟级别的间隔时间。


求大神指点下 这个是为什么啊

问下,这个属性值是在哪个文件中,能截图出来吗,我的脚本出现这个问题,亟待解决

楼主,解决了这个问题吗,最近我也遇到了,click 点击坐标是正常的速度,但识别元素和 sendkey 很慢,也没找到原因,我升级了 appium-desktop 的版本,识别速度就正常了,你可以试试

李晔 #19 · 2019年03月04日 Author
杉菜 回复

好的!我有空试试!你的有我这么慢吗?要几分钟的呢!

李晔 回复

有,现在在某些界面识别一个 xpath 需要 60 秒,用的是 appium1.10.0,也不知道为什么会这么慢,其他界面识别元素还是正常的。

李晔 #20 · 2019年03月05日 Author
杉菜 回复

我现在没做 app 自动化了,但以前我换了个项目又是正常的额!

最近遇到相似的问题,解决方案是
driver.update_settings({"waitForIdleTimeout": 100})

要注意看下静置时 CPU 的消耗情况

参考链接:
https://github.com/appium/appium/issues/14349
https://developer.android.com/reference/android/support/test/uiautomator/Configurator#setWaitForIdleTimeoutlong)(

xz6 回复

楼上这个是正解
可以在 capability 里面配置 waitForIdleTimeout: 100 即可

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