【问题标题】:Is it possible to catch a KIF timeout?是否可以捕获 KIF 超时?
【发布时间】:2014-12-20 15:27:32
【问题描述】:

我有一种情况,我想等待视图出现,但如果它没有出现,我只想记录它,而不会出现 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."];
}

【问题讨论】:

    标签: kif-framework kif


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-03-01
      • 2018-02-28
      • 2018-09-17
      • 2011-06-18
      • 2019-04-02
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      相关资源
      最近更新 更多