Skip to content

Commit ec68fa9

Browse files
committed
Merge branch 'modified_appium_wda' of ssh://git-qa.gz.netease.com:32200/maki/wda-eov into modified_appium_wda
2 parents 22fa435 + dc65d91 commit ec68fa9

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ typedef NS_ENUM(NSUInteger, FBUIInterfaceAppearance) {
147147
duration:(NSTimeInterval)duration
148148
error:(NSError **)error;
149149

150+
// modified start tag
151+
- (BOOL)fb_synthTapWithX:(CGFloat)x
152+
y:(CGFloat)y
153+
duration:(CGFloat)duration;
154+
155+
- (BOOL)fb_synthSwipe:(CGFloat)fromX
156+
fromY:(CGFloat)fromY
157+
toX:(CGFloat)toX
158+
toY:(CGFloat)toY
159+
delay:(CGFloat)delay;
160+
161+
- (BOOL)fb_synthKeyEvent:(id)keyId
162+
modifierFlags:(unsigned long long)modifierFlags;
163+
// end tag
164+
150165
/**
151166
Allows to set device appearance
152167

WebDriverAgentLib/Categories/XCUIDevice+FBHelpers.m

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#import "FBXCTestDaemonsProxy.h"
2525
#import "XCUIDevice.h"
2626

27+
#import "XCPointerEventPath.h"
28+
#import "XCSynthesizedEventRecord.h"
29+
#import "XCTRunnerDaemonSession.h"
30+
2731
static const NSTimeInterval FBHomeButtonCoolOffTime = 1.;
2832
static const NSTimeInterval FBScreenLockTimeout = 5.;
2933

@@ -363,6 +367,52 @@ - (BOOL)fb_performIOHIDEventWithPage:(unsigned int)page
363367
return nil == event ? NO : [self performDeviceEvent:event error:error];
364368
}
365369

370+
// modified start tag
371+
- (BOOL)fb_synthTapWithX:(CGFloat)x
372+
y:(CGFloat) y
373+
duration:(CGFloat) duration
374+
{
375+
CGPoint point = CGPointMake(x,y);
376+
377+
CGFloat TapDuration = duration;
378+
379+
XCPointerEventPath *pointerEventPath = [[XCPointerEventPath alloc] initForTouchAtPoint:point offset:0];
380+
[pointerEventPath liftUpAtOffset:TapDuration];
381+
382+
XCSynthesizedEventRecord *eventRecord = [[XCSynthesizedEventRecord alloc] initWithName:nil interfaceOrientation:0];
383+
[eventRecord addPointerEventPath:pointerEventPath];
384+
385+
[[self eventSynthesizer]
386+
synthesizeEvent:eventRecord
387+
completion:(id)^(BOOL result, NSError *invokeError) {} ];
388+
return YES;
389+
}
390+
391+
- (BOOL)fb_synthSwipe:(CGFloat)fromX
392+
fromY:(CGFloat) fromY
393+
toX:(CGFloat) toX
394+
toY:(CGFloat) toY
395+
delay:(CGFloat) delay
396+
{
397+
CGPoint point1 = CGPointMake(fromX,fromY);
398+
CGPoint point2 = CGPointMake(toX,toY);
399+
400+
CGFloat TapDuration = 0.05;
401+
402+
XCPointerEventPath *pointerEventPath = [[XCPointerEventPath alloc] initForTouchAtPoint:point1 offset:0];
403+
[pointerEventPath moveToPoint:point2 atOffset:delay];
404+
[pointerEventPath liftUpAtOffset:delay];
405+
406+
XCSynthesizedEventRecord *eventRecord = [[XCSynthesizedEventRecord alloc] initWithName:nil interfaceOrientation:0];
407+
[eventRecord addPointerEventPath:pointerEventPath];
408+
409+
[[self eventSynthesizer]
410+
synthesizeEvent:eventRecord
411+
completion:(id)^(BOOL result, NSError *invokeError) {} ];
412+
return YES;
413+
}
414+
// end tag
415+
366416
- (BOOL)fb_setAppearance:(FBUIInterfaceAppearance)appearance error:(NSError **)error
367417
{
368418
SEL selector = NSSelectorFromString(@"setAppearanceMode:");

WebDriverAgentLib/Commands/FBCustomCommands.m

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#import "XCUIElement+FBIsVisible.h"
3131
#import "XCUIElementQuery.h"
3232
#import "FBUnattachedAppLauncher.h"
33+
#import "sys/utsname.h"
3334

3435
@implementation FBCustomCommands
3536

@@ -56,7 +57,21 @@ + (NSArray *)routes
5657
[[FBRoute GET:@"/wda/batteryInfo"] respondWithTarget:self action:@selector(handleGetBatteryInfo:)],
5758
#endif
5859
[[FBRoute POST:@"/wda/pressButton"] respondWithTarget:self action:@selector(handlePressButtonCommand:)],
60+
61+
// modified start tag
62+
[[FBRoute POST:@"/wda/pressButton"].withoutSession respondWithTarget:self action:@selector(handlePressButtonCommand:)],
63+
// end tag
64+
5965
[[FBRoute POST:@"/wda/performIoHidEvent"] respondWithTarget:self action:@selector(handlePeformIOHIDEvent:)],
66+
67+
// modified start tag
68+
[[FBRoute POST:@"/wda/performIoHidEvent"].withoutSession respondWithTarget:self action:@selector(handlePeformIOHIDEvent:)],
69+
[[FBRoute POST:@"/wda/tap"] respondWithTarget:self action:@selector(handleDeviceTap:)],
70+
[[FBRoute POST:@"/wda/tap"].withoutSession respondWithTarget:self action:@selector(handleDeviceTap:)],
71+
[[FBRoute POST:@"/wda/swipe"] respondWithTarget:self action:@selector(handleDeviceSwipe:)],
72+
[[FBRoute POST:@"/wda/swipe"].withoutSession respondWithTarget:self action:@selector(handleDeviceSwipe:)],
73+
// end tag
74+
6075
[[FBRoute POST:@"/wda/expectNotification"] respondWithTarget:self action:@selector(handleExpectNotification:)],
6176
[[FBRoute POST:@"/wda/siri/activate"] respondWithTarget:self action:@selector(handleActivateSiri:)],
6277
[[FBRoute POST:@"/wda/apps/launchUnattached"].withoutSession respondWithTarget:self action:@selector(handleLaunchUnattachedApp:)],
@@ -285,6 +300,34 @@ + (NSDictionary *)processArguments:(XCUIApplication *)app
285300
return FBResponseWithOK();
286301
}
287302

303+
// modified start tag
304+
+ (id <FBResponsePayload>)handleDeviceTap:(FBRouteRequest *)request
305+
{
306+
CGFloat x = [request.arguments[@"x"] doubleValue];
307+
CGFloat y = [request.arguments[@"y"] doubleValue];
308+
CGFloat duration = [request.arguments[@"duration"] doubleValue];
309+
[XCUIDevice.sharedDevice
310+
fb_synthTapWithX:x
311+
y:y duration:duration];
312+
313+
return FBResponseWithOK();
314+
}
315+
316+
+ (id <FBResponsePayload>)handleDeviceSwipe:(FBRouteRequest *)request
317+
{
318+
CGFloat fromX = [request.arguments[@"fromX"] doubleValue];
319+
CGFloat fromY = [request.arguments[@"fromY"] doubleValue];
320+
CGFloat toX = [request.arguments[@"toX"] doubleValue];
321+
CGFloat toY = [request.arguments[@"toY"] doubleValue];
322+
CGFloat delay = [request.arguments[@"delay"] doubleValue];
323+
[XCUIDevice.sharedDevice
324+
fb_synthSwipe:fromX
325+
fromY:fromY toX:toX toY:toY delay:delay];
326+
327+
return FBResponseWithOK();
328+
}
329+
// modified end tag
330+
288331
+ (id <FBResponsePayload>)handleLaunchUnattachedApp:(FBRouteRequest *)request
289332
{
290333
NSString *bundle = (NSString *)request.arguments[@"bundleId"];

0 commit comments

Comments
 (0)