我寫了一個測試,應該等待15秒才能評估一個條件。它目前等待時間更短,並立即進入評估塊,產生錯誤。 waitWithTimeout之後的seconds參數似乎被忽略。EarlGrey GREYCondition waitWithTimeout:15不等待15秒
我的測試代碼:
- (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秒。 (並且因爲沒有找到具有這種文本的元素而失敗)。
我通過禁用GRAY API上的同步來解決此問題,如下所示:[[GREYConfiguration sharedInstance] setValue:@(NO) forConfigKey:kGREYConfigKeySynchronizationEnabled];它現在等待我指定的全部金額。所以我想知道是什麼導致它在啓用同步API時提前觸發.... – Alex