From 259f7319305b15a3f541957d3ccaa3cb12c9e1a3 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Thu, 18 May 2023 09:25:41 +0200 Subject: [PATCH] chore: Drop obsolete workarounds for coordinates calculation (#701) --- WebDriverAgent.xcodeproj/project.pbxproj | 12 -- .../Categories/XCUIApplication+FBHelpers.m | 4 +- .../Categories/XCUIElement+FBForceTouch.m | 8 +- .../Categories/XCUIElement+FBTap.h | 35 ----- .../Categories/XCUIElement+FBTap.m | 32 ----- .../Categories/XCUIElement+FBTyping.m | 3 +- .../Commands/FBElementCommands.m | 135 ++++++------------ WebDriverAgentLib/FBAlert.m | 24 ++-- WebDriverAgentLib/WebDriverAgentLib.h | 1 - .../IntegrationTests/FBAlertTests.m | 5 +- .../FBAutoAlertsHandlerTests.m | 4 +- .../FBElementAttributeTests.m | 2 +- .../IntegrationTests/FBTapTest.m | 17 +-- 13 files changed, 77 insertions(+), 205 deletions(-) delete mode 100644 WebDriverAgentLib/Categories/XCUIElement+FBTap.h delete mode 100644 WebDriverAgentLib/Categories/XCUIElement+FBTap.m diff --git a/WebDriverAgent.xcodeproj/project.pbxproj b/WebDriverAgent.xcodeproj/project.pbxproj index b719df35b..eafb306ad 100644 --- a/WebDriverAgent.xcodeproj/project.pbxproj +++ b/WebDriverAgent.xcodeproj/project.pbxproj @@ -112,7 +112,6 @@ 641EE6222240C5CA00173FCB /* FBApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = EE9AB7671CAEDF0C008C271F /* FBApplication.m */; }; 641EE6232240C5CA00173FCB /* FBScreen.m in Sources */ = {isa = PBXBuildFile; fileRef = 715AFAC01FFA29180053896D /* FBScreen.m */; }; 641EE6242240C5CA00173FCB /* FBXCTestDaemonsProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = EE35AD7A1E3B80C000A02D78 /* FBXCTestDaemonsProxy.m */; }; - 641EE6252240C5CA00173FCB /* XCUIElement+FBTap.m in Sources */ = {isa = PBXBuildFile; fileRef = EE9AB74C1CAEDF0C008C271F /* XCUIElement+FBTap.m */; }; 641EE6262240C5CA00173FCB /* FBMathUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = EE1888391DA661C400307AA8 /* FBMathUtils.m */; }; 641EE6272240C5CA00173FCB /* FBXCAXClientProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 7157B290221DADD2001C348C /* FBXCAXClientProxy.m */; }; 641EE6312240C5CA00173FCB /* XCUIElement+FBWebDriverAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = EEE376471D59FAE900ED88DD /* XCUIElement+FBWebDriverAttributes.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -161,7 +160,6 @@ 641EE65D2240C5CA00173FCB /* XCTRunnerAutomationSession.h in Headers */ = {isa = PBXBuildFile; fileRef = EE35ACEE1E3B77D600A02D78 /* XCTRunnerAutomationSession.h */; settings = {ATTRIBUTES = (Public, ); }; }; 641EE65F2240C5CA00173FCB /* XCSourceCodeTreeNodeEnumerator.h in Headers */ = {isa = PBXBuildFile; fileRef = EE35ACC61E3B77D600A02D78 /* XCSourceCodeTreeNodeEnumerator.h */; settings = {ATTRIBUTES = (Public, ); }; }; 641EE6602240C5CA00173FCB /* XCUIElement+FBIsVisible.h in Headers */ = {isa = PBXBuildFile; fileRef = EE9AB7471CAEDF0C008C271F /* XCUIElement+FBIsVisible.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 641EE6612240C5CA00173FCB /* XCUIElement+FBTap.h in Headers */ = {isa = PBXBuildFile; fileRef = EE9AB74B1CAEDF0C008C271F /* XCUIElement+FBTap.h */; settings = {ATTRIBUTES = (Public, ); }; }; 641EE6622240C5CA00173FCB /* FBResponsePayload.h in Headers */ = {isa = PBXBuildFile; fileRef = EE9AB7821CAEDF0C008C271F /* FBResponsePayload.h */; settings = {ATTRIBUTES = (Public, ); }; }; 641EE6632240C5CA00173FCB /* FBUnknownCommands.h in Headers */ = {isa = PBXBuildFile; fileRef = EE9AB7641CAEDF0C008C271F /* FBUnknownCommands.h */; }; 641EE6642240C5CA00173FCB /* NSPredicate+FBFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 71A224E31DE2F56600844D55 /* NSPredicate+FBFormat.h */; }; @@ -571,8 +569,6 @@ EE158AB11CBD456F00A3E3F0 /* XCUIElement+FBIsVisible.m in Sources */ = {isa = PBXBuildFile; fileRef = EE9AB7481CAEDF0C008C271F /* XCUIElement+FBIsVisible.m */; }; EE158AB21CBD456F00A3E3F0 /* XCUIElement+FBScrolling.h in Headers */ = {isa = PBXBuildFile; fileRef = EE9AB7491CAEDF0C008C271F /* XCUIElement+FBScrolling.h */; settings = {ATTRIBUTES = (Public, ); }; }; EE158AB31CBD456F00A3E3F0 /* XCUIElement+FBScrolling.m in Sources */ = {isa = PBXBuildFile; fileRef = EE9AB74A1CAEDF0C008C271F /* XCUIElement+FBScrolling.m */; }; - EE158AB41CBD456F00A3E3F0 /* XCUIElement+FBTap.h in Headers */ = {isa = PBXBuildFile; fileRef = EE9AB74B1CAEDF0C008C271F /* XCUIElement+FBTap.h */; settings = {ATTRIBUTES = (Public, ); }; }; - EE158AB51CBD456F00A3E3F0 /* XCUIElement+FBTap.m in Sources */ = {isa = PBXBuildFile; fileRef = EE9AB74C1CAEDF0C008C271F /* XCUIElement+FBTap.m */; }; EE158AB81CBD456F00A3E3F0 /* FBAlertViewCommands.h in Headers */ = {isa = PBXBuildFile; fileRef = EE9AB7501CAEDF0C008C271F /* FBAlertViewCommands.h */; }; EE158AB91CBD456F00A3E3F0 /* FBAlertViewCommands.m in Sources */ = {isa = PBXBuildFile; fileRef = EE9AB7511CAEDF0C008C271F /* FBAlertViewCommands.m */; }; EE158ABA1CBD456F00A3E3F0 /* FBCustomCommands.h in Headers */ = {isa = PBXBuildFile; fileRef = EE9AB7521CAEDF0C008C271F /* FBCustomCommands.h */; }; @@ -1272,8 +1268,6 @@ EE9AB7481CAEDF0C008C271F /* XCUIElement+FBIsVisible.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XCUIElement+FBIsVisible.m"; sourceTree = ""; }; EE9AB7491CAEDF0C008C271F /* XCUIElement+FBScrolling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XCUIElement+FBScrolling.h"; sourceTree = ""; }; EE9AB74A1CAEDF0C008C271F /* XCUIElement+FBScrolling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XCUIElement+FBScrolling.m"; sourceTree = ""; }; - EE9AB74B1CAEDF0C008C271F /* XCUIElement+FBTap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XCUIElement+FBTap.h"; sourceTree = ""; }; - EE9AB74C1CAEDF0C008C271F /* XCUIElement+FBTap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XCUIElement+FBTap.m"; sourceTree = ""; }; EE9AB7501CAEDF0C008C271F /* FBAlertViewCommands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBAlertViewCommands.h; sourceTree = ""; }; EE9AB7511CAEDF0C008C271F /* FBAlertViewCommands.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBAlertViewCommands.m; sourceTree = ""; }; EE9AB7521CAEDF0C008C271F /* FBCustomCommands.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBCustomCommands.h; sourceTree = ""; }; @@ -1757,8 +1751,6 @@ EE9AB74A1CAEDF0C008C271F /* XCUIElement+FBScrolling.m */, 71F5BE21252E576C00EE9EBA /* XCUIElement+FBSwiping.h */, 71F5BE22252E576C00EE9EBA /* XCUIElement+FBSwiping.m */, - EE9AB74B1CAEDF0C008C271F /* XCUIElement+FBTap.h */, - EE9AB74C1CAEDF0C008C271F /* XCUIElement+FBTap.m */, AD76723B1D6B7CC000610457 /* XCUIElement+FBTyping.h */, AD76723C1D6B7CC000610457 /* XCUIElement+FBTyping.m */, 71B49EC51ED1A58100D51AD6 /* XCUIElement+FBUID.h */, @@ -2299,7 +2291,6 @@ 641EE65D2240C5CA00173FCB /* XCTRunnerAutomationSession.h in Headers */, 641EE65F2240C5CA00173FCB /* XCSourceCodeTreeNodeEnumerator.h in Headers */, 641EE6602240C5CA00173FCB /* XCUIElement+FBIsVisible.h in Headers */, - 641EE6612240C5CA00173FCB /* XCUIElement+FBTap.h in Headers */, 641EE6622240C5CA00173FCB /* FBResponsePayload.h in Headers */, 641EE6632240C5CA00173FCB /* FBUnknownCommands.h in Headers */, 641EE7062240CDCF00173FCB /* XCUIElement+FBTVFocuse.h in Headers */, @@ -2536,7 +2527,6 @@ EE35AD371E3B77D600A02D78 /* XCSourceCodeTreeNodeEnumerator.h in Headers */, EE158AB01CBD456F00A3E3F0 /* XCUIElement+FBIsVisible.h in Headers */, 71414ED42670A1EE003A8C5D /* LRUCache.h in Headers */, - EE158AB41CBD456F00A3E3F0 /* XCUIElement+FBTap.h in Headers */, EE158ADC1CBD456F00A3E3F0 /* FBResponsePayload.h in Headers */, 13815F6F2328D20400CDAB61 /* FBActiveAppDetectionPoint.h in Headers */, EE158ACC1CBD456F00A3E3F0 /* FBUnknownCommands.h in Headers */, @@ -3159,7 +3149,6 @@ 641EE6232240C5CA00173FCB /* FBScreen.m in Sources */, 71D04DCB25356C43008A052C /* XCUIElement+FBCaching.m in Sources */, 641EE6242240C5CA00173FCB /* FBXCTestDaemonsProxy.m in Sources */, - 641EE6252240C5CA00173FCB /* XCUIElement+FBTap.m in Sources */, 13DE7A58287CA1EC003243C6 /* FBXCElementSnapshotWrapper.m in Sources */, 641EE6262240C5CA00173FCB /* FBMathUtils.m in Sources */, 641EE6272240C5CA00173FCB /* FBXCAXClientProxy.m in Sources */, @@ -3292,7 +3281,6 @@ 715AFAC21FFA29180053896D /* FBScreen.m in Sources */, 71B155DC230711E900646AFB /* FBCommandStatus.m in Sources */, EE35AD7C1E3B80C000A02D78 /* FBXCTestDaemonsProxy.m in Sources */, - EE158AB51CBD456F00A3E3F0 /* XCUIElement+FBTap.m in Sources */, EE18883B1DA661C400307AA8 /* FBMathUtils.m in Sources */, 7157B292221DADD2001C348C /* FBXCAXClientProxy.m in Sources */, ); diff --git a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m index 086643296..ec752c5a0 100644 --- a/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m +++ b/WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m @@ -256,7 +256,7 @@ - (BOOL)fb_dismissKeyboardWithKeyNames:(nullable NSArray *)keyNames continue; } - [matchedKey fb_tapWithError:nil]; + [matchedKey tap]; if (isKeyboardInvisible()) { return YES; } @@ -269,7 +269,7 @@ - (BOOL)fb_dismissKeyboardWithKeyNames:(nullable NSArray *)keyNames @[@(XCUIElementTypeKey), @(XCUIElementTypeButton)]]; NSArray *matchedKeys = findMatchingKeys(searchPredicate); if (matchedKeys.count > 0) { - [matchedKeys[matchedKeys.count - 1] fb_tapWithError:nil]; + [matchedKeys[matchedKeys.count - 1] tap]; } } #endif diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBForceTouch.m b/WebDriverAgentLib/Categories/XCUIElement+FBForceTouch.m index e7629c6bc..1c7a9ce0e 100644 --- a/WebDriverAgentLib/Categories/XCUIElement+FBForceTouch.m +++ b/WebDriverAgentLib/Categories/XCUIElement+FBForceTouch.m @@ -35,10 +35,10 @@ - (BOOL)fb_forceTouchCoordinate:(NSValue *)relativeCoordinate [self pressWithPressure:[pressure doubleValue] duration:[duration doubleValue]]; } } else { - CGSize size = self.frame.size; - CGVector offset = CGVectorMake(size.width > 0 ? relativeCoordinate.CGPointValue.x / size.width : 0, - size.height > 0 ? relativeCoordinate.CGPointValue.y / size.height : 0); - XCUICoordinate *hitPoint = [self coordinateWithNormalizedOffset:offset]; + CGVector offset = CGVectorMake(relativeCoordinate.CGPointValue.x, + relativeCoordinate.CGPointValue.y); + XCUICoordinate *hitPoint = [[self coordinateWithNormalizedOffset:CGVectorMake(0, 0)] + coordinateWithOffset:offset]; if (nil == pressure || nil == duration) { [hitPoint forcePress]; } else { diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBTap.h b/WebDriverAgentLib/Categories/XCUIElement+FBTap.h deleted file mode 100644 index ed92bb6d7..000000000 --- a/WebDriverAgentLib/Categories/XCUIElement+FBTap.h +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface XCUIElement (FBTap) - -/** - Waits for element to become stable (not move) and performs sync tap on element - - @param error If there is an error, upon return contains an NSError object that describes the problem. - @return YES if the operation succeeds, otherwise NO. -*/ -- (BOOL)fb_tapWithError:(NSError **)error; - -/** - Waits for element to become stable (not move) and performs sync tap on element - - @param relativeCoordinate hit point coordinate relative to the current element position - @param error If there is an error, upon return contains an NSError object that describes the problem. - @return YES if the operation succeeds, otherwise NO. - */ -- (BOOL)fb_tapCoordinate:(CGPoint)relativeCoordinate error:(NSError **)error; - -@end - -NS_ASSUME_NONNULL_END diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBTap.m b/WebDriverAgentLib/Categories/XCUIElement+FBTap.m deleted file mode 100644 index c3c4346ae..000000000 --- a/WebDriverAgentLib/Categories/XCUIElement+FBTap.m +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import "XCUIElement+FBTap.h" - - -#if !TARGET_OS_TV -@implementation XCUIElement (FBTap) - -- (BOOL)fb_tapWithError:(NSError **)error -{ - [self tap]; - return YES; -} - -- (BOOL)fb_tapCoordinate:(CGPoint)relativeCoordinate error:(NSError **)error -{ - XCUICoordinate *startCoordinate = [self coordinateWithNormalizedOffset:CGVectorMake(0, 0)]; - CGVector offset = CGVectorMake(relativeCoordinate.x, relativeCoordinate.y); - XCUICoordinate *dstCoordinate = [startCoordinate coordinateWithOffset:offset]; - [dstCoordinate tap]; - return YES; -} - -@end -#endif diff --git a/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m b/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m index aabc6e8bf..a538be380 100644 --- a/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m +++ b/WebDriverAgentLib/Categories/XCUIElement+FBTyping.m @@ -16,7 +16,6 @@ #import "FBXCElementSnapshotWrapper.h" #import "FBXCElementSnapshotWrapper+Helpers.h" #import "XCUIElement+FBCaching.h" -#import "XCUIElement+FBTap.h" #import "XCUIElement+FBUtilities.h" #import "FBXCodeCompatibility.h" @@ -72,7 +71,7 @@ - (void)fb_prepareForTextInputWithSnapshot:(FBXCElementSnapshotWrapper *)snapsho // There is no possibility to open the keyboard by tapping a field in TvOS #if !TARGET_OS_TV [FBLogger logFmt:@"Trying to tap the \"%@\" element to have it focused", snapshot.fb_description]; - [self fb_tapWithError:nil]; + [self tap]; // It might take some time to update the UI [self fb_takeSnapshot]; #endif diff --git a/WebDriverAgentLib/Commands/FBElementCommands.m b/WebDriverAgentLib/Commands/FBElementCommands.m index 49c3a0231..adb5f6092 100644 --- a/WebDriverAgentLib/Commands/FBElementCommands.m +++ b/WebDriverAgentLib/Commands/FBElementCommands.m @@ -30,7 +30,6 @@ #import "XCUIElement+FBIsVisible.h" #import "XCUIElement+FBPickerWheel.h" #import "XCUIElement+FBScrolling.h" -#import "XCUIElement+FBTap.h" #import "XCUIElement+FBForceTouch.h" #import "XCUIElement+FBSwiping.h" #import "XCUIElement+FBTyping.h" @@ -233,14 +232,14 @@ + (NSArray *)routes { FBElementCache *elementCache = request.session.elementCache; XCUIElement *element = [elementCache elementForUUID:(NSString *)request.parameters[@"uuid"]]; - NSError *error = nil; #if TARGET_OS_IOS - if (![element fb_tapWithError:&error]) { + [element tap]; #elif TARGET_OS_TV + NSError *error = nil; if (![element fb_selectWithError:&error]) { -#endif return FBResponseWithStatus([FBCommandStatus invalidElementStateErrorWithMessage:error.description traceback:nil]); } +#endif return FBResponseWithOK(); } @@ -296,9 +295,10 @@ + (NSArray *)routes + (id)handleDoubleTapCoordinate:(FBRouteRequest *)request { - CGPoint doubleTapPoint = CGPointMake((CGFloat)[request.arguments[@"x"] doubleValue], (CGFloat)[request.arguments[@"y"] doubleValue]); - XCUICoordinate *doubleTapCoordinate = [self.class gestureCoordinateWithCoordinate:doubleTapPoint - application:request.session.activeApplication]; + CGVector offset = CGVectorMake([request.arguments[@"x"] doubleValue], + [request.arguments[@"y"] doubleValue]); + XCUICoordinate *doubleTapCoordinate = [self.class gestureCoordinateWithOffset:offset + element:request.session.activeApplication]; [doubleTapCoordinate doubleTap]; return FBResponseWithOK(); } @@ -334,9 +334,10 @@ + (NSArray *)routes + (id)handleTouchAndHoldCoordinate:(FBRouteRequest *)request { - CGPoint touchPoint = CGPointMake((CGFloat)[request.arguments[@"x"] doubleValue], (CGFloat)[request.arguments[@"y"] doubleValue]); - XCUICoordinate *pressCoordinate = [self.class gestureCoordinateWithCoordinate:touchPoint - application:request.session.activeApplication]; + CGVector offset = CGVectorMake([request.arguments[@"x"] doubleValue], + [request.arguments[@"y"] doubleValue]); + XCUICoordinate *pressCoordinate = [self.class gestureCoordinateWithOffset:offset + element:request.session.activeApplication]; [pressCoordinate pressForDuration:[request.arguments[@"duration"] doubleValue]]; return FBResponseWithOK(); } @@ -359,18 +360,18 @@ + (NSArray *)routes + (id)handlePressAndDragCoordinateWithVelocity:(FBRouteRequest *)request { 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]); - XCUICoordinate *endCoordinate = [self.class gestureCoordinateWithCoordinate:endPoint - application:session.activeApplication]; - XCUICoordinate *startCoordinate = [self.class gestureCoordinateWithCoordinate:startPoint - application:session.activeApplication]; + CGVector startOffset = CGVectorMake((CGFloat)[request.arguments[@"fromX"] doubleValue], + (CGFloat)[request.arguments[@"fromY"] doubleValue]); + XCUICoordinate *startCoordinate = [self.class gestureCoordinateWithOffset:startOffset + element:session.activeApplication]; if (![startCoordinate respondsToSelector:@selector(pressForDuration:thenDragToCoordinate:withVelocity:thenHoldForDuration:)]) { return FBResponseWithStatus([FBCommandStatus unsupportedOperationErrorWithMessage:@"This method is only supported in Xcode 12 and above" traceback:nil]); } + CGVector endOffset = CGVectorMake((CGFloat)[request.arguments[@"toX"] doubleValue], + (CGFloat)[request.arguments[@"toY"] doubleValue]); + XCUICoordinate *endCoordinate = [self.class gestureCoordinateWithOffset:endOffset + element:session.activeApplication]; [startCoordinate pressForDuration:[request.arguments[@"pressDuration"] doubleValue] thenDragToCoordinate:endCoordinate withVelocity:[request.arguments[@"velocity"] doubleValue] @@ -444,13 +445,15 @@ + (NSArray *)routes + (id)handleDragCoordinate:(FBRouteRequest *)request { 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]); + CGVector startOffset = CGVectorMake([request.arguments[@"fromX"] doubleValue], + [request.arguments[@"fromY"] doubleValue]); + XCUICoordinate *startCoordinate = [self.class gestureCoordinateWithOffset:startOffset + element:session.activeApplication]; + CGVector endOffset = CGVectorMake([request.arguments[@"toX"] doubleValue], + [request.arguments[@"toY"] doubleValue]); + XCUICoordinate *endCoordinate = [self.class gestureCoordinateWithOffset:endOffset + element:session.activeApplication]; NSTimeInterval duration = [request.arguments[@"duration"] doubleValue]; - XCUICoordinate *endCoordinate = [self.class gestureCoordinateWithCoordinate:endPoint - application:session.activeApplication]; - XCUICoordinate *startCoordinate = [self.class gestureCoordinateWithCoordinate:startPoint - application:session.activeApplication]; [startCoordinate pressForDuration:duration thenDragToCoordinate:endCoordinate]; return FBResponseWithOK(); } @@ -460,14 +463,13 @@ + (NSArray *)routes FBSession *session = request.session; FBElementCache *elementCache = session.elementCache; XCUIElement *element = [elementCache elementForUUID:(NSString *)request.parameters[@"uuid"]]; - CGRect frame = [(id)element.lastSnapshot frame]; - CGPoint startPoint = CGPointMake((CGFloat)(frame.origin.x + [request.arguments[@"fromX"] doubleValue]), (CGFloat)(frame.origin.y + [request.arguments[@"fromY"] doubleValue])); - CGPoint endPoint = CGPointMake((CGFloat)(frame.origin.x + [request.arguments[@"toX"] doubleValue]), (CGFloat)(frame.origin.y + [request.arguments[@"toY"] doubleValue])); + CGVector startOffset = CGVectorMake([request.arguments[@"fromX"] doubleValue], + [request.arguments[@"fromY"] doubleValue]); + XCUICoordinate *startCoordinate = [self.class gestureCoordinateWithOffset:startOffset element:element]; + CGVector endOffset = CGVectorMake([request.arguments[@"toX"] doubleValue], + [request.arguments[@"toY"] doubleValue]); + XCUICoordinate *endCoordinate = [self.class gestureCoordinateWithOffset:endOffset element:element]; NSTimeInterval duration = [request.arguments[@"duration"] doubleValue]; - XCUICoordinate *endCoordinate = [self.class gestureCoordinateWithCoordinate:endPoint - application:session.activeApplication]; - XCUICoordinate *startCoordinate = [self.class gestureCoordinateWithCoordinate:startPoint - application:session.activeApplication]; [startCoordinate pressForDuration:duration thenDragToCoordinate:endCoordinate]; return FBResponseWithOK(); } @@ -493,19 +495,13 @@ + (NSArray *)routes + (id)handleTap:(FBRouteRequest *)request { FBElementCache *elementCache = request.session.elementCache; - CGPoint tapPoint = CGPointMake((CGFloat)[request.arguments[@"x"] doubleValue], (CGFloat)[request.arguments[@"y"] doubleValue]); - if ([elementCache hasElementWithUUID:request.parameters[@"uuid"]]) { - XCUIElement *element = [elementCache elementForUUID:(NSString *)request.parameters[@"uuid"]]; - NSError *error; - if (![element fb_tapCoordinate:tapPoint error:&error]) { - return FBResponseWithStatus([FBCommandStatus invalidElementStateErrorWithMessage:error.description - traceback:nil]); - } - } else { - XCUICoordinate *tapCoordinate = [self.class gestureCoordinateWithCoordinate:tapPoint - application:request.session.activeApplication]; - [tapCoordinate tap]; - } + CGVector offset = CGVectorMake([request.arguments[@"x"] doubleValue], + [request.arguments[@"y"] doubleValue]); + XCUIElement *element = [elementCache hasElementWithUUID:request.parameters[@"uuid"]] + ? [elementCache elementForUUID:(NSString *)request.parameters[@"uuid"]] + : request.session.activeApplication; + XCUICoordinate *tapCoordinate = [self.class gestureCoordinateWithOffset:offset element:element]; + [tapCoordinate tap]; return FBResponseWithOK(); } @@ -672,55 +668,18 @@ + (NSArray *)routes } /** - Returns gesture coordinate for the application based on absolute coordinate + Returns gesture coordinate for the element based on absolute coordinate - @param coordinate absolute screen coordinates - @param application the instance of current application under test + @param offset absolute screen offset for the given application + @param element the element instance to perform the gesture on @return translated gesture coordinates ready to be passed to XCUICoordinate methods */ -+ (XCUICoordinate *)gestureCoordinateWithCoordinate:(CGPoint)coordinate - application:(XCUIApplication *)application -{ - CGPoint point = coordinate; - /** - If SDK >= 11, the tap coordinate based on application is not correct when - the application orientation is landscape and - tapX > application portrait width or tapY > application portrait height. - Pass the window element to the method [FBElementCommands gestureCoordinateWithCoordinate:element:] - will resolve the problem. - More details about the bug, please see the following issues: - #705: https://github.com/facebook/WebDriverAgent/issues/705 - #798: https://github.com/facebook/WebDriverAgent/issues/798 - #856: https://github.com/facebook/WebDriverAgent/issues/856 - Notice: On iOS 10, if the application is not launched by wda, no elements will be found. - See issue #732: https://github.com/facebook/WebDriverAgent/issues/732 - */ - XCUIElement *element = application; - XCUIElement *window = application.windows.allElementsBoundByIndex.firstObject; - if (window) { - element = window; - id snapshot = element.fb_cachedSnapshot ?: element.fb_takeSnapshot; - point.x -= snapshot.frame.origin.x; - point.y -= snapshot.frame.origin.y; - } - return [self gestureCoordinateWithCoordinate:point element:element]; -} - -/** - Returns gesture coordinate based on the specified element. - - @param coordinate absolute coordinates based on the element - @param element the element in the current application under test - @return translated gesture coordinates ready to be passed to XCUICoordinate methods - */ -+ (XCUICoordinate *)gestureCoordinateWithCoordinate:(CGPoint)coordinate - element:(XCUIElement *)element ++ (XCUICoordinate *)gestureCoordinateWithOffset:(CGVector)offset + element:(XCUIElement *)element { - XCUICoordinate *appCoordinate = [[XCUICoordinate alloc] initWithElement:element - normalizedOffset:CGVectorMake(0, 0)]; - return [[XCUICoordinate alloc] initWithCoordinate:appCoordinate - pointsOffset:CGVectorMake(coordinate.x, coordinate.y)]; + return [[element coordinateWithNormalizedOffset:CGVectorMake(0, 0)] coordinateWithOffset:offset]; } + #endif @end diff --git a/WebDriverAgentLib/FBAlert.m b/WebDriverAgentLib/FBAlert.m index 705ab3ccc..d692b04b2 100644 --- a/WebDriverAgentLib/FBAlert.m +++ b/WebDriverAgentLib/FBAlert.m @@ -17,7 +17,6 @@ #import "FBXCodeCompatibility.h" #import "XCUIApplication+FBAlert.h" #import "XCUIElement+FBClassChain.h" -#import "XCUIElement+FBTap.h" #import "XCUIElement+FBTyping.h" #import "XCUIElement+FBUtilities.h" #import "XCUIElement+FBWebDriverAttributes.h" @@ -190,11 +189,13 @@ - (BOOL)acceptWithError:(NSError **)error ? buttons.lastObject : buttons.firstObject; } - return nil == acceptButton - ? [[[FBErrorBuilder builder] + if (nil == acceptButton) { + return [[[FBErrorBuilder builder] withDescriptionFormat:@"Failed to find accept button for alert: %@", self.alertElement] - buildError:error] - : [acceptButton fb_tapWithError:error]; + buildError:error]; + } + [acceptButton tap]; + return YES; } - (BOOL)dismissWithError:(NSError **)error @@ -230,11 +231,13 @@ - (BOOL)dismissWithError:(NSError **)error : buttons.lastObject; } - return nil == dismissButton - ? [[[FBErrorBuilder builder] + if (nil == dismissButton) { + return [[[FBErrorBuilder builder] withDescriptionFormat:@"Failed to find dismiss button for alert: %@", self.alertElement] - buildError:error] - : [dismissButton fb_tapWithError:error]; + buildError:error]; + } + [dismissButton tap]; + return YES; } - (BOOL)clickAlertButton:(NSString *)label error:(NSError **)error @@ -251,7 +254,8 @@ - (BOOL)clickAlertButton:(NSString *)label error:(NSError **)error withDescriptionFormat:@"Failed to find button with label '%@' for alert: %@", label, self.alertElement] buildError:error]; } - return [requestedButton fb_tapWithError:error]; + [requestedButton tap]; + return YES; } - (XCUIElement *)alertElement diff --git a/WebDriverAgentLib/WebDriverAgentLib.h b/WebDriverAgentLib/WebDriverAgentLib.h index b8f85e98f..6d9daa1f6 100644 --- a/WebDriverAgentLib/WebDriverAgentLib.h +++ b/WebDriverAgentLib/WebDriverAgentLib.h @@ -46,7 +46,6 @@ FOUNDATION_EXPORT const unsigned char WebDriverAgentLib_VersionString[]; #import #import #import -#import #import #import #import diff --git a/WebDriverAgentTests/IntegrationTests/FBAlertTests.m b/WebDriverAgentTests/IntegrationTests/FBAlertTests.m index e94c4109e..57c48e492 100644 --- a/WebDriverAgentTests/IntegrationTests/FBAlertTests.m +++ b/WebDriverAgentTests/IntegrationTests/FBAlertTests.m @@ -15,7 +15,6 @@ #import "FBIntegrationTestCase.h" #import "FBTestMacros.h" #import "FBMacros.h" -#import "XCUIElement+FBTap.h" @interface FBAlertTests : FBIntegrationTestCase @end @@ -42,13 +41,13 @@ - (void)tearDown - (void)showApplicationAlert { - [self.testedApplication.buttons[FBShowAlertButtonName] fb_tapWithError:nil]; + [self.testedApplication.buttons[FBShowAlertButtonName] tap]; FBAssertWaitTillBecomesTrue(self.testedApplication.alerts.count != 0); } - (void)showApplicationSheet { - [self.testedApplication.buttons[FBShowSheetAlertButtonName] fb_tapWithError:nil]; + [self.testedApplication.buttons[FBShowSheetAlertButtonName] tap]; FBAssertWaitTillBecomesTrue(self.testedApplication.sheets.count != 0); } diff --git a/WebDriverAgentTests/IntegrationTests/FBAutoAlertsHandlerTests.m b/WebDriverAgentTests/IntegrationTests/FBAutoAlertsHandlerTests.m index 5294fb50c..25dc39d21 100644 --- a/WebDriverAgentTests/IntegrationTests/FBAutoAlertsHandlerTests.m +++ b/WebDriverAgentTests/IntegrationTests/FBAutoAlertsHandlerTests.m @@ -53,7 +53,7 @@ - (void)disabled_testAutoAcceptingOfAlerts initWithApplication:FBApplication.fb_activeApplication defaultAlertAction:@"accept"]; for (int i = 0; i < 2; i++) { - [self.testedApplication.buttons[FBShowAlertButtonName] fb_tapWithError:nil]; + [self.testedApplication.buttons[FBShowAlertButtonName] tap]; [self.testedApplication fb_waitUntilStable]; FBAssertWaitTillBecomesTrue(self.testedApplication.alerts.count == 0); } @@ -66,7 +66,7 @@ - (void)disabled_testAutoDismissingOfAlerts initWithApplication:FBApplication.fb_activeApplication defaultAlertAction:@"dismiss"]; for (int i = 0; i < 2; i++) { - [self.testedApplication.buttons[FBShowAlertButtonName] fb_tapWithError:nil]; + [self.testedApplication.buttons[FBShowAlertButtonName] tap]; [self.testedApplication fb_waitUntilStable]; FBAssertWaitTillBecomesTrue(self.testedApplication.alerts.count == 0); } diff --git a/WebDriverAgentTests/IntegrationTests/FBElementAttributeTests.m b/WebDriverAgentTests/IntegrationTests/FBElementAttributeTests.m index bc0966f91..c7cc3505e 100644 --- a/WebDriverAgentTests/IntegrationTests/FBElementAttributeTests.m +++ b/WebDriverAgentTests/IntegrationTests/FBElementAttributeTests.m @@ -160,7 +160,7 @@ - (void)testSwitchAttributes XCTAssertNil(element.wdLabel); XCTAssertEqualObjects(element.wdValue, @"1"); XCTAssertFalse(element.wdSelected); - XCTAssertTrue([element fb_tapWithError:nil]); + [element tap]; XCTAssertEqualObjects(element.wdValue, @"0"); XCTAssertFalse(element.wdSelected); } diff --git a/WebDriverAgentTests/IntegrationTests/FBTapTest.m b/WebDriverAgentTests/IntegrationTests/FBTapTest.m index 30b5f0f9e..9dce4084c 100644 --- a/WebDriverAgentTests/IntegrationTests/FBTapTest.m +++ b/WebDriverAgentTests/IntegrationTests/FBTapTest.m @@ -15,7 +15,6 @@ #import "FBElementCache.h" #import "FBTestMacros.h" #import "XCUIDevice+FBRotation.h" -#import "XCUIElement+FBTap.h" #import "XCUIElement+FBIsVisible.h" @interface FBTapTest : FBIntegrationTestCase @@ -28,8 +27,7 @@ @implementation FBTapTest - (void)verifyTapWithOrientation:(UIDeviceOrientation)orientation { [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:orientation]; - NSError *error; - [self.testedApplication.buttons[FBShowAlertButtonName] fb_tapWithError:&error]; + [self.testedApplication.buttons[FBShowAlertButtonName] tap]; FBAssertWaitTillBecomesTrue(self.testedApplication.alerts.count > 0); } @@ -66,10 +64,7 @@ - (void)testTapInLandscapeRight [self verifyTapWithOrientation:UIDeviceOrientationLandscapeRight]; } -// Visibility detection for upside-down orientation is broken -// and cannot be workarounded properly, but this is not very important for Appium, since -// We don't support such orientation anyway -- (void)disabled_testTapInPortraitUpsideDown +- (void)testTapInPortraitUpsideDown { [self verifyTapWithOrientation:UIDeviceOrientationPortraitUpsideDown]; } @@ -77,9 +72,8 @@ - (void)disabled_testTapInPortraitUpsideDown - (void)verifyTapByCoordinatesWithOrientation:(UIDeviceOrientation)orientation { [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:orientation]; - NSError *error; XCUIElement *dstButton = self.testedApplication.buttons[FBShowAlertButtonName]; - [dstButton fb_tapCoordinate:CGPointMake(dstButton.frame.size.width / 2, dstButton.frame.size.height / 2) error:&error]; + [[dstButton coordinateWithNormalizedOffset:CGVectorMake(0.5, 0.5)] tap]; FBAssertWaitTillBecomesTrue(self.testedApplication.alerts.count > 0); } @@ -98,10 +92,7 @@ - (void)testTapCoordinatesInLandscapeRight [self verifyTapByCoordinatesWithOrientation:UIDeviceOrientationLandscapeRight]; } -// Visibility detection for upside-down orientation is broken -// and cannot be workarounded properly, but this is not very important for Appium, since -// We don't support such orientation anyway -- (void)disabled_testTapCoordinatesInPortraitUpsideDown +- (void)testTapCoordinatesInPortraitUpsideDown { [self verifyTapByCoordinatesWithOrientation:UIDeviceOrientationPortraitUpsideDown]; }