我写了一个测试,它应该在评估条件之前等待 15 秒。它目前等待的时间要短得多,并立即进入评估块,产生错误。之后的秒参数:waitWithTimeout 似乎被忽略了。
我的测试代码:
- (void)testAsyncEvent {
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Button")]
performAction:grey_tap()];
// Wait for the main view controller to become the root view controller.
BOOL success = [[GREYCondition conditionWithName:@"Wait for label to change text"
block:^{
NSError *error;
[[EarlGrey selectElementWithMatcher:grey_text(@"Delayed Appearance")]
performAction:grey_tap()
error:&error];
if ([error.domain isEqual:kGREYInteractionErrorDomain] &&
error.code == kGREYInteractionElementNotFoundErrorCode) {
return NO;
}
return YES;
}] waitWithTimeout:15];
GREYAssertTrue(success, @"Label text should be changed after 5 seconds. ");
}
这是按钮点击操作:
- (IBAction)buttonPressed:(id)sender
{
self.titleLabel.text = @"Button Pressed";
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 4 * NSEC_PER_SEC), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),
^(void)
{
dispatch_async(dispatch_get_main_queue(), ^{
self.titleLabel.text = @"Delayed Appearance";
});
});
}
titleLabel 的文本应该在 4 秒后通过异步调度更改为“延迟外观”。但是测试中的块触发非常快,尽管它设置为 15 秒。(并且失败,因为没有找到具有此类文本的元素)。