我有一个案例,我想等待一个视图出现,但如果它没有出现我想只记录它,没有KIF超时并引发异常。我尝试使用@try/@catch
块,但它似乎没有抓住它。研究表明这可能是KIF的限制,但只是想验证。我不想仅仅针对这一情况修改failWithException
,因为每次我都希望测试失败。
我尝试过的例子:
@try {
[tester waitForViewWithAccessibilityLabel:@"Foo"];
}
@catch (NSException *exception) {
[TestLogger logTestMethodFailed:[NSString stringWithFormat:@"%@ on %@", self.currentTest, [[UIDevice currentDevice] name]] withExceptionMessage:@"LOGOUT FAILED! Didn't find 'foo' element. This may be acceptable if the test does not need to log out."];
}
答案 0 :(得分:0)
您应该使用Test
代替tryFindingView
。见下文:
waitForViewWithAccessibilityLabel
此外,您可以使用与此版本相同的 do {
try tester().tryFindingView(withAccessibilityLabel: "Foo")
} catch {
//it will wait to find the view if does not find it it comes here and you can do your stuff here.
}
。