From 344f11ca06a65d549098be27f04d97dda1a57fc5 Mon Sep 17 00:00:00 2001 From: Suman Cherukuri Date: Wed, 18 Jul 2018 15:39:54 -0700 Subject: [PATCH 1/2] Added support to get source for WKWebView --- WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m | 5 +++++ 1 file changed, 5 insertions(+) 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]; } From 0921cd25cd7c63b435eedc978c9a1435db5d476e Mon Sep 17 00:00:00 2001 From: Suman Cherukuri Date: Wed, 29 Aug 2018 14:56:28 -0700 Subject: [PATCH 2/2] Text input was very slow. Removed the wait for the keyboard to be visible Support for tap when system dialog is up Getting source was very slow when system dialog is up. Removed the test on the child object --- .../Categories/XCUIElement+FBIsVisible.m | 12 +++--- .../Commands/FBElementCommands.m | 42 ++++++++++++++++++- WebDriverAgentLib/Utilities/FBKeyboard.m | 6 +-- 3 files changed, 51 insertions(+), 9 deletions(-) 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/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)){