EarlGrey icon indicating copy to clipboard operation
EarlGrey copied to clipboard

EarlGrey 2.0: openDeeplinkURL:inApplication:error fails

Open john-twigg-ck opened this issue 5 years ago • 2 comments

The call

- (BOOL)openDeeplinkURL:(NSString *)URL
          inApplication:(XCUIApplication *)application
                  error:(NSError **)error;

doesn't work on a clean simulator, 13.4.

NOTES:

  • If the landing screen in safari is this screen, it FAILS image

  • if the safari is primed with ANY web page, it WORKS. image

  • There are no unit tests in the FuntionalTests that provide coverage to this feature.

It fails with error:

   t =     6.15s Open com.apple.mobilesafari
    t =     6.17s     Launch com.apple.mobilesafari
    t =     6.21s         Setting up automation session
    t =     6.41s         Wait for com.apple.mobilesafari to idle
    t =     8.98s Wait for com.apple.mobilesafari to become Running Foreground
    t =     8.98s Find the Application 'com.apple.mobilesafari'
    t =     9.10s Tap "URL" Button
    t =     9.10s     Wait for com.apple.mobilesafari to idle
    t =     9.15s     Find the "URL" Button
    t =    10.28s         Find the "URL" Button (retry 1)
    t =    11.39s         Find the "URL" Button (retry 2)
    t =    11.46s         Collecting extra data to assist test failure triage
    t =    11.46s             Requesting snapshot of accessibility hierarchy for app with pid 3529
    t =    11.57s             Requesting snapshot of accessibility hierarchy for app with pid 3529
    t =    11.65s             Find: Descendants matching type Button
    t =    11.66s             Find: Elements matching predicate '"URL" IN identifiers'
    t =    11.79s         Assertion Failure: EarlGrey.m:202: Failed to get matching snapshot: No matches found for Elements matching predicate '"URL" IN identifiers' from input {(
    Button, label: 'Show Toolbar', Disabled,
    Button, identifier: 'shift', label: 'shift',
    Button, label: 'Emoji',
    Button, identifier: 'dictation', label: 'Dictate',
    Button, identifier: 'Go', label: 'go',
    Button, identifier: 'NavigationBarCancelButton', label: 'Cancel',
    Button, identifier: 'BackButton', label: 'Back', Disabled,
    Button, identifier: 'ForwardButton', label: 'Forward', Disabled,
    Button, identifier: 'ShareButton', label: 'Share', Disabled,
    Button, identifier: 'BookmarksButton', label: 'Bookmarks',
    Button, identifier: 'TabsButton', label: 'Tabs'
)}
Possibly caused by runtime issues:
Automation type mismatch: computed WebView from legacy attributes vs ScrollView from modern attribute. Input attributes and values: {
    "XC_kAXXCAttributeAutomationType" = 46;
    "XC_kAXXCAttributeElementBaseType" = UIScrollView;
    "XC_kAXXCAttributeElementType" = WKScrollView;
    "XC_kAXXCAttributeTraits" = 8589934592;
}
Automation type mismatch: computed Button from legacy attributes vs Key from modern attribute. Input attributes and values: {
    "XC_kAXXCAttributeAutomationType" = 20;
    "XC_kAXXCAttributeElementBaseType" = UIAccessibilityElement;
    "XC_kAXXCAttributeElementType" = UIAccessibilityElementKBKey;
    "XC_kAXXCAttributeTraits" = 8589934641;
}
Automation type mismatch: computed TextView from legacy attributes vs Other from modern attribute. Input attributes and values: {
    "XC_kAXXCAttributeAutomationType" = 0;
    "XC_kAXXCAttributeElementBaseType" = UIView;
    "XC_kAXXCAttributeElementType" = WKContentView;
    "XC_kAXXCAttributeTraits" = 140883517505536;
}
Automation type mismatch: computed Button from legacy attributes vs Key from modern attribute. Input attributes and values: {
    "XC_kAXXCAttributeAutomationType" = 20;
    "XC_kAXXCAttributeElementBaseType" = UIAccessibilityElement;
    "XC_kAXXCAttributeElementType" = UIAccessibilityElementKBKey;
    "XC_kAXXCAttributeTraits" = 8589936689;
}
See test report attachments for more detail.

john-twigg-ck avatar May 04 '20 20:05 john-twigg-ck

Can you update EarlGrey.m's openDeepLink method with this and check?

#if defined(__IPHONE_11_0)
- (BOOL)openDeepLinkURL:(NSString *)URL
        withApplication:(XCUIApplication *)application
                  error:(NSError **)error {
#if TARGET_OS_IOS
  XCUIApplication *safariApp =
      [[XCUIApplication alloc] initWithBundleIdentifier:@"com.apple.mobilesafari"];
  [safariApp activate];
  BOOL success = [safariApp waitForState:XCUIApplicationStateRunningForeground timeout:30];
  I_GREYAssertTrue(success, @"Safari did not launch successfully.");

  // As Safari loads up for the first time, the URL is not clickable and we have to wait for the app
  // to be hittable for it.
  if ([safariApp.buttons[@"URL"] waitForExistenceWithTimeout:10] &&
      safariApp.hittable) {
    [safariApp.buttons[@"URL"] tap];
    [safariApp.textFields[@"URL"] typeText:URL];
    [safariApp.buttons[@"Go"] tap];
  } else if (error) {
    *error = GREYErrorMake(kGREYDeeplinkErrorDomain, kGREYInteractionActionFailedErrorCode,
                           @"Deeplink open action failed since URL field not present.");
  }
  XCUIElement *openBtn = safariApp.buttons[@"Open"];
  if ([openBtn waitForExistenceWithTimeout:10]) {
    [safariApp.buttons[@"Open"] tap];
    return YES;
  } else if (error) {
    *error = GREYErrorMake(kGREYDeeplinkErrorDomain, kGREYInteractionActionFailedErrorCode,
                           @"Deeplink open action failed since Open Button on the app dialog for "
                           @"the deeplink not present.");
    // Reset Safari.
    [safariApp terminate];
  }
  // This is needed otherwise failed tests will stall until failure.
  [application activate];
#endif  // TARGET_OS_IOS
  return NO;
}
#endif  // defined(__IPHONE_11_0)

tirodkar avatar May 04 '20 20:05 tirodkar

Will try...

jtwigg avatar May 04 '20 22:05 jtwigg