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

Add a possibility to perform press with pressure #79

Merged
merged 1 commit into from
Apr 27, 2018
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
22 changes: 20 additions & 2 deletions WebDriverAgentLib/Utilities/FBAppiumActionsSynthesizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
static NSString *const FB_OPTION_DURATION = @"duration";
static NSString *const FB_OPTION_COUNT = @"count";
static NSString *const FB_OPTION_MS = @"ms";
static NSString *const FB_OPTION_PRESSURE = @"pressure";

// Some useful constants might be found at
// https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/ViewConfiguration.java
Expand All @@ -50,7 +51,7 @@ @interface FBTapItem : FBAppiumGestureItem
@end

@interface FBPressItem : FBAppiumGestureItem

@property (nonatomic, nullable, readonly) NSNumber *pressure;
@end

@interface FBLongPressItem : FBAppiumGestureItem
Expand Down Expand Up @@ -189,6 +190,19 @@ - (double)durationWithOptions:(nullable NSDictionary<NSString *, id> *)options

@implementation FBPressItem

- (nullable instancetype)initWithActionItem:(NSDictionary<NSString *, id> *)item application:(XCUIApplication *)application atPosition:(nullable NSValue *)atPosition offset:(double)offset error:(NSError **)error
{
self = [super initWithActionItem:item application:application atPosition:atPosition offset:offset error:error];
if (self) {
_pressure = nil;
id options = [item objectForKey:FB_OPTIONS_KEY];
if ([options isKindOfClass:NSDictionary.class]) {
_pressure = [options objectForKey:FB_OPTION_PRESSURE];
}
}
return self;
}

+ (NSString *)actionName
{
return FB_ACTION_PRESS;
Expand All @@ -201,7 +215,11 @@ + (BOOL)hasAbsolutePositioning

- (NSArray<XCPointerEventPath *> *)addToEventPath:(XCPointerEventPath *)eventPath allItems:(NSArray<FBBaseGestureItem *> *)allItems currentItemIndex:(NSUInteger)currentItemIndex error:(NSError **)error
{
return @[[[XCPointerEventPath alloc] initForTouchAtPoint:self.atPosition offset:FBMillisToSeconds(self.offset)]];
XCPointerEventPath *result = [[XCPointerEventPath alloc] initForTouchAtPoint:self.atPosition offset:FBMillisToSeconds(self.offset)];
if (nil != self.pressure) {
[result pressDownWithPressure:self.pressure.doubleValue atOffset:self.offset];
}
return @[result];
}

- (double)durationWithOptions:(nullable NSDictionary<NSString *, id> *)options
Expand Down
18 changes: 16 additions & 2 deletions WebDriverAgentLib/Utilities/FBW3CActionsSynthesizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
static NSString *const FB_ACTION_ITEM_KEY_X = @"x";
static NSString *const FB_ACTION_ITEM_KEY_Y = @"y";
static NSString *const FB_ACTION_ITEM_KEY_BUTTON = @"button";
static NSString *const FB_ACTION_ITEM_KEY_PRESSURE = @"pressure";

static NSString *const FB_KEY_ID = @"id";
static NSString *const FB_KEY_PARAMETERS = @"parameters";
Expand All @@ -62,7 +63,7 @@ @interface FBW3CGestureItem : FBBaseGestureItem
@end

@interface FBPointerDownItem : FBW3CGestureItem

@property (nullable, readonly, nonatomic) NSNumber *pressure;
@end

@interface FBPauseItem : FBW3CGestureItem
Expand Down Expand Up @@ -153,6 +154,15 @@ - (nullable NSValue *)hitpointWithElement:(nullable XCUIElement *)element positi

@implementation FBPointerDownItem

- (nullable instancetype)initWithActionItem:(NSDictionary<NSString *, id> *)actionItem application:(XCUIApplication *)application previousItem:(nullable FBBaseGestureItem *)previousItem offset:(double)offset error:(NSError **)error
{
self = [super initWithActionItem:actionItem application:application previousItem:previousItem offset:offset error:error];
if (self) {
_pressure = [actionItem objectForKey:FB_ACTION_ITEM_KEY_PRESSURE];;
}
return self;
}

+ (NSString *)actionName
{
return FB_ACTION_ITEM_TYPE_POINTER_DOWN;
Expand All @@ -166,7 +176,11 @@ + (NSString *)actionName
return @[eventPath];
}
}
return @[[[XCPointerEventPath alloc] initForTouchAtPoint:self.atPosition offset:FBMillisToSeconds(self.offset)]];
XCPointerEventPath *result = [[XCPointerEventPath alloc] initForTouchAtPoint:self.atPosition offset:FBMillisToSeconds(self.offset)];
if (nil != self.pressure) {
[result pressDownWithPressure:self.pressure.doubleValue atOffset:FBMillisToSeconds(self.offset)];
}
return @[result];
}

@end
Expand Down
28 changes: 22 additions & 6 deletions WebDriverAgentTests/IntegrationApp/Classes/FBAlertViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ @implementation FBAlertViewController

- (IBAction)createAppAlert:(UIButton *)sender
{
UIAlertController *alerController =
[UIAlertController alertControllerWithTitle:@"Magic"
message:@"Should read"
preferredStyle:UIAlertControllerStyleAlert];
[alerController addAction:[UIAlertAction actionWithTitle:@"Will do" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alerController animated:YES completion:nil];
[self presentAlertController];
}

- (IBAction)createAppSheet:(UIButton *)sender
Expand Down Expand Up @@ -57,4 +52,25 @@ - (IBAction)createGPSAccessAlert:(UIButton *)sender
[self.locationManager requestAlwaysAuthorization];
}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
for (UITouch *touch in touches) {
if (fabs(touch.maximumPossibleForce - touch.force) < 0.0001) {
[self presentAlertController];
return;
}
}
}

- (void)presentAlertController
{
UIAlertController *alerController =
[UIAlertController alertControllerWithTitle:@"Magic"
message:@"Should read"
preferredStyle:UIAlertControllerStyleAlert];
[alerController addAction:[UIAlertAction actionWithTitle:@"Will do" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alerController animated:YES completion:nil];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,18 @@
<action selector="createAppSheet:" destination="gK5-IX-eJx" eventType="touchUpInside" id="U6X-fw-xU2"/>
</connections>
</button>
<button opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="D7g-22-s49">
<rect key="frame" x="69" y="360" width="182" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="TzV-CY-64y"/>
</constraints>
<state key="normal" title="Create Alert (Force Touch)"/>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="3Zk-wE-jwj" firstAttribute="centerX" secondItem="JWE-cA-TW0" secondAttribute="centerX" id="83u-1W-xLt"/>
<constraint firstItem="D7g-22-s49" firstAttribute="centerX" secondItem="JWE-cA-TW0" secondAttribute="centerX" id="9nT-k0-9gf"/>
<constraint firstItem="ntr-45-Ycd" firstAttribute="top" secondItem="rG5-3k-LFe" secondAttribute="bottom" constant="8" id="DYt-NB-TSO"/>
<constraint firstItem="3Zk-wE-jwj" firstAttribute="top" secondItem="ntr-45-Ycd" secondAttribute="bottom" constant="8" id="Edq-zL-Soc"/>
<constraint firstItem="y1x-J5-Nkw" firstAttribute="centerX" secondItem="CZ1-7J-OGl" secondAttribute="centerX" constant="117.5" id="Ell-4O-Iqa"/>
Expand All @@ -392,6 +400,7 @@
<constraint firstItem="y1x-J5-Nkw" firstAttribute="centerX" secondItem="JWE-cA-TW0" secondAttribute="centerX" id="M6w-gn-nXE"/>
<constraint firstItem="ntr-45-Ycd" firstAttribute="centerX" secondItem="CZ1-7J-OGl" secondAttribute="centerX" constant="117.5" id="Qj1-d9-KDa"/>
<constraint firstItem="CZ1-7J-OGl" firstAttribute="top" secondItem="y1x-J5-Nkw" secondAttribute="bottom" constant="33" id="UHk-wV-Ehk"/>
<constraint firstItem="D7g-22-s49" firstAttribute="top" secondItem="3Zk-wE-jwj" secondAttribute="bottom" constant="8" id="eML-6C-Von"/>
<constraint firstItem="plO-2e-XmX" firstAttribute="top" secondItem="y1x-J5-Nkw" secondAttribute="bottom" constant="37" id="f0Z-LP-5Dg"/>
<constraint firstItem="4VK-4B-FEF" firstAttribute="centerX" secondItem="CZ1-7J-OGl" secondAttribute="centerX" constant="117" id="fDG-Jl-VER"/>
<constraint firstItem="y1x-J5-Nkw" firstAttribute="top" secondItem="Ew1-ik-0G1" secondAttribute="bottom" constant="25" id="gaL-qu-PB6"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,31 @@ - (void)testLongPress
[self verifyGesture:gesture orientation:orientation];
}

- (void)testForcePress
{
NSArray<NSDictionary<NSString *, id> *> *gesture =
@[@{
@"action": @"press",
@"options": @{
@"element": self.testedApplication.buttons[FBShowAlertForceTouchButtonName],
@"x": @1,
@"y": @1,
@"pressure": @1
}
},
@{
@"action": @"wait",
@"options": @{
@"ms": @300
}
},
@{
@"action": @"release"
}
];
[self verifyGesture:gesture orientation:UIDeviceOrientationPortrait];
}

@end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

extern NSString *const FBShowAlertButtonName;
extern NSString *const FBShowSheetAlertButtonName;
extern NSString *const FBShowAlertForceTouchButtonName;

/**
XCTestCase helper class used for integration tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

NSString *const FBShowAlertButtonName = @"Create App Alert";
NSString *const FBShowSheetAlertButtonName = @"Create Sheet Alert";
NSString *const FBShowAlertForceTouchButtonName = @"Create Alert (Force Touch)";

@interface FBIntegrationTestCase ()
@property (nonatomic, strong) XCUIApplication *testedApplication;
Expand Down