Skip to content
This repository was archived by the owner on Dec 26, 2019. It is now read-only.

Added support to get source for WKWebView #964

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions WebDriverAgentLib/Categories/XCUIElement+FBUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
42 changes: 41 additions & 1 deletion WebDriverAgentLib/Commands/FBElementCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ + (NSArray *)routes

+ (id<FBResponsePayload>)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]);
Expand Down Expand Up @@ -371,8 +377,42 @@ + (NSArray *)routes

+ (id<FBResponsePayload>)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")];
Expand Down
6 changes: 3 additions & 3 deletions WebDriverAgentLib/Utilities/FBKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down