Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure my EarlGrey test to wait for a view or an event?

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?

like image 336
gran_profaci Avatar asked Feb 17 '16 03:02

gran_profaci


1 Answers

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.
}
like image 93
khandpur Avatar answered Oct 15 '22 14:10

khandpur