无法使用 autoAcceptAlerts 运行 Appium 在 iOS 上进行测试

Unable to run Appium tests on iOS using autoAcceptAlerts

我在 Mac OS X 上使用 Appium 1.3.6,并用 C# 编写我的测试。 我已将 autoAcceptAlerts 功能参数添加到我的测试初始化​​中,所以它看起来像这样:

Console.WriteLine("Connecting to Appium server...");
capabilities = new DesiredCapabilities();
capabilities.SetCapability(CapabilityType.BrowserName, "iOS");
capabilities.SetCapability(CapabilityType.Platform, "Mac 10.10");
capabilities.SetCapability(CapabilityType.Version, version);
capabilities.SetCapability("deviceName", device);
capabilities.SetCapability("autoAcceptAlerts", true);

driver = new IOSDriver(new Uri("my-appium-URL"), capabilities);

Console.WriteLine("Connection established.");

而且我加了之后,只能偶尔成功启动测试。大多数时候我看到应用程序已启动,警报已关闭,main activity 显示,但随后测试失败。我在日志中看到的是:

Given I start app for iOS 8.1 on iPad Retina
Connecting to Appium server...
-> error: The HTTP request to the remote WebDriver server for URL <my-appium-URL> timed out after 60 seconds.

并且来自 Appium 日志:

info: [debug] [INST] 2015-03-23 22:29:39 +0000 Debug: target.frontMostApp().alert().buttons()[1].tap()
info: [debug] [INST] 2015-03-23 22:29:40 +0000 Debug: Waiting for alert to close...
info: [debug] [INST] 2015-03-23 22:29:40 +0000 Debug: Waiting for alert to close...
info: [debug] [INST] 2015-03-23 22:29:41 +0000 Debug: Got new command 1 from instruments: au.setScreenOrientation('PORTRAIT')
info: [debug] [INST] 2015-03-23 22:29:41 +0000 Debug: evaluating au.setScreenOrientation('PORTRAIT')
info: [debug] [INST] 2015-03-23 22:29:41 +0000 Debug: target.setDeviceOrientation("1")
info: [debug] [INST] 2015-03-23 22:29:42 +0000 Debug: evaluation finished
info: [debug] [INST] 2015-03-23 22:29:42 +0000 Debug: responding with:
info: [debug] [INST] 2015-03-23 22:29:42 +0000 Debug: Running system command #2: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":"PORTRAIT"}...
info: [debug] Socket data received (33 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":"PORTRAIT"}
info: [debug] Waiting for app source to contain elements
info: [debug] Pushing command to appium work queue: "au.mainApp().getTreeForXML()"
info: [debug] Sending command to instruments: au.mainApp().getTreeForXML()
info: [debug] [INST] 2015-03-23 22:29:43 +0000 Debug: Got new command 2 from instruments: au.mainApp().getTreeForXML()
info: [debug] [INST] 2015-03-23 22:29:43 +0000 Debug: evaluating au.mainApp().getTreeForXML()
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.6","revision":"004f52f249d3513809e7d0734d9205d1fec19f8e"},"isShuttingDown":false},"sessionId":"86e71593-3f35-4cbb-a7d4-a53b0eb38a4d"}

所以,au.mainApp().getTreeForXML() 没有被及时评估。如果我从 init 中删除 autoAcceptAlerts 参数,我需要手动关闭警报,但评估会在一秒钟左右后发生,并且测试运行正常。

也许有人偶然发现了类似的问题并且对正在发生的事情有某种了解?非常感谢。

经过相当长一段时间的反复试验,我更换了

capabilities.SetCapability("autoAcceptAlerts", true);
driver = new IOSDriver(new Uri("my-appium-URL"), capabilities);

driver = new IOSDriver(new Uri("my-appium-URL"), capabilities);
driver.SwitchTo().Alert().Accept();

一切正常。尽管如此,还是很高兴知道为什么 autoAcceptAlerts 会导致这个问题,但现在我很高兴。