This repository has been archived by the owner on Dec 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: A couple of commands which make possible to force touch given element or point by coordinates. In fact – copy of the tap extension. Baked with integration tests. Updated with mykola-mokhnach improvements in appium#79 Closes #917 Differential Revision: D8220249 Pulled By: marekcirkos fbshipit-source-id: 2a14ab5759894577a1f5e40f20b4a6d79e519419
- Loading branch information
1 parent
762760d
commit a5b61b4
Showing
10 changed files
with
279 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* 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 <WebDriverAgentLib/XCUIElement.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface XCUIElement (FBForceTouch) | ||
|
||
/** | ||
Waits for element to become stable (not move) and performs sync force touch on element | ||
@param error If there is an error, upon return contains an NSError object that describes the problem. | ||
@param pressure The pressure of the force touch – valid values are [0, touch.maximumPossibleForce] | ||
@param duration The duration of the gesture | ||
@return YES if the operation succeeds, otherwise NO. | ||
*/ | ||
- (BOOL)fb_forceTouchWithPressure:(double)pressure duration:(double)duration error:(NSError **)error; | ||
|
||
/** | ||
Waits for element to become stable (not move) and performs sync force touch on element | ||
@param relativeCoordinate hit point coordinate relative to the current element position | ||
@param pressure The pressure of the force touch – valid values are [0, touch.maximumPossibleForce] | ||
@param duration The duration of the gesture | ||
@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_forceTouchCoordinate:(CGPoint)relativeCoordinate pressure:(double)pressure duration:(double)duration error:(NSError **)error; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* 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+FBForceTouch.h" | ||
|
||
#import "FBRunLoopSpinner.h" | ||
#import "FBLogger.h" | ||
#import "FBMacros.h" | ||
#import "FBMathUtils.h" | ||
#import "XCUIElement+FBUtilities.h" | ||
#import "XCEventGenerator.h" | ||
#import "XCSynthesizedEventRecord.h" | ||
#import "XCElementSnapshot+FBHitPoint.h" | ||
#import "XCPointerEventPath.h" | ||
#import "XCTRunnerDaemonSession.h" | ||
|
||
@implementation XCUIElement (FBForceTouch) | ||
|
||
- (BOOL)fb_forceTouchWithPressure:(double)pressure duration:(double)duration error:(NSError **)error | ||
{ | ||
XCElementSnapshot *snapshot = self.fb_lastSnapshot; | ||
CGPoint hitpoint = snapshot.fb_hitPoint; | ||
if (CGPointEqualToPoint(hitpoint, CGPointMake(-1, -1))) { | ||
hitpoint = [snapshot.suggestedHitpoints.lastObject CGPointValue]; | ||
} | ||
return [self fb_performFourceTouchAtPoint:hitpoint pressure:pressure duration:duration error:error]; | ||
} | ||
|
||
- (BOOL)fb_forceTouchCoordinate:(CGPoint)relativeCoordinate pressure:(double)pressure duration:(double)duration error:(NSError **)error | ||
{ | ||
CGPoint hitPoint = CGPointMake(self.frame.origin.x + relativeCoordinate.x, self.frame.origin.y + relativeCoordinate.y); | ||
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) { | ||
/* | ||
Since iOS 10.0 XCTest has a bug when it always returns portrait coordinates for UI elements | ||
even if the device is not in portait mode. That is why we need to recalculate them manually | ||
based on the current orientation value | ||
*/ | ||
hitPoint = FBInvertPointForApplication(hitPoint, self.application.frame.size, self.application.interfaceOrientation); | ||
} | ||
return [self fb_performFourceTouchAtPoint:hitPoint pressure:pressure duration:duration error:error]; | ||
} | ||
|
||
- (BOOL)fb_performFourceTouchAtPoint:(CGPoint)hitPoint pressure:(double)pressure duration:(double)duration error:(NSError *__autoreleasing*)error | ||
{ | ||
[self fb_waitUntilFrameIsStable]; | ||
__block BOOL didSucceed; | ||
[FBRunLoopSpinner spinUntilCompletion:^(void(^completion)(void)){ | ||
XCEventGeneratorHandler handlerBlock = ^(XCSynthesizedEventRecord *record, NSError *commandError) { | ||
if (commandError) { | ||
[FBLogger logFmt:@"Failed to perform force touch: %@", commandError]; | ||
} | ||
if (error) { | ||
*error = commandError; | ||
} | ||
didSucceed = (commandError == nil); | ||
completion(); | ||
}; | ||
|
||
XCSynthesizedEventRecord *event = [self fb_generateForceTouchEvent:hitPoint pressure:pressure duration:duration orientation:self.interfaceOrientation]; | ||
[[XCTRunnerDaemonSession sharedSession] synthesizeEvent:event completion:^(NSError *invokeError){ | ||
handlerBlock(event, invokeError); | ||
}]; | ||
}]; | ||
return didSucceed; | ||
} | ||
|
||
- (XCSynthesizedEventRecord *)fb_generateForceTouchEvent:(CGPoint)hitPoint pressure:(double)pressure duration:(double)duration orientation:(UIInterfaceOrientation)orientation | ||
{ | ||
XCPointerEventPath *eventPath = [[XCPointerEventPath alloc] initForTouchAtPoint:hitPoint offset:0.0]; | ||
[eventPath pressDownWithPressure:pressure atOffset:0.0]; | ||
if (![XCTRunnerDaemonSession sharedSession].useLegacyEventCoordinateTransformationPath) { | ||
orientation = UIInterfaceOrientationPortrait; | ||
} | ||
[eventPath liftUpAtOffset:duration]; | ||
XCSynthesizedEventRecord *event = | ||
[[XCSynthesizedEventRecord alloc] | ||
initWithName:[NSString stringWithFormat:@"Force touch on %@", NSStringFromCGPoint(hitPoint)] | ||
interfaceOrientation:orientation]; | ||
[event addPointerEventPath:eventPath]; | ||
return event; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.