2

I have a case where i want to wait for a view to appear, but if it doesn't appear I want to just log it, without KIF timing out and raising an exception. I tried using a @try/@catch block, but it didn't seem to catch it. Research suggests this may be a limitation of KIF, but just wanted to verify. I don't want to modify failWithException for just this one case, since every other time I do want the test to fail.

Example of what I tried:

@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."];
}
4

1 回答 1

0

您应该使用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. 
 }

您也可以使用tryFindingTappableView与此相同的。

于 2018-05-09T20:19:10.517 回答