为什么我在 iOS 真实设备上进行 运行 移动网络测试时收到“[XCUITest] 未能在超时内接收任何数据:5000”错误?

Why am I getting an "[XCUITest] Failed to receive any data within the timeout: 5000" error when running mobile web tests on iOS real device?

我目前正在尝试 运行 在真实的 iOS 设备上使用 Appium 进行测试,使用 pytest 和 selenium 框架。在 运行ning 测试之前,我成功地将 WebDriverAgent 构建到设备上并启动了 Appium 服务器。输入 pytest 命令开始测试后,iOS 设备中的 Safari 浏览器打开,但测试没有启动。我在 Appium 日志中收到此错误:

[debug] [iProxy@67f2ea78:8100] Closing the connection
[debug] [DevCon Factory] Cached connections count: 0
[debug] [XCUITest] Not clearing log files. Use `clearSystemFiles` capability to turn on.
[debug] [XCUITest] Found a remote debugger session. Removing...
[debug] [RemoteDebugger] Cleaning up listeners
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1639089800521 (14:43:20 GMT-0800 (Pacific Standard Time))
[debug] [W3C] Encountered internal error running command: Error: Could not navigate to webview! Err: Failed to receive any data within the timeout: 5000
[debug] [W3C]     at spinHandles (/Users/user/.nvm/versions/node/v17.0.1/lib/node_modules/appium/node_modules/appium-ios-driver/lib/commands/context.js:522:23)
[debug] [W3C]     at XCUITestDriver.navToViewWithTitle (/Users/user/.nvm/versions/node/v17.0.1/lib/node_modules/appium/node_modules/appium-ios-driver/lib/commands/context.js:564:3)
[debug] [W3C]     at XCUITestDriver.navToInitialWebview (/Users/user/.nvm/versions/node/v17.0.1/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/context.js:29:5)
[debug] [W3C]     at XCUITestDriver.start (/Users/user/.nvm/versions/node/v17.0.1/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/driver.js:479:7)
[debug] [W3C]     at XCUITestDriver.createSession (/Users/user/.nvm/versions/node/v17.0.1/lib/node_modules/appium/node_modules/appium-xcuitest-driver/lib/driver.js:215:7)
[debug] [W3C]     at AppiumDriver.createSession (/Users/user/.nvm/versions/node/v17.0.1/lib/node_modules/appium/lib/appium.js:371:35)
[debug] [W3C] Caused by: Error: Failed to receive any data within the timeout: 5000
[debug] [W3C]     at Timeout._onTimeout (/Users/user/.nvm/versions/node/v17.0.1/lib/node_modules/appium/node_modules/appium-ios-device/lib/plist-service/index.js:67:16)
[debug] [W3C]     at listOnTimeout (node:internal/timers:557:17)
[debug] [W3C]     at processTimers (node:internal/timers:500:7)
[HTTP] <-- POST /wd/hub/session 500 14924 ms - 741
[HTTP] 
[iProxy@67f2ea78:8100] The connection has been closed

有没有人遇到过这个问题并找到了解决方案?

能力={ “平台名称”:settings.MOBILE_DEVICE_PLATFORM, “平台版本”:_platform_version, “新命令超时”:3000, "udid": _device_id, "automationName" = "XCUITest", "浏览器名称" = "野生动物园", “usePrebuiltWDA”:是的, “设备名称”:“iPhone }

Appium 版本:1.22.1

XCode 版本:13.1 (13A1030d)

iOS 设备版本:15.1

节点版本:17.0.1

NVM 版本:0.39.0

不确定原因或方式,但我的问题已通过使用 Appium Desktop 解决。

这是因为当我们以编程方式访问时,IOSDriver 导致的。 Android 工作正常。

org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Failed to receive any data within the timeout: 5000

这里失败了。

driver = new IOSDriver<>(new URL(remoteUrl.toString()), desiredCapabilities);

AppiumServiceBuilder serviceBuilder = new AppiumServiceBuilder();
    serviceBuilder.usingAnyFreePort();
    serviceBuilder.usingDriverExecutable(new File(Appium_Node_Path));
    serviceBuilder.withAppiumJS(new File(Appium_JS_Path));
    HashMap<String, String> environment = new HashMap<String,String>();
    environment.put("PATH", "/usr/local/bin:" + System.getenv("PATH"));
    serviceBuilder.withEnvironment(environment);
    server = AppiumDriverLocalService.buildService(serviceBuilder);
    server.start();
    server.isRunning();
driver = new IOSDriver<>(new URL(remoteUrl.toString()), desiredCapabilities);

Mac OS version 12.2.1 Xcode version 13.2.1 Appium 1.22.2

如果直接使用 WDA 没有问题 运行 Appium 桌面服务器工作正常。

 URL remoteUrl = new URL("http://0.0.0.0:4723/wd/hub");
    driver = new IOSDriver<>(remoteUrl, desiredCapabilities);