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

时间:2015-03-23 22:36:12

标签: c# ios appium ios-ui-automation ui-testing

我在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.");

添加之后,我只能偶尔成功启动测试。大部分时间我看到应用程序已启动,警报已关闭,主要活动显示,但测试失败。我在日志中看到的是:

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 参数,我需要手动关闭警报,但是大约一秒钟之后就会进行评估,并且测试运行正常。

也许有人偶然发现了类似的问题并且对于发生了什么有一些洞察力?真的很感激。

1 个答案:

答案 0 :(得分:1)

经过一段时间的试验和错误后,我更换了

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 会导致这个问题,但是现在我很高兴。