我正在编写一个测试,我需要等待特定视图使用EarlGrey
UI测试框架在我的UI中显示。所以,我查看了文档here,并尝试使用GREYCondition
实现此目的。但似乎GREYCondition
需要特定的条件检查才能使用。任何人都可以告诉我这种情况的格式是什么?我有什么方法可以通过我的观点来传达它等待它的条件吗?
答案 0 :(得分:7)
通常,您不必等待特定视图,因为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.
}