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

我仍然在学习如何正确使用UItesting。

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

在这里输入图像说明

我在使用模拟器时遇到同样的问题。 我试着在设备上运行testing用例,它工作正常。 所以在实际设备上运行,看看是否出现错误。

你不应该在你的testing中使用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); 

这个例子来自我的UItesting备忘单 。 如果您刚开始使用UItesting,我build议您检查一下。

重置模拟器解决了我的问题。 它可以通过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