I wrote a test that is supposed to wait for 15 seconds before evaluating a condition. It currently waits much shorter, and goes to the evaluation block right away, producing an error. The seconds parameter after: waitWithTimeout seems to be getting ignored.
My Test Code:
- (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. ");
}
And here is the Button tap 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's text is supposed to change to "Delayed Appearance" after 4 seconds through dispatch Async. But the block in the test fires very quickly, although it's set to 15 seconds. (And fails because no element with such text is found).