我编写了一个测试,该测试应该等待 15 秒才能评估条件。它目前等待的时间要短得多,并立即进入评估 block ,产生错误。之后的秒参数: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. ");
}
这是按钮点击 Action :
- (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 秒后通过分派(dispatch)异步更改为“延迟出现”。但是测试中的 block 触发非常快,尽管它设置为 15 秒。 (并且失败,因为没有找到具有此类文本的元素)。
最佳答案
我认为这不是 API 的意图。 API 用于等待满足 X 秒的条件。超时中的秒参数是真正应该等待条件满足的时间。如果届时仍不满足条件,则超时并返回NO。如果您真的只想等待 15 秒,请使用:
[[NSRunLoop currentRunLoop] runUntilDate:]
而且,由于您使用的是 dispatch_after,因此可以增加 dispatch_after 调用的跟踪时间:
[[GREYConfiguration sharedInstance] setValue:@(5.0)
forConfigKey:kGREYConfigKeyDispatchAfterMaxTrackableDelay];
如果您不再希望在未来 5.0 秒的调用后跟踪调度,请记住将其重置为默认值。
关于ios - EarlGrey GREY条件 waitWithTimeout :15 does not wait for 15 seconds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37528892/