Usually you donβt have to wait for a certain presentation, as the built-in EarlGreys synchronization should automatically do this for you. There are various GREYConfiguration settings that you can configure to increase (or decrease) the extent to which EarlGrey is synchronized. If none of these options work, you can add explicit synchronization with something like the GREYCondition you created and use the top-level EarlGrey API to determine if the 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. }
source share