Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add velocity argument to swipes #392

Merged
merged 3 commits into from
Oct 8, 2020
Merged
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
6 changes: 6 additions & 0 deletions PrivateHeaders/XCTest/XCUIElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,10 @@
// Available since Xcode 10.0
- (id)screenshot;

// Since Xcode 11.4
- (void)swipeRightWithVelocity:(double)arg1;
- (void)swipeLeftWithVelocity:(double)arg1;
- (void)swipeDownWithVelocity:(double)arg1;
- (void)swipeUpWithVelocity:(double)arg1;

@end
17 changes: 16 additions & 1 deletion WebDriverAgent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
315A15012518CB8700A3A064 /* TouchableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 315A15002518CB8700A3A064 /* TouchableView.m */; };
315A15072518CC2800A3A064 /* TouchSpotView.m in Sources */ = {isa = PBXBuildFile; fileRef = 315A15062518CC2800A3A064 /* TouchSpotView.m */; };
315A150A2518D6F400A3A064 /* TouchViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 315A15092518D6F400A3A064 /* TouchViewController.m */; };
315B7EE52519F90100E28DA3 /* WebDriverAgentLib.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = EE158A991CBD452B00A3E3F0 /* WebDriverAgentLib.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
31EC77FC224F7D0600380FCD /* XCUIApplicationProcessQuiescence.h in Headers */ = {isa = PBXBuildFile; fileRef = 31EC77FA224F7D0600380FCD /* XCUIApplicationProcessQuiescence.h */; };
31EC77FD224F7D0600380FCD /* XCUIApplicationProcessQuiescence.h in Headers */ = {isa = PBXBuildFile; fileRef = 31EC77FA224F7D0600380FCD /* XCUIApplicationProcessQuiescence.h */; };
31EC77FE224F7D0600380FCD /* XCUIApplicationProcessQuiescence.m in Sources */ = {isa = PBXBuildFile; fileRef = 31EC77FB224F7D0600380FCD /* XCUIApplicationProcessQuiescence.m */; };
Expand Down Expand Up @@ -429,6 +428,11 @@
71BD20731F86116100B36EC2 /* XCUIApplication+FBTouchAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 71BD20711F86116100B36EC2 /* XCUIApplication+FBTouchAction.h */; };
71BD20741F86116100B36EC2 /* XCUIApplication+FBTouchAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 71BD20721F86116100B36EC2 /* XCUIApplication+FBTouchAction.m */; };
71BD20781F869E0F00B36EC2 /* FBAppiumTouchActionsIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 71BD20771F869E0F00B36EC2 /* FBAppiumTouchActionsIntegrationTests.m */; };
71F5BE23252E576C00EE9EBA /* XCUIElement+FBSwiping.h in Headers */ = {isa = PBXBuildFile; fileRef = 71F5BE21252E576C00EE9EBA /* XCUIElement+FBSwiping.h */; };
71F5BE24252E576C00EE9EBA /* XCUIElement+FBSwiping.h in Headers */ = {isa = PBXBuildFile; fileRef = 71F5BE21252E576C00EE9EBA /* XCUIElement+FBSwiping.h */; };
71F5BE25252E576C00EE9EBA /* XCUIElement+FBSwiping.m in Sources */ = {isa = PBXBuildFile; fileRef = 71F5BE22252E576C00EE9EBA /* XCUIElement+FBSwiping.m */; };
71F5BE26252E576C00EE9EBA /* XCUIElement+FBSwiping.m in Sources */ = {isa = PBXBuildFile; fileRef = 71F5BE22252E576C00EE9EBA /* XCUIElement+FBSwiping.m */; };
71F5BE34252E5B2200EE9EBA /* FBElementSwipingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 71F5BE33252E5B2200EE9EBA /* FBElementSwipingTests.m */; };
7255FBD0249F2EC10079B1E4 /* CocoaAsyncSocket.framework in Copy frameworks */ = {isa = PBXBuildFile; fileRef = E4C91FD92493A41000C9FC04 /* CocoaAsyncSocket.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
7255FBD1249F2ED80079B1E4 /* CocoaAsyncSocket.framework in Copy frameworks */ = {isa = PBXBuildFile; fileRef = E4C91FDC2493A41A00C9FC04 /* CocoaAsyncSocket.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
AD35D06C1CF1C35500870A75 /* WebDriverAgentLib.framework in Copy frameworks */ = {isa = PBXBuildFile; fileRef = EE158A991CBD452B00A3E3F0 /* WebDriverAgentLib.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -1001,6 +1005,9 @@
71BD20721F86116100B36EC2 /* XCUIApplication+FBTouchAction.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "XCUIApplication+FBTouchAction.m"; sourceTree = "<group>"; };
71BD20771F869E0F00B36EC2 /* FBAppiumTouchActionsIntegrationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBAppiumTouchActionsIntegrationTests.m; sourceTree = "<group>"; };
71E504941DF59BAD0020C32A /* XCUIElementAttributesTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XCUIElementAttributesTests.m; sourceTree = "<group>"; };
71F5BE21252E576C00EE9EBA /* XCUIElement+FBSwiping.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XCUIElement+FBSwiping.h"; sourceTree = "<group>"; };
71F5BE22252E576C00EE9EBA /* XCUIElement+FBSwiping.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "XCUIElement+FBSwiping.m"; sourceTree = "<group>"; };
71F5BE33252E5B2200EE9EBA /* FBElementSwipingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBElementSwipingTests.m; sourceTree = "<group>"; };
AD42DD2A1CF121E600806E5D /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; };
AD42DD2B1CF1238500806E5D /* RoutingHTTPServer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RoutingHTTPServer.framework; path = Carthage/Build/iOS/RoutingHTTPServer.framework; sourceTree = "<group>"; };
AD6C26921CF2379700F8B5FF /* FBAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FBAlert.h; path = WebDriverAgentLib/FBAlert.h; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -1692,6 +1699,8 @@
7136A4781E8918E60024FC3D /* XCUIElement+FBPickerWheel.m */,
EE9AB7491CAEDF0C008C271F /* XCUIElement+FBScrolling.h */,
EE9AB74A1CAEDF0C008C271F /* XCUIElement+FBScrolling.m */,
71F5BE21252E576C00EE9EBA /* XCUIElement+FBSwiping.h */,
71F5BE22252E576C00EE9EBA /* XCUIElement+FBSwiping.m */,
EE9AB74B1CAEDF0C008C271F /* XCUIElement+FBTap.h */,
EE9AB74C1CAEDF0C008C271F /* XCUIElement+FBTap.m */,
AD76723B1D6B7CC000610457 /* XCUIElement+FBTyping.h */,
Expand Down Expand Up @@ -1889,6 +1898,7 @@
719CD8FE2126C90200C7D0C2 /* FBAutoAlertsHandlerTests.m */,
EE26409C1D0EBA25009BE6B0 /* FBElementAttributeTests.m */,
71AB82B11FDAE8C000D1D7C3 /* FBElementScreenshotTests.m */,
71F5BE33252E5B2200EE9EBA /* FBElementSwipingTests.m */,
EE006EAC1EB99B15006900A4 /* FBElementVisibilityTests.m */,
EE6A89361D0B35920083E92B /* FBFailureProofTestCaseTests.m */,
EE8DDD7A20C57320004D4925 /* FBForceTouchTests.m */,
Expand Down Expand Up @@ -2303,6 +2313,7 @@
641EE6B42240C5CA00173FCB /* XCTWaiterManager.h in Headers */,
641EE6B52240C5CA00173FCB /* XCTestDriverInterface-Protocol.h in Headers */,
648C10B022AAAE4000B81B9A /* TIPreferencesController.h in Headers */,
71F5BE24252E576C00EE9EBA /* XCUIElement+FBSwiping.h in Headers */,
641EE6B62240C5CA00173FCB /* _XCTestSuiteImplementation.h in Headers */,
641EE6B72240C5CA00173FCB /* FBBaseActionsSynthesizer.h in Headers */,
641EE6B82240C5CA00173FCB /* FBAlert.h in Headers */,
Expand Down Expand Up @@ -2575,6 +2586,7 @@
EE35AD151E3B77D600A02D78 /* CDStructures.h in Headers */,
EE35AD311E3B77D600A02D78 /* XCKeyboardLayout.h in Headers */,
E444DCB624913C220060D7EB /* RouteRequest.h in Headers */,
71F5BE23252E576C00EE9EBA /* XCUIElement+FBSwiping.h in Headers */,
EE35AD3B1E3B77D600A02D78 /* XCTAsyncActivity-Protocol.h in Headers */,
EE35AD251E3B77D600A02D78 /* XCActivityRecord.h in Headers */,
EEBBD48B1D47746D00656A81 /* XCUIElement+FBFind.h in Headers */,
Expand Down Expand Up @@ -3027,6 +3039,7 @@
641EE6182240C5CA00173FCB /* XCElementSnapshot+FBHitPoint.m in Sources */,
641EE6192240C5CA00173FCB /* FBConfiguration.m in Sources */,
641EE61A2240C5CA00173FCB /* FBElementCache.m in Sources */,
71F5BE26252E576C00EE9EBA /* XCUIElement+FBSwiping.m in Sources */,
641EE61B2240C5CA00173FCB /* FBPasteboard.m in Sources */,
641EE61C2240C5CA00173FCB /* FBAlert.m in Sources */,
718F49CB23087B040045FE8B /* FBCommandStatus.m in Sources */,
Expand Down Expand Up @@ -3129,6 +3142,7 @@
7150348821A6DAD600A0F4BA /* FBImageUtils.m in Sources */,
E444DCAB24913C220060D7EB /* HTTPResponseProxy.m in Sources */,
E444DC6D249131890060D7EB /* HTTPErrorResponse.m in Sources */,
71F5BE25252E576C00EE9EBA /* XCUIElement+FBSwiping.m in Sources */,
EE158AE51CBD456F00A3E3F0 /* FBSession.m in Sources */,
E444DCB224913C220060D7EB /* RoutingConnection.m in Sources */,
EE158AC11CBD456F00A3E3F0 /* FBFindElementCommands.m in Sources */,
Expand Down Expand Up @@ -3261,6 +3275,7 @@
EE55B3271D1D54CF003AAAEC /* FBScrollingTests.m in Sources */,
EE6A89371D0B35920083E92B /* FBFailureProofTestCaseTests.m in Sources */,
EE006EAD1EB99B15006900A4 /* FBElementVisibilityTests.m in Sources */,
71F5BE34252E5B2200EE9EBA /* FBElementSwipingTests.m in Sources */,
7152EB301F41F9960047EEFF /* FBSessionIntegrationTests.m in Sources */,
EE9B769A1CF799F400275851 /* FBAlertTests.m in Sources */,
);
Expand Down
26 changes: 26 additions & 0 deletions WebDriverAgentLib/Categories/XCUIElement+FBSwiping.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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 <XCTest/XCTest.h>

NS_ASSUME_NONNULL_BEGIN

@interface XCUIElement (FBSwiping)

/**
* Performs swipe gesture on the element
*
* @param direction Swipe direction. The following values are supported: up, down, left and right
* @param velocity Swipe speed in pixels per second. This parameter is only supported since Xcode 11.4
* nil value means that the default velocity is going to be used.
*/
- (void)fb_swipeWithDirection:(NSString *)direction velocity:(nullable NSNumber*)velocity;

@end

NS_ASSUME_NONNULL_END
40 changes: 40 additions & 0 deletions WebDriverAgentLib/Categories/XCUIElement+FBSwiping.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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+FBSwiping.h"

#import "FBLogger.h"
#import "XCUIElement.h"

@implementation XCUIElement (FBSwiping)

- (void)fb_swipeWithDirection:(NSString *)direction velocity:(nullable NSNumber*)velocity
{
double velocityValue = .0;
if (nil != velocity) {
if ([self respondsToSelector:@selector(swipeUpWithVelocity:)]) {
velocityValue = [velocity doubleValue];
} else {
[FBLogger log:@"Custom velocity values are only supported since Xcode SDK 11.4. The default velocity will be used instead"];
}
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (velocityValue > 0) {
SEL selector = NSSelectorFromString([NSString stringWithFormat:@"swipe%@WithVelocity:", direction.lowercaseString.capitalizedString]);
[self performSelector:selector withObject:@(velocityValue)];
} else {
SEL selector = NSSelectorFromString([NSString stringWithFormat:@"swipe%@", direction.lowercaseString.capitalizedString]);
[self performSelector:selector];
}
#pragma clang diagnostic pop
}

@end
19 changes: 8 additions & 11 deletions WebDriverAgentLib/Commands/FBElementCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#import "XCUIElement+FBScrolling.h"
#import "XCUIElement+FBTap.h"
#import "XCUIElement+FBForceTouch.h"
#import "XCUIElement+FBSwiping.h"
#import "XCUIElement+FBTyping.h"
#import "XCUIElement+FBUtilities.h"
#import "XCUIElement+FBWebDriverAttributes.h"
Expand Down Expand Up @@ -471,21 +472,17 @@ + (NSArray *)routes
return FBResponseWithStatus([FBCommandStatus staleElementReferenceErrorWithMessage:nil
traceback:nil]);
}
NSString *const direction = request.arguments[@"direction"];
NSString *direction = request.arguments[@"direction"];
if (!direction) {
return FBResponseWithStatus([FBCommandStatus invalidArgumentErrorWithMessage:@"Missing 'direction' parameter" traceback:nil]);
}
if ([direction isEqualToString:@"up"]) {
[element swipeUp];
} else if ([direction isEqualToString:@"down"]) {
[element swipeDown];
} else if ([direction isEqualToString:@"left"]) {
[element swipeLeft];
} else if ([direction isEqualToString:@"right"]) {
[element swipeRight];
} else {
return FBResponseWithStatus([FBCommandStatus invalidArgumentErrorWithMessage:@"Unsupported swipe type" traceback:nil]);
NSArray<NSString *> *supportedDirections = @[@"up", @"down", @"left", @"right"];
if (![supportedDirections containsObject:direction.lowercaseString]) {
return FBResponseWithStatus([FBCommandStatus
invalidArgumentErrorWithMessage:[NSString stringWithFormat: @"Unsupported swipe direction '%@'. Only the following directions are supported: %@", direction, supportedDirections]
traceback:nil]);
}
[element fb_swipeWithDirection:direction.lowercaseString velocity:request.arguments[@"velocity"]];
return FBResponseWithOK();
}

Expand Down
57 changes: 57 additions & 0 deletions WebDriverAgentTests/IntegrationTests/FBElementSwipingTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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 <XCTest/XCTest.h>

#import "FBIntegrationTestCase.h"
#import "FBTestMacros.h"
#import "XCUIElement+FBWebDriverAttributes.h"
#import "FBXCodeCompatibility.h"
#import "XCUIElement+FBSwiping.h"

@interface FBElementSwipingTests : FBIntegrationTestCase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@property (nonatomic, strong) XCUIElement *scrollView;
@end

@implementation FBElementSwipingTests

- (void)setUp
{
[super setUp];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self launchApplication];
[self goToScrollPageWithCells:YES];
self.scrollView = [[self.testedApplication.query descendantsMatchingType:XCUIElementTypeAny] matchingIdentifier:@"scrollView"].element;
});
}

- (void)testSwipeUp
{
[self.scrollView fb_swipeWithDirection:@"up" velocity:nil];
FBAssertInvisibleCell(@"0");
}

- (void)testSwipeDown
{
[self.scrollView fb_swipeWithDirection:@"up" velocity:nil];
FBAssertInvisibleCell(@"0");
[self.scrollView fb_swipeWithDirection:@"down" velocity:nil];
FBAssertVisibleCell(@"0");
}

- (void)testSwipeDownWithVelocity
{
[self.scrollView fb_swipeWithDirection:@"up" velocity:@2500];
FBAssertInvisibleCell(@"0");
[self.scrollView fb_swipeWithDirection:@"down" velocity:@2500];
FBAssertVisibleCell(@"0");
}

@end
3 changes: 0 additions & 3 deletions WebDriverAgentTests/IntegrationTests/FBScrollingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#import "XCUIElement+FBClassChain.h"
#import "FBXCodeCompatibility.h"

#define FBCellElementWithLabel(label) ([self.testedApplication descendantsMatchingType:XCUIElementTypeAny][label])
#define FBAssertVisibleCell(label) FBAssertWaitTillBecomesTrue(FBCellElementWithLabel(label).fb_isVisible)
#define FBAssertInvisibleCell(label) FBAssertWaitTillBecomesTrue(!FBCellElementWithLabel(label).fb_isVisible)

@interface FBScrollingTests : FBIntegrationTestCase
@property (nonatomic, strong) XCUIElement *scrollView;
Expand Down
4 changes: 4 additions & 0 deletions WebDriverAgentTests/IntegrationTests/FBTestMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@
({ \
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:(timeoutSeconds)]]; \
})

#define FBCellElementWithLabel(label) ([self.testedApplication descendantsMatchingType:XCUIElementTypeAny][label])
#define FBAssertVisibleCell(label) FBAssertWaitTillBecomesTrue(FBCellElementWithLabel(label).fb_isVisible)
#define FBAssertInvisibleCell(label) FBAssertWaitTillBecomesTrue(!FBCellElementWithLabel(label).fb_isVisible)