2016-02-17 22 views
5

我正在写一个测试,我需要等待一个特定的视图出现在我的UI中,使用EarlGrey UI测试框架。因此,我查看了文档here,并试图使用GREYCondition来实现此目的。但似乎GREYCondition需要使用特定的条件检查。任何人都可以告诉我这种情况的格式是什么?在我看来,有什么办法可以让它等待呢?如何配置我的EarlGrey测试以等待视图或事件?

回答

6

通常,您不应该等待特定的视图,因为EarlGrey的内置同步应该自动为您执行此操作。 GREYConfiguration中有各种设置可以调整以增加(或减少)EarlGrey同步的程度。如果这些设置都不起作用,则可以使用您创建的GREYCondition之类的内容添加显式同步,并使用顶级EarlGrey API来确定是否存在视图。

GREYCondition *waitForFoo = [[GREYCondition conditionWithName:@"wait for Foo" block:^BOOL{ 
    NSError *error; 
    // Checking if a view with accessibility ID "Foo" exists: 
    [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@”Foo”)] 
     assertWithMatcher:grey_notNil() error:&error]; 
    return error == nil; 
}]; 

// Wait until 5 seconds for the view. 
BOOL fooExists = [waitForFoo waitWithTimeout:5]; 
if (fooExists) { 
    // Interact with Foo. 
} 
+0

非常感谢! –