How to set up an EarlGrey test to wait for a view or event?

I am writing a test where I need to wait for a certain type to appear in my user interface using the EarlGrey UI Testing framework. So, I looked at the docs here and am trying to achieve this using GREYCondition . But it seems that GREYCondition requires a certain state check or so that it is used. Can someone advise me in what format this condition is? Is there a way by which I can convey in my opinion a condition to make it wait for it?

+5
source share
1 answer

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. } 
+7
source

Source: https://habr.com/ru/post/1243186/


All Articles