ATX [求助][iOS] 使用 appium 的 WDA 连跑中断开,请问哪位小伙伴有解决方法

匿名 · September 23, 2019 · Last by replied at December 11, 2020 · 3064 hits

每次断开时间也不一致,有时候半小时,有时候一个半小时,有时候两个半小时,有小伙伴遇到过这种情况么?

环境信息:
  1. python: 3.7.3
  2. facebook-wda: 0.4.1
  3. com.facebook.wda.runner: 6.0
  4. xcode:10.3
  5. mac os:10.14.6
  6. 设备:iphone5s(12.4.1),iphone6p(12.1.4)
python 端报错日志

这里只能看出来是连接断了

E               urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

xcodebuild 日志

Session-WebDriverAgentRunner 日志路径:/Users/zhangsan/Library/Developer/Xcode/DerivedData/WebDriverAgent-gepobbogdbbwbigexigktqefklzg/Logs/Test/Test-WebDriverAgentRunner-2019.09.23_17-57-30-+0800.xcresult/1_Test/Diagnostics/WebDriverAgentRunner-79E6171C-C803-446E-8972-168FD5BE3D85/WebDriverAgentRunner-EB35C1AF-7EBA-42B5-B47A-FF12D89E3E18/Session-WebDriverAgentRunner-2019-09-23_193014-DJYk0S.log

19:30:32.551 WebDriverAgentRunner-Runner[2386:71867] Process environment: {
    "CA_ASSERT_MAIN_THREAD_TRANSACTIONS" = 0;
    "CA_DEBUG_TRANSACTIONS" = 0;
    "CFFIXED_USER_HOME" = "/private/var/mobile/Containers/Data/Application/EE8303AA-404F-4CF0-B55F-5E141B9431BE";
    CLASSIC = 1;
    "DYLD_FRAMEWORK_PATH" = "/private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/Frameworks:";
    "DYLD_LIBRARY_PATH" = "/usr/lib/swift:/private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/Frameworks";
    HOME = "/private/var/mobile/Containers/Data/Application/EE8303AA-404F-4CF0-B55F-5E141B9431BE";
    LOGNAME = mobile;
    "MJPEG_SERVER_PORT" = "";
    "MTC_CRASH_ON_REPORT" = 1;
    NSUnbufferedIO = YES;
    "OS_ACTIVITY_DT_MODE" = YES;
    PATH = "/usr/bin:/bin:/usr/sbin:/sbin";
    SHELL = "/bin/sh";
    "SQLITE_ENABLE_THREAD_ASSERTIONS" = 1;
    TMPDIR = "/private/var/mobile/Containers/Data/Application/EE8303AA-404F-4CF0-B55F-5E141B9431BE/tmp/";
    "UPGRADE_TIMESTAMP" = "";
    USER = mobile;
    "USE_PORT" = "";
    "WDA_PRODUCT_BUNDLE_IDENTIFIER" = "";
    XCTestConfigurationFilePath = "/private/var/mobile/Containers/Data/Application/EE8303AA-404F-4CF0-B55F-5E141B9431BE/tmp/WebDriverAgentRunner-841173F8-F53E-4429-9D42-B0CBC344BFF5.xctestconfiguration";
    "XPC_FLAGS" = 0x0;
    "XPC_SERVICE_NAME" = "UIKitApplication:com.apple.test.WebDriverAgentRunner-Runner[0xd183][60]";
    "__CF_USER_TEXT_ENCODING" = "0x1F5:0:0";
}
19:30:32.552 WebDriverAgentRunner-Runner[2386:71867] App Sandbox active: YES
19:30:32.589 WebDriverAgentRunner-Runner[2386:71867] Creating future for 'Acquiring IDE transport' with timeout 60.00
19:30:32.712 WebDriverAgentRunner-Runner[2386:71867] Creating future for 'Exchange protocol versions with daemon' with timeout 15.00
19:30:32.732 WebDriverAgentRunner-Runner[2386:71867] <XCTWaiter: 0x280f5ce80, state: XCTWaiterStateSucceeded> entering wait loop for 15.00s with expectations: `Exchange protocol versions with daemon`
19:30:32.733 WebDriverAgentRunner-Runner[2386:71867] <XCTWaiter: 0x280f5ce80, state: XCTWaiterStateSucceeded> done waiting
19:30:32.733 WebDriverAgentRunner-Runner[2386:71867] Canceling watchdog for <XCTWaiter: 0x280f5ce80, state: XCTWaiterStateSucceeded>.
19:30:32.733 WebDriverAgentRunner-Runner[2386:71867] <XCTWaiter: 0x280f5ce80, state: XCTWaiterStateSucceeded> cleaning up `Exchange protocol versions with daemon`
19:30:32.734 WebDriverAgentRunner-Runner[2386:71867] Got daemon protocol version 26
19:30:32.735 WebDriverAgentRunner-Runner[2386:71867] Requesting IDE connection transport
19:30:32.736 WebDriverAgentRunner-Runner[2386:71867] <XCTWaiter: 0x280f5ca60, state: XCTWaiterStateInProgress> entering wait loop for 59.88s with expectations: `Acquiring IDE transport`
19:30:32.740 WebDriverAgentRunner-Runner[2386:71927] Creating transport with received transport data
19:30:32.741 WebDriverAgentRunner-Runner[2386:71927] <XCTWaiter: 0x280f5ca60, state: XCTWaiterStateSucceeded>: cancelWaiting
19:30:32.745 WebDriverAgentRunner-Runner[2386:71867] <XCTWaiter: 0x280f5ca60, state: XCTWaiterStateSucceeded> done waiting
19:30:32.745 WebDriverAgentRunner-Runner[2386:71867] Canceling watchdog for <XCTWaiter: 0x280f5ca60, state: XCTWaiterStateInProgress>.
19:30:32.745 WebDriverAgentRunner-Runner[2386:71867] <XCTWaiter: 0x280f5ca60, state: XCTWaiterStateSucceeded> cleaning up `Acquiring IDE transport`
19:30:32.745 WebDriverAgentRunner-Runner[2386:71867] Creating connection with transport <DTXFileDescriptorTransport: 0x28265e990>
19:30:32.747 WebDriverAgentRunner-Runner[2386:71867] Creating the proxy channel with connection <DTXConnection 0x283150000 : x1>
19:30:33.140 xcodebuild[57209:7764306] Starting test plan, clearing initialization timeout timer.
19:30:33.100 WebDriverAgentRunner-Runner[2386:71867] Initializing for UI testing.
19:30:33.113 WebDriverAgentRunner-Runner[2386:71867] Linked XCTAutomationSupport.framework from /var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/Frameworks/XCTAutomationSupport.framework/XCTAutomationSupport, built with Xcode 1020(10G1d), modified on 2019年9月23日 星期一 中国标准时间 17:59:11
XCTAutomationSupport.framework bundle version: 14490.71
19:30:33.117 WebDriverAgentRunner-Runner[2386:71867] Creating future for 'Loading Accessibility' with timeout 70.00
19:30:33.118 WebDriverAgentRunner-Runner[2386:71867] <XCTWaiter: 0x280f51920, state: XCTWaiterStateInProgress> entering wait loop for 70.00s with expectations: `Loading Accessibility`
19:30:33.124 WebDriverAgentRunner-Runner[2386:71927] <XCTWaiter: 0x280f51920, state: XCTWaiterStateSucceeded>: cancelWaiting
19:30:33.124 WebDriverAgentRunner-Runner[2386:71867] <XCTWaiter: 0x280f51920, state: XCTWaiterStateSucceeded> done waiting
19:30:33.125 WebDriverAgentRunner-Runner[2386:71867] Canceling watchdog for <XCTWaiter: 0x280f51920, state: XCTWaiterStateInProgress>.
19:30:33.125 WebDriverAgentRunner-Runner[2386:71867] <XCTWaiter: 0x280f51920, state: XCTWaiterStateSucceeded> cleaning up `Loading Accessibility`
19:30:33.126 WebDriverAgentRunner-Runner[2386:71867] Error from daemon in loading AX: Not authorized for performing UI testing actions.
19:30:33.126 WebDriverAgentRunner-Runner[2386:71867] Error capturing sample for process backboardd:
Error Domain=XCTDaemonErrorDomain Code=20 "Failed to spawn process for sample: 22 - Invalid argument" UserInfo={NSLocalizedDescription=Failed to spawn process for sample: 22 - Invalid argument}
19:30:33.126 WebDriverAgentRunner-Runner[2386:71867] Error capturing sample for process SpringBoard:
Error Domain=XCTDaemonErrorDomain Code=20 "Failed to spawn process for sample: 22 - Invalid argument" UserInfo={NSLocalizedDescription=Failed to spawn process for sample: 22 - Invalid argument}
19:30:33.127 WebDriverAgentRunner-Runner[2386:71867] Failed to load accessibility.
19:30:33.127 WebDriverAgentRunner-Runner[2386:71867] Failed to initialize for UI testing: Error Domain=XCTDaemonErrorDomain Code=41 "Not authorized for performing UI testing actions." UserInfo={samples={
    SpringBoard = "Error Domain=XCTDaemonErrorDomain Code=20 \"Failed to spawn process for sample: 22 - Invalid argument\" UserInfo={NSLocalizedDescription=Failed to spawn process for sample: 22 - Invalid argument}";
    backboardd = "Error Domain=XCTDaemonErrorDomain Code=20 \"Failed to spawn process for sample: 22 - Invalid argument\" UserInfo={NSLocalizedDescription=Failed to spawn process for sample: 22 - Invalid argument}";
}, NSLocalizedDescription=Not authorized for performing UI testing actions.}
19:30:33.173 xcodebuild[57209:7764306] Initialization failure for UI testing: Not authorized for performing UI testing actions.
19:30:33.174 xcodebuild[57209:7764306] Test operation failure: The test runner failed to initialize for UI testing
19:30:33.174 xcodebuild[57209:7764306] _finishWithError:Error Domain=IDETestOperationsObserverErrorDomain Code=13 "The test runner failed to initialize for UI testing" UserInfo={NSLocalizedDescription=The test runner failed to initialize for UI testing, NSUnderlyingError=0x7fbbf3b57c10 {Error Domain=XCTDaemonErrorDomain Code=41 "Not authorized for performing UI testing actions." UserInfo={samples={
    SpringBoard = "Error Domain=XCTDaemonErrorDomain Code=20 \"Failed to spawn process for sample: 22 - Invalid argument\" UserInfo={NSLocalizedDescription=Failed to spawn process for sample: 22 - Invalid argument}";
    backboardd = "Error Domain=XCTDaemonErrorDomain Code=20 \"Failed to spawn process for sample: 22 - Invalid argument\" UserInfo={NSLocalizedDescription=Failed to spawn process for sample: 22 - Invalid argument}";
}, NSLocalizedDescription=Not authorized for performing UI testing actions.}}}

StandardOutputAndStandardError.txt 日志路径:/Users/zhangsan/Library/Developer/Xcode/DerivedData/WebDriverAgent-gepobbogdbbwbigexigktqefklzg/Logs/Test/Test-WebDriverAgentRunner-2019.09.23_17-57-30-+0800.xcresult/1_Test/Diagnostics/WebDriverAgentRunner-79E6171C-C803-446E-8972-168FD5BE3D85/WebDriverAgentRunner-EB35C1AF-7EBA-42B5-B47A-FF12D89E3E18/StandardOutputAndStandardError.txt

== 0 OR frame == 0 OR value == 0 OR title == 0 OR label == 0 OR elementType == 0 OR enabled == 0 OR placeholderValue == 0)'
    t =  4290.27s     Find: Identity Binding
    t =  4290.28s Snapshot accessibility hierarchy for app with pid 1700
    t =  4290.28s Find: Descendants matching type Table
    t =  4290.29s Find: Children matching type Cell
    t =  4290.30s Find: Identity Binding
    t =  4290.30s Find: Children matching type StaticText
    t =  4290.30s Find: Elements matching predicate 'wdName == "This is 007.jpg Email20190923191032" AND (1 == 1 OR identifier == 0 OR frame == 0 OR value == 0 OR title == 0 OR label == 0 OR elementType == 0 OR enabled == 0 OR placeholderValue == 0)'
    t =  4290.31s Find: Identity Binding
    t =  4290.57s Get all elements bound by accessibility element for: Children matching type Cell
    t =  4290.58s     Snapshot accessibility hierarchy for app with pid 1700
    t =  4292.13s     Find: Descendants matching type Table
    t =  4292.13s     Find: Children matching type Cell
    t =  4292.72s Get all elements bound by accessibility element for: Children matching type StaticText
    t =  4292.73s     Snapshot accessibility hierarchy for app with pid 1700
    t =  4292.85s     Find: Descendants matching type Table
    t =  4292.86s     Find: Children matching type Cell
    t =  4292.86s     Find: Identity Binding
    t =  4292.92s Get all elements bound by accessibility element for: Children matching type Cell
    t =  4292.92s     Snapshot accessibility hierarchy for app with pid 1700
    t =  4293.04s     Find: Descendants matching type Table
    t =  4293.05s     Find: Children matching type Cell
    t =  4293.28s Get all elements bound by accessibility element for: Children matching type StaticText
    t =  4293.28s     Snapshot accessibility hierarchy for app with pid 1700
    t =  4293.40s     Find: Descendants matching type Table
    t =  4293.41s     Find: Children matching type Cell
    t =  4293.41s     Find: Identity Binding
    t =  4293.42s     Find: Children matching type StaticText
    t =  4293.49s Checking existence of `"This is 007.jpg Email20190923191032" StaticText`
    t =  4293.50s     Snapshot accessibility hierarchy for app with pid 1700
    t =  4293.62s     Find: Descendants matching type Table
    t =  4293.63s     Find: Children matching type Cell
    t =  4293.63s     Find: Identity Binding
    t =  4293.64s     Find: Children matching type StaticText
    t =  4293.64s     Find: Identity Binding
    t =  4293.65s Snapshot accessibility hierarchy for app with pid 1700
2019-09-23 19:30:31.749442+0800 WebDriverAgentRunner-Runner[2386:71867] Running tests...
objc[2386]: Class GCDAsyncSocketPreBuffer is implemented in both /private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/CocoaAsyncSocket.framework/CocoaAsyncSocket (0x102778578) and /private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/RoutingHTTPServer.framework/RoutingHTTPServer (0x1026e1358). One of the two will be used. Which one is undefined.
objc[2386]: Class GCDAsyncReadPacket is implemented in both /private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/CocoaAsyncSocket.framework/CocoaAsyncSocket (0x1027785c8) and /private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/RoutingHTTPServer.framework/RoutingHTTPServer (0x1026e13a8). One of the two will be used. Which one is undefined.
objc[2386]: Class GCDAsyncWritePacket is implemented in both /private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/CocoaAsyncSocket.framework/CocoaAsyncSocket (0x102778618) and /private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/RoutingHTTPServer.framework/RoutingHTTPServer (0x1026e13f8). One of the two will be used. Which one is undefined.
objc[2386]: Class GCDAsyncSpecialPacket is implemented in both /private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/CocoaAsyncSocket.framework/CocoaAsyncSocket (0x102778668) and /private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/RoutingHTTPServer.framework/RoutingHTTPServer (0x1026e1448). One of the two will be used. Which one is undefined.
objc[2386]: Class GCDAsyncSocket is implemented in both /private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/CocoaAsyncSocket.framework/CocoaAsyncSocket (0x1027786b8) and /private/var/containers/Bundle/Application/A18F515B-773A-497F-89F7-29918BC1B713/WebDriverAgentRunner-Runner.app/PlugIns/WebDriverAgentRunner.xctest/Frameworks/RoutingHTTPServer.framework/RoutingHTTPServer (0x1026e1498). One of the two will be used. Which one is undefined.


*** If you believe this error represents a bug, please attach the result bundle at /Users/zhangsan/Library/Developer/Xcode/DerivedData/WebDriverAgent-gepobbogdbbwbigexigktqefklzg/Logs/Test/Test-WebDriverAgentRunner-2019.09.23_17-57-30-+0800.xcresult
共收到 10 条回复 时间 点赞

1、有可能是 iproxy 的问题,即使用了其他端口映射的工具也有可能出现类似的问题,只是时间问题,可以在 python 逻辑程序中的访问 WDA 的接口的时候来个 try except 来捕获异常,重试代理
2、从日志上看,工具运行时间的挺长的,内存使用率达到一定峰值也会销毁 WDA,首先看你的写的逻辑是不是死循环,死循环定时退出循环,来个@autoreleases清理下内存,如果不是的话也只能重试 WDA

匿名 #2 · September 26, 2019
ltyd5788 回复

非常感谢答复,我试了重试,但是因为是 xcodebuild 运行的 WDA 断开,重新运行 xcodebuild 启动 wda 服务后,就算服务起来了,用例也已经全部失败了,内存使用率这块不知道怎么控制,没有死循环,请问 wda 有提供清理内存的接口么?

1、https://github.com/manishPatwari/WebDriverAgent 例子可以看提交的 commit,类似可以在 fb_tree、handleTap 等常用的方法对 xcuitest 相应的 api 嵌套@autoreleasepool ,可以及时释放内存,这种情况对于 Monkey 工具来说是有好处的,常规的业务自动化只能算是小优化吧,并不能解决你遇到的问题,重新看了下日志你这种情况更贴近第二种情况
2、页面底部存在 “加载更多” 功能,使用 XCUITEST 查找元素短时间内会频繁的创建对象,App 也会出现卡死的现象,可以找下有 Table 嵌套的 Cell 页面尝试复现,打开报告面板,观察 Memory 的变化,如果是这种情况解决方法需要研发配合下,具体可以看下 Appium issues 和 WDA issues

3、WDA 断开还有一种情况是端口转发的问题,我仔细复现过这个问题,iproxy 转发出现异常,实际 WDA 是正常运行的,当下一次在发送请求时 WDA 就挂了,所以需要在下一次向 WDA 发送请求时 kill iproxy、start iproxy,可以先加上类似的操作,以免干扰你的判断

匿名 #4 · September 27, 2019
ltyd5788 回复

谢谢,如果是第二种,appium 他们应该会做内存释放吧,而且我有时候会看到这样的日志"xcodebuild iscarding message, buffer is full",感觉是你说的这种 ;对于 3,我做用例前置添加 killall iproxy && iproxy 8100 8100 ,每次用例开始都断掉重连,但是实际情况是用例都直接因为断开而失败了,这个地方该如何处理,搞好几天了,头都大了

匿名 #5 · October 09, 2019

这个 WDA 断开的问题,有谁遇到么,貌似是 result 文件太大导致"Failed to spawn process for sample: 34 - Result too large"

21:10:05.243 WebDriverAgentRunner-Runner[3765:110238] <XCTWaiter: 0x281f15590, state: XCTWaiterStateSucceeded> cleaning up `Loading Accessibility`
21:10:05.246 WebDriverAgentRunner-Runner[3765:110238] Error from daemon in loading AX: Not authorized for performing UI testing actions.
21:10:05.246 WebDriverAgentRunner-Runner[3765:110238] Error capturing sample for process backboardd:
Error Domain=XCTDaemonErrorDomain Code=20 "Failed to spawn process for sample: 34 - Result too large" UserInfo={NSLocalizedDescription=Failed to spawn process for sample: 34 - Result too large}
21:10:05.247 WebDriverAgentRunner-Runner[3765:110238] Error capturing sample for process SpringBoard:
Error Domain=XCTDaemonErrorDomain Code=20 "Failed to spawn process for sample: 34 - Result too large" UserInfo={NSLocalizedDescription=Failed to spawn process for sample: 34 - Result too large}
21:10:05.250 WebDriverAgentRunner-Runner[3765:110238] Failed to load accessibility.
21:10:05.250 WebDriverAgentRunner-Runner[3765:110238] Failed to initialize for UI testing: Error Domain=XCTDaemonErrorDomain Code=41 "Not authorized for performing UI testing actions." UserInfo={samples={
    SpringBoard = "Error Domain=XCTDaemonErrorDomain Code=20 \"Failed to spawn process for sample: 34 - Result too large\" UserInfo={NSLocalizedDescription=Failed to spawn process for sample: 34 - Result too large}";
    backboardd = "Error Domain=XCTDaemonErrorDomain Code=20 \"Failed to spawn process for sample: 34 - Result too large\" UserInfo={NSLocalizedDescription=Failed to spawn process for sample: 34 - Result too large}";
}, NSLocalizedDescription=Not authorized for performing UI testing actions.}
21:10:05.280 xcodebuild[85261:710619] Initialization failure for UI testing: Not authorized for performing UI testing actions.

pytest-rerunfailures,对用例进行重试。
每条用例都重新启动 appium 和 iproxy

匿名 #7 · October 10, 2019
edsion 回复

没用的,如果是代理断开,重启 iproxy 可以,但如果不是代理断开,而是 wda 断开,即使重试,仍然连不上的,只能重新将 wda build 到手机上。

“重新启动 appium” 和 “重新将 wda build 到手机上” 不是一回事吗

之前也遇到此问题,解决方案,以下几点,你逐一试试吧,
1.python3.7.3 升级为 python3.7.4 版本,上一版本有此问题
2.openssl 升级版本
3.防火墙看看关了吗?查看代码是否有循环请求,在同一命令循环快速请求时,报此错误
4.安装 conda,python 和 python3 都指向了 conda(实际就这个方法,碰对了)
挨个试试吧,试了多长时间我就不说了,反正坑到头了

有解决方案嘛

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up