iOS UI测试:获取活动应用程序列表失败:AX错误-25205

时间:2016-03-21 14:18:43

标签: ios xcode-ui-testing

我还在学习如何正确使用UI测试。

我在后台登录,之后,我在新闻Feed中显示结果。然后,我点击更多按钮。当有Web服务时,我看起来无法从我的api获得结果。它总是像这样失败,我的api数据也没有显示出来。我该怎么办?

enter image description here

3 个答案:

答案 0 :(得分:2)

我在使用模拟器时遇到了同样的问题。我尝试在设备上运行测试用例,它运行正常。因此,请在实际设备上运行,看看是否出现错误。

答案 1 :(得分:1)

您不应该在测试中使用sleep()。相反,使用本机API等待元素存在。例如,您可以等到“竞赛”文本显示以下内容:

XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *moreButton = app.tabBars.buttons[@"More"];

XCUIElement *contestsText = app.staticTexts[@"Contests"];
NSPredicate *exists = [NSPredicate predicateWithFormat:@"exists == YES"];
[self expectationForPredicate:exists evaluatedWithObject:contestsText handler:nil];

[moreButton tap];

[self waitForExpectationsWithTimeout:5.0f handler:nil];
XCTAssert(contestsText.exists);

此示例来自我的UI Testing Cheat Sheet。如果您刚刚开始使用UI测试,我建议您查看它。

答案 2 :(得分:0)

重置模拟器为我解决了这个问题。可以通过模拟器主菜单中的Simulator - Reset Content and Settings...来完成。

要与CI系统一起使用,这些命令可能有所帮助:

osascript -e 'tell application "iOS Simulator" to quit'
osascript -e 'tell application "Simulator" to quit'
xcrun simctl erase all