diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m b/WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m index e86a021de..ab8e25ee9 100644 --- a/WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m +++ b/WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m @@ -55,11 +55,13 @@ - (BOOL)fb_isVisible if (hitPoint != nil && CGRectContainsPoint(appFrame, hitPoint.point)) { return YES; } - for (XCElementSnapshot *elementSnapshot in self.children.copy) { - if (elementSnapshot.fb_isVisible) { - return YES; - } - } + + // the following fallback check is unnecessary and it is adding a lot of overhead when there is a system dialog up +// for (XCElementSnapshot *elementSnapshot in self.children.copy) { +// if (elementSnapshot.fb_isVisible) { +// return YES; +// } +// } return NO; } diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m b/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m index 868dfb687..65b1b44be 100644 --- a/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m +++ b/WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m @@ -67,6 +67,11 @@ - (BOOL)fb_obstructsElement:(XCUIElement *)element - (XCElementSnapshot *)fb_lastSnapshot { [self resolve]; + XCUIElementQuery *webviews = [self webViews]; + NSArray *array = [webviews allElementsBoundByIndex]; + for (XCUIElement *wv in array) { + [wv resolve]; + } return [[self query] elementSnapshotForDebugDescription]; } diff --git a/WebDriverAgentLib/Commands/FBElementCommands.m b/WebDriverAgentLib/Commands/FBElementCommands.m index b8a7ae887..14db3902b 100644 --- a/WebDriverAgentLib/Commands/FBElementCommands.m +++ b/WebDriverAgentLib/Commands/FBElementCommands.m @@ -322,6 +322,12 @@ + (NSArray *)routes + (id)handleDragCoordinate:(FBRouteRequest *)request { + XCUIApplication *app = [[XCUIApplication alloc] initWithBundleIdentifier: @"com.apple.springboard"]; + NSArray *alerts = [[app alerts] allElementsBoundByIndex]; + if (alerts.count > 0) { + return FBResponseWithStatus(FBCommandStatusUnexpectedAlertPresent, @"A modal dialog was open, blocking this operation"); + } + FBSession *session = request.session; CGPoint startPoint = CGPointMake((CGFloat)[request.arguments[@"fromX"] doubleValue], (CGFloat)[request.arguments[@"fromY"] doubleValue]); CGPoint endPoint = CGPointMake((CGFloat)[request.arguments[@"toX"] doubleValue], (CGFloat)[request.arguments[@"toY"] doubleValue]); @@ -371,8 +377,42 @@ + (NSArray *)routes + (id)handleTap:(FBRouteRequest *)request { - FBElementCache *elementCache = request.session.elementCache; CGPoint tapPoint = CGPointMake((CGFloat)[request.arguments[@"x"] doubleValue], (CGFloat)[request.arguments[@"y"] doubleValue]); + + XCUIApplication *app = [[XCUIApplication alloc] initWithBundleIdentifier: @"com.apple.springboard"]; + NSArray *alerts = [[app alerts] allElementsBoundByIndex]; + if (alerts.count > 0) { + XCUIElement *alert = alerts[0]; + NSArray *texts = [[alert staticTexts] allElementsBoundByIndex]; + NSString *title = [texts[0] label]; + NSString *subtitle = [texts[1] label]; + NSArray *buttons = [[alert buttons] allElementsBoundByIndex]; + for (XCUIElement *button in buttons) { + if (CGRectContainsPoint(button.frame, tapPoint)) { + NSString *label = [button label]; + [button tap]; + return FBResponseWithStatus(FBCommandStatusNoError, @{ + @"action": @"tap", + @"element": @"button", + @"id": label, + @"point": @{ + @"x": @(tapPoint.x), + @"y": @(tapPoint.y) + }, + @"alert":@{ + @"title" : title != nil ? title : @"", + @"subtitle" : subtitle != nil ? subtitle : @"" + } + }); + } + } + + if (alerts.count > 0) { + return FBResponseWithStatus(FBCommandStatusUnexpectedAlertPresent, @"A modal dialog was open, blocking this operation"); + } + } + + FBElementCache *elementCache = request.session.elementCache; XCUIElement *element = [elementCache elementForUUID:request.parameters[@"uuid"]]; if (nil == element) { XCUICoordinate *tapCoordinate = [self.class gestureCoordinateWithCoordinate:tapPoint application:request.session.application shouldApplyOrientationWorkaround:isSDKVersionLessThan(@"11.0")]; diff --git a/WebDriverAgentLib/Utilities/FBKeyboard.m b/WebDriverAgentLib/Utilities/FBKeyboard.m index f26dcb5ad..00dc6f542 100644 --- a/WebDriverAgentLib/Utilities/FBKeyboard.m +++ b/WebDriverAgentLib/Utilities/FBKeyboard.m @@ -33,9 +33,9 @@ + (BOOL)typeText:(NSString *)text error:(NSError **)error + (BOOL)typeText:(NSString *)text frequency:(NSUInteger)frequency error:(NSError **)error { - if (![FBKeyboard waitUntilVisibleWithError:error]) { - return NO; - } +// if (![FBKeyboard waitUntilVisibleWithError:error]) { +// return NO; +// } __block BOOL didSucceed = NO; __block NSError *innerError; [FBRunLoopSpinner spinUntilCompletion:^(void(^completion)(void)){