I'm writing a test where I need to wait for a particular view to show up in my UI using the EarlGrey
UI Testing framework. So, I looked at the docs here and am trying to achieve this using GREYCondition
. But it seems as though GREYCondition
requires a particular condition check or so to be used. Can anyone advise me as to what the format of the condition is? Is there any way by which I can pass in my view to the condition to make it wait for it?
Typically you shouldn’t have to wait for a particular view as EarlGrey’s built-in synchronization should automatically do that for you. There are various settings in GREYConfiguration that can be tweaked to increase (or decrease) the extent to which EarlGrey synchronizes. If none of those settings work, you can add explicit synchronization with something like the GREYCondition
that you’ve created and use the top-level EarlGrey API to determine whether a view exists.
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.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With