Skip to content

Commit

Permalink
Add wda/tap method
Browse files Browse the repository at this point in the history
Added raw/optimized tap method to tap at absolute screen coordinates as fast as possible.
  • Loading branch information
nanoscopic committed May 9, 2021
1 parent faf90f1 commit 3ad6454
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.h
Expand Up @@ -113,6 +113,9 @@ NS_ASSUME_NONNULL_BEGIN
duration:(NSTimeInterval)duration
error:(NSError **)error;

- (BOOL)fb_synthTapWithX:(CGFloat)x
y:(CGFloat)y;

@end

NS_ASSUME_NONNULL_END
24 changes: 24 additions & 0 deletions WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.m
Expand Up @@ -23,6 +23,11 @@
#import "XCUIDevice.h"
#import "XCDeviceEvent.h"

#import "XCPointerEventPath.h"
#import "XCSynthesizedEventRecord.h"
#import "FBXCTestDaemonsProxy.h"
#import "XCTRunnerDaemonSession.h"

static const NSTimeInterval FBHomeButtonCoolOffTime = 1.;
static const NSTimeInterval FBScreenLockTimeout = 5.;

Expand Down Expand Up @@ -294,4 +299,23 @@ - (BOOL)fb_performIOHIDEventWithPage:(unsigned int)page
return [self performDeviceEvent:event error:error];
}

- (BOOL)fb_synthTapWithX:(CGFloat)x
y:(CGFloat) y
{
CGPoint point = CGPointMake(x,y);

CGFloat TapDuration = 0.05;

XCPointerEventPath *pointerEventPath = [[XCPointerEventPath alloc] initForTouchAtPoint:point offset:0];
[pointerEventPath liftUpAtOffset:TapDuration];

XCSynthesizedEventRecord *eventRecord = [[XCSynthesizedEventRecord alloc] initWithName:nil interfaceOrientation:0];
[eventRecord addPointerEventPath:pointerEventPath];

[[self eventSynthesizer]
synthesizeEvent:eventRecord
completion:(id)^(BOOL result, NSError *invokeError) {} ];
return YES;
}

@end
13 changes: 13 additions & 0 deletions WebDriverAgentLib/Commands/FBCustomCommands.m
Expand Up @@ -57,6 +57,8 @@ + (NSArray *)routes
#endif
[[FBRoute POST:@"/wda/pressButton"] respondWithTarget:self action:@selector(handlePressButtonCommand:)],
[[FBRoute POST:@"/wda/performIoHidEvent"] respondWithTarget:self action:@selector(handlePeformIOHIDEvent:)],
[[FBRoute POST:@"/wda/tap"] respondWithTarget:self action:@selector(handleDeviceTap:)],
[[FBRoute POST:@"/wda/tap"].withoutSession respondWithTarget:self action:@selector(handleDeviceTap:)],
[[FBRoute POST:@"/wda/expectNotification"] respondWithTarget:self action:@selector(handleExpectNotification:)],
[[FBRoute POST:@"/wda/siri/activate"] respondWithTarget:self action:@selector(handleActivateSiri:)],
[[FBRoute POST:@"/wda/apps/launchUnattached"].withoutSession respondWithTarget:self action:@selector(handleLaunchUnattachedApp:)],
Expand Down Expand Up @@ -258,6 +260,17 @@ + (NSDictionary *)processArguments:(XCUIApplication *)app
return FBResponseWithOK();
}

+ (id <FBResponsePayload>)handleDeviceTap:(FBRouteRequest *)request
{
CGFloat x = [request.arguments[@"x"] doubleValue];
CGFloat y = [request.arguments[@"y"] doubleValue];
[XCUIDevice.sharedDevice
fb_synthTapWithX:x
y:y];

return FBResponseWithOK();
}

+ (id <FBResponsePayload>)handlePeformIOHIDEvent:(FBRouteRequest *)request
{
NSNumber *page = request.arguments[@"page"];
Expand Down

0 comments on commit 3ad6454

Please sign in to comment.