Appium 无法在 xCode 13.3 和 iOS 15.4 上截屏

Appium unable to take screenshot on xCode 13.3 and iOS 15.4

我几天前醒来 运行 在 iOS 模拟器上进行了 appium UI 自动化测试,运行 完美无误地进行了测试。我最近升级到 iOS 15.4 和 iOS 13.3,令我惊讶的是 Appium 无法再次截屏。我试着检查可能是什么原因,并在此处 Socket hang up error while taking screenshot in appium (iOS 15.4 beta & xCode 13.3 beta 2). I find this as well on Apple post Xcode 12 Beta 3 Release Notes 发现了完全相似的问题。目前有任何解决方法吗?

这是我遇到的错误

[HTTP] --> GET /wd/hub/session/ea84cef2-3649-4e76-91b9-23cec159e3a1/element/1B000000-0000-0000-1439-000000000000/screenshot
[HTTP] {}
[debug] [W3C (ea84cef2)] Calling AppiumDriver.getElementScreenshot() with args: ["1B000000-0000-0000-1439-000000000000","ea84cef2-3649-4e76-91b9-23cec159e3a1"]
[debug] [XCUITest] Executing command 'getElementScreenshot'
[debug] [WD Proxy] Matched '/element/1B000000-0000-0000-1439-000000000000/screenshot' to command name 'getElementScreenshot'
[debug] [Protocol Converter] Did not know how to rewrite the original URL '/element/1B000000-0000-0000-1439-000000000000/screenshot' for W3C protocol
[debug] [WD Proxy] Proxying [GET /element/1B000000-0000-0000-1439-000000000000/screenshot] to [GET http://127.0.0.1:8100/session/88FE5109-F180-482B-B948-980F345404CC/element/1B000000-0000-0000-1439-000000000000/screenshot] with no body
[WD Proxy] Got response with status 500: {"value":{"error":"unable to capture screen","message":"Error Domain=com.facebook.WebDriverAgent Code=1 \"Cannot take a screenshot within 20000 ms timeout\" UserInfo={NSLocalizedDescription=Cannot take a screenshot within 20000 ms timeout}","traceback":""},"sessionId":"88FE5109-F180-482B-B948-980F345404CC"}
[debug] [W3C] Matched W3C error code 'unable to capture screen' to UnableToCaptureScreen
[debug] [W3C (ea84cef2)] Encountered internal error running command: UnableToCaptureScreen: Error Domain=com.facebook.WebDriverAgent Code=1 "Cannot take a screenshot within 20000 ms timeout" UserInfo={NSLocalizedDescription=Cannot take a screenshot within 20000 ms timeout}
[debug] [W3C (ea84cef2)]     at errorFromW3CJsonCode (/Users/kadeoye/.appium/appium-xcuitest-driver/node_modules/appium-base-driver/lib/protocol/errors.js:780:25)
[debug] [W3C (ea84cef2)]     at ProxyRequestError.getActualError (/Users/kadeoye/.appium/appium-xcuitest-driver/node_modules/appium-base-driver/lib/protocol/errors.js:663:14)
[debug] [W3C (ea84cef2)]     at JWProxy.command (/Users/kadeoye/.appium/appium-xcuitest-driver/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:272:19)
[debug] [W3C (ea84cef2)]     at runMicrotasks (<anonymous>)
[debug] [W3C (ea84cef2)]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[debug] [W3C (ea84cef2)]     at XCUITestDriver.proxyCommand (/Users/kadeoye/.appium/appium-xcuitest-driver/node_modules/appium-xcuitest-driver/lib/commands/proxy-helper.js:96:12)
[debug] [W3C (ea84cef2)]     at XCUITestDriver.getElementScreenshot (/Users/kadeoye/.appium/appium-xcuitest-driver/node_modules/appium-xcuitest-driver/lib/commands/screenshots.js:52:16)
[HTTP] <-- GET /wd/hub/session/ea84cef2-3649-4e76-91b9-23cec159e3a1/element/1B000000-0000-0000-1439-000000000000/screenshot 500 20106 ms - 1319

改回iOS 15.2我遇到了同样的问题,苦苦挣扎了好几个小时……什么都试过了……和你的情况完全一样。昨天它在工作,今天突然停止工作。所以最后,唯一的变化是 xcode 模拟器从 15.2 更新到 iOS 15.4。这就是为什么 appium inspector 停止工作并截取屏幕截图的原因。我想从 appium 方面更新需要一些时间,但在那之前只需回到最新的稳定 iOS 模拟器版本 15.2。 如何操作 - Xcode -> 首选项 -> 组件 -> select 旧 iOS 版本模拟器 -> 下载,立即检查并安装 -> 构建 -> 瞧:)

可以通过更改WebDriverAgentLib/Utilities/FBScreenshot.m(第257行)来修复:

(nullable id)screenshotRequestWithScreenID:(unsigned int)screenID

至:

(nullable id)screenshotRequestWithScreenID:(long long)screenID

问题已报告,解决方案也在这里: https://github.com/appium/appium/issues/16604