-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathAfMHandlers.m
1221 lines (1024 loc) · 58.5 KB
/
AfMHandlers.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// AfMHandlers.m
// AppiumForMac
//
// Created by Dan Cuellar on 7/28/13.
// Improvements by Stuart Russell at Intuit.
// Copyright (c) 2013-2016 Appium. All rights reserved.
//
#import "AfMHandlers.h"
#import <PFAssistive/PFAssistive.h>
#import "AfMElementLocator.h"
#import "AfMSessionController.h"
#import "AfMStatusCodes.h"
#import "AppiumMacHTTP303JSONResponse.h"
#import "AppiumMacHTTPJSONResponse.h"
#import "HTTPMessage.h"
#import "NSData+Base64.h"
#import "Utility.h"
@implementation AfMHandlers
- (id)init
{
self = [super init];
if (self) {
[self setSessions:[NSMutableDictionary new]];
}
return self;
}
-(AfMSessionController*) controllerForSession:(NSString*)sessionId
{
return [self.sessions objectForKey:sessionId];
}
// This convenience method uses the path to select a session, then sends this message to the session instance.
- (AppiumMacHTTPJSONResponse *)executeWebDriverCommandWithPath:(NSString *)path data:(NSData *)postData onMainThread:(BOOL)onMainThread
commandBlock:(AppiumMacHTTPJSONResponse *(^)(AfMSessionController *session, NSDictionary *commandParams, int *statusCode))commandBlock
{
NSString *sessionId = [Utility getSessionIDFromPath:path];
AfMSessionController *session = [self controllerForSession:sessionId];
if (!session) {
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchDriver session:session.sessionId];
}
return [session executeWebDriverCommandWithPath:path data:postData onMainThread:onMainThread commandBlock:commandBlock];
}
// GET /status
// Query the server's current status.
- (AppiumMacHTTPJSONResponse *)get_status:(NSString*)path
{
// This can not use executeWebDriverCommandWithPath because that method requires a sessionId in the path.
NSDictionary *buildJson = [NSDictionary dictionaryWithObjectsAndKeys:[Utility bundleVersion], @"version", [Utility bundleRevision], @"revision", [NSString stringWithFormat:@"%d", [Utility unixTimestamp]], @"time", nil];
NSDictionary *osJson = [NSDictionary dictionaryWithObjectsAndKeys:[Utility arch], @"arch", @"Mac OS X", @"name", [Utility version], @"version", nil];
NSDictionary *json = [NSDictionary dictionaryWithObjectsAndKeys:buildJson, @"build", osJson, @"os", nil];
return [AppiumMacHTTPJSONResponse responseWithJson:json status:kAfMStatusCodeSuccess session:nil];
}
// POST /session
// Create a new session.
// https://w3c.github.io/webdriver/webdriver-spec.html#new-session
- (AppiumMacHTTPJSONResponse *)post_session:(NSString*)path data:(NSData*)postData
{
// This can not use executeWebDriverCommandWithPath because that method requires a sessionId in the path.
NSDictionary *postParams = [Utility dictionaryFromPostData:postData];
NSDictionary *desiredCapabilities = [postParams objectForKey:@"desiredCapabilities"];
// We can only have so many sessions, and no more.
if ([self.sessions count] >= kMaximumActiveSessions) {
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeSessionNotCreatedException session:nil];
}
// Create a new session. It will generate its own sessionId. Use that as a key for our session dictionary.
AfMSessionController *newSession = [[AfMSessionController alloc] init];
[newSession setDesiredCapabilities:desiredCapabilities];
[self.sessions setValue:newSession forKey:newSession.sessionId];
return [AppiumMacHTTPJSONResponse responseWithJson:newSession.capabilities status:kAfMStatusCodeSuccess session:newSession.sessionId];
}
// GET /sessions
// Returns a list of the currently active sessions.
- (AppiumMacHTTPJSONResponse *)get_sessions:(NSString*)path
{
// This can not use executeWebDriverCommandWithPath because that method requires a sessionId in the path.
NSMutableArray *json = [NSMutableArray new];
for (id key in self.sessions) {
AfMSessionController *session = [self.sessions objectForKey:key];
[json addObject:@{@"id":key, @"capabilities":session.capabilities}];
}
return [AppiumMacHTTPJSONResponse responseWithJson:json status:kAfMStatusCodeSuccess session: nil];
}
// GET /session/:sessionId
// Retrieve the capabilities of the specified session.
- (AppiumMacHTTPJSONResponse *)get_session:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
return [AppiumMacHTTPJSONResponse responseWithJson:session.capabilities status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// DELETE /session/:sessionId
// Delete the session.
- (AppiumMacHTTPJSONResponse *)delete_session:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
if (session != nil) {
[self.sessions removeObjectForKey:session.sessionId];
}
return [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// POST /session/:sessionId/timeouts
// Configure the amount of time that a particular type of operation can execute for before they are aborted and a |Timeout| error is returned to the client.
- (AppiumMacHTTPJSONResponse *)post_timeouts:(NSString*)path data:(NSData*)postData;
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSTimeInterval seconds = 0;
NSNumber *msValue = [commandParams objectForKey:@"ms"];
if (msValue && [msValue isKindOfClass:[NSNumber class]]) {
seconds = [msValue unsignedIntegerValue] / 1000;
}
// Valid values are: "script" for script timeouts, "implicit" for modifying the implicit wait timeout and "page load" for setting a page load timeout.
NSString *type = [commandParams objectForKey:@"type"];
if (type && [type isKindOfClass:[NSString class]]) {
if ([type isEqualToString:@"implicit"]) {
session.implicitTimeout = seconds;
} else if ([type isEqualToString:@"page load"]) {
session.pageLoadTimeout = seconds;
} else if ([type isEqualToString:@"script"]) {
session.scriptTimeout = seconds;
} else {
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeUnknownCommand session:session.sessionId];
}
}
return [AppiumMacHTTPJSONResponse responseWithJson:session.currentWindowHandle status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// POST /session/:sessionId/timeouts/async_script
// Set the amount of time, in milliseconds, that asynchronous scripts executed by /session/:sessionId/execute_async are permitted to run before they are aborted and a |Timeout| error is returned to the client.
- (AppiumMacHTTPJSONResponse *)post_timeouts_async_script:(NSString*)path data:(NSData*)postData;
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSNumber *msValue = [commandParams objectForKey:@"ms"];
if (msValue && [msValue isKindOfClass:[NSNumber class]]) {
session.scriptTimeout = [msValue unsignedIntegerValue] / 1000;
}
return [AppiumMacHTTPJSONResponse responseWithJson:session.currentWindowHandle status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// POST /session/:sessionId/timeouts/implicit_wait
// Set the amount of time the driver should wait when searching for elements.
- (AppiumMacHTTPJSONResponse *)post_timeouts_implicit_wait:(NSString*)path data:(NSData*)postData;
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSNumber *msValue = [commandParams objectForKey:@"ms"];
if (msValue && [msValue isKindOfClass:[NSNumber class]]) {
session.implicitTimeout = [msValue unsignedIntegerValue] / 1000;
}
return [AppiumMacHTTPJSONResponse responseWithJson:session.currentWindowHandle status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/window_handle
// Retrieve the current window handle.
- (AppiumMacHTTPJSONResponse *)get_window_handle:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
if ([session.currentWindowHandle intValue] >= session.allWindows.count)
{
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchWindow session:session.sessionId];
}
return [AppiumMacHTTPJSONResponse responseWithJson:session.currentWindowHandle status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/window_handles
// Retrieve the list of all window handles available to the session.
- (AppiumMacHTTPJSONResponse *)get_window_handles:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
return [AppiumMacHTTPJSONResponse responseWithJson:session.allWindowHandles status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/url
// Retrieve the URL of the current page.
- (AppiumMacHTTPJSONResponse *)get_url:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
return [AppiumMacHTTPJSONResponse responseWithJson:session.currentApplication.AXTitle status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// POST /session/:sessionId/url
// Navigate to a new URL.
- (AppiumMacHTTPJSONResponse *)post_url:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
// In AppiumForMac, a "url" is an application name or url string, not a hypertext link.
// e.g. url == "Calculator" will launch Calculator.app.
NSString *url = (NSString*)[commandParams objectForKey:@"url"];
return [session postURL:url];
}];
}
// POST /session/:sessionId/forward
// Navigate forwards in the browser history, if possible.
// POST /session/:sessionId/back
// Navigate backwards in the browser history, if possible.
// POST /session/:sessionId/refresh
// Refresh the current page.
// POST /session/:sessionId/execute
// Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be synchronous and the result of evaluating the script is returned to the client.
// POST /session/:sessionId/execute_async
// Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. The executed script is assumed to be asynchronous and must signal that is done by invoking the provided callback, which is always provided as the final argument to the function.
// GET /session/:sessionId/screenshot
// Take a screenshot of the current page.
-(HTTPDataResponse*)get_screenshot:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
// Ask the session to put a screen shot into the clipboard.
if (![session screenCaptureToClipboard]) {
return [AppiumMacHTTPJSONResponse responseWithJson:nil
status:kAfMStatusCodeSuccess
session:session.sessionId];
}
NSArray *objectsToPaste = [[NSPasteboard generalPasteboard] readObjectsForClasses:@[[NSImage class]]
options:@{}];
NSImage *image = [objectsToPaste objectAtIndex:0];
NSData *tiffData = [image TIFFRepresentation];
NSData *pngData = [[NSBitmapImageRep imageRepWithData:tiffData] representationUsingType:NSPNGFileType
properties:@{}];
NSString *base64Image = [pngData base64EncodedString];
return [AppiumMacHTTPJSONResponse responseWithJson:base64Image
status:kAfMStatusCodeSuccess
session:session.sessionId];
}];
}
// GET /session/:sessionId/ime/available_engines
// List all available engines on the machine. To use an engine, it has to be present in this list.
// GET /session/:sessionId/ime/active_engine
// Get the name of the active IME engine. The name string is platform specific.
// GET /session/:sessionId/ime/activated
// Indicates whether IME input is active at the moment (not if it's available).
// POST /session/:sessionId/ime/deactivate
// De-activates the currently-active IME engine.
// POST /session/:sessionId/ime/activate
// Make an engine that is available (appears on the list returned by getAvailableEngines) active.
// POST /session/:sessionId/frame
// Change focus to another frame on the page. If the frame id is null, the server should switch to the page's default content.
// POST /session/:sessionId/frame/parent
// Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged.
// POST /session/:sessionId/window
// Change focus to another window. The window to change focus to may be specified by its server assigned window handle, or by the value of its name attribute.
- (AppiumMacHTTPJSONResponse *)post_window:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
// activate application for supplied process
NSString *windowHandle = (NSString*)[commandParams objectForKey:@"name"];
if ([windowHandle intValue] >= session.allWindows.count)
{
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchWindow session:session.sessionId];
}
[session setCurrentWindowHandle:windowHandle];
[session activateWindow];
return [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// DELETE /session/:sessionId/window
// Close the current window.
- (AppiumMacHTTPJSONResponse *)delete_window:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
// check that there is at least one window
NSUInteger originalWindowCount = session.allWindows.count;
if (originalWindowCount < 1)
{
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchWindow session:session.sessionId];
}
// close the window
[session closeWindow];
return (session.allWindows.count < originalWindowCount) ? [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId] : [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchWindow session:session.sessionId];
}];
}
// POST /session/:sessionId/window/:windowHandle/size
// Change the size of the specified window. If the :windowHandle URL parameter is "current", the currently active window will be resized.
- (AppiumMacHTTPJSONResponse *)post_window_size:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSString *windowHandle = [Utility getItemFromPath:path withSeparator:@"window"];
if (windowHandle == nil) {
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchWindow session:session.sessionId];
}
PFUIElement *window = nil;
if ([windowHandle isEqualToString:@"current"]) {
window = [session currentWindow];
} else {
window = [session windowForHandle:windowHandle];
}
CGFloat width = [(NSNumber *)[commandParams objectForKey:@"width"] floatValue];
CGFloat height = [(NSNumber *)[commandParams objectForKey:@"height"] floatValue];
NSSize size = [window.AXSize sizeValue];
size.width = width;
size.height = height;
[window setAXSize:[NSValue valueWithSize:size]];
return [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/window/:windowHandle/size
// Get the size of the specified window. If the :windowHandle URL parameter is "current", the size of the currently active window will be returned.
- (AppiumMacHTTPJSONResponse *)get_window_size:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSString *windowHandle = [Utility getItemFromPath:path withSeparator:@"window"];
if (windowHandle == nil) {
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchWindow session:session.sessionId];
}
PFUIElement *window = nil;
if ([windowHandle isEqualToString:@"current"]) {
window = [session currentWindow];
} else {
window = [session windowForHandle:windowHandle];
}
NSSize size = [window.AXSize sizeValue];
return [AppiumMacHTTPJSONResponse responseWithJson:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:size.width], @"width", [NSNumber numberWithFloat:size.height], @"height", nil] status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// POST /session/:sessionId/window/:windowHandle/position
// Change the position of the specified window. If the :windowHandle URL parameter is "current", the currently active window will be moved.
- (AppiumMacHTTPJSONResponse *)post_window_position:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSString *windowHandle = [Utility getItemFromPath:path withSeparator:@"window"];
if (windowHandle == nil) {
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchWindow session:session.sessionId];
}
PFUIElement *window = nil;
if ([windowHandle isEqualToString:@"current"]) {
window = [session currentWindow];
} else {
window = [session windowForHandle:windowHandle];
}
CGFloat x = [(NSNumber*)[commandParams objectForKey:@"x"] floatValue];
CGFloat y = [(NSNumber*)[commandParams objectForKey:@"y"] floatValue];
NSPoint position = [window.AXPosition pointValue];
position.x = x;
position.y = y;
[window setAXPosition:[NSValue valueWithPoint:position]];
return [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/window/:windowHandle/position
// Get the position of the specified window. If the :windowHandle URL parameter is "current", the position of the currently active window will be returned.
- (AppiumMacHTTPJSONResponse *)get_window_position:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSString *windowHandle = [Utility getItemFromPath:path withSeparator:@"window"];
if (windowHandle == nil) {
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchWindow session:session.sessionId];
}
PFUIElement *window = nil;
if ([windowHandle isEqualToString:@"current"]) {
window = [session currentWindow];
} else {
window = [session windowForHandle:windowHandle];
}
NSPoint position = [[window AXPosition] pointValue];
return [AppiumMacHTTPJSONResponse responseWithJson:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:position.x], "x", [NSNumber numberWithFloat:position.y], @"y", nil] status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// POST /session/:sessionId/window/:windowHandle/maximize
// Maximize the specified window if not already maximized. If the :windowHandle URL parameter is "current", the currently active window will be maximized.
// GET /session/:sessionId/cookie
// Retrieve all cookies visible to the current page.
- (AppiumMacHTTPJSONResponse *)get_cookie:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSArray *allCookies = [session getAllCookies];
NSLog(@"get_cookie allCookies:%@", allCookies);
return [AppiumMacHTTPJSONResponse responseWithJson:allCookies status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// POST /session/:sessionId/cookie
// Set a cookie. If the cookie path is not specified, it should be set to "/". Likewise, if the domain is omitted, it should default to the current page's domain.
- (AppiumMacHTTPJSONResponse *)post_cookie:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSLog(@"post_cookie commandParams:%@", commandParams);
NSDictionary *cookie = commandParams[@"cookie"];
[session setCookie:cookie];
return [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// DELETE /session/:sessionId/cookie
// Delete all cookies visible to the current page.
// DELETE /session/:sessionId/cookie/:name
// Delete the cookie with the given name. This command should be a no-op if there is no such cookie visible to the current page.
// GET /session/:sessionId/source
// Get the current page source.
- (AppiumMacHTTPJSONResponse *)get_source:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
// xml page source
NSString *pageSource = [[NSString alloc]initWithData:[session xmlPageSource].XMLData encoding:NSUTF8StringEncoding];
//NSLog(@"%@", pageSource);
return [AppiumMacHTTPJSONResponse responseWithJson:pageSource status:kAfMStatusCodeSuccess session:session.sessionId];
// json page source
//return [AppiumMacHTTPJSONResponse responseWithJson:[session pageSource] status:0 session:session.sessionId];
}];
}
// POST /session/:sessionId/element
// Search for an element on the page, starting from the document root.
- (AppiumMacHTTPJSONResponse *)post_element:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSString *using = (NSString*)[commandParams objectForKey:@"using"];
NSString *value = (NSString*)[commandParams objectForKey:@"value"];
AfMElementLocator *locator = [AfMElementLocator locatorWithSession:session using:using value:value];
// initialize status as though no element were found
*statusCode = kAfMStatusCodeNoSuchElement;
if (locator != nil)
{
PFUIElement *element = [locator findUsingBaseUIElement:nil statusCode:statusCode];
if (element != nil)
{
session.elementIndex++;
NSString *myKey = [NSString stringWithFormat:@"%d", session.elementIndex];
[session.elements setValue:element forKey:myKey];
return [AppiumMacHTTPJSONResponse responseWithJson:[NSDictionary dictionaryWithObject:myKey forKey:@"ELEMENT"] status:kAfMStatusCodeSuccess session:session.sessionId];
}
}
return [AppiumMacHTTPJSONResponse responseWithJsonError:*statusCode session:session.sessionId];
}];
}
// POST /session/:sessionId/elements
// Search for multiple elements on the page, starting from the document root.
- (AppiumMacHTTPJSONResponse *)post_elements:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSString *using = (NSString*)[commandParams objectForKey:@"using"];
NSString *value = (NSString*)[commandParams objectForKey:@"value"];
AfMElementLocator *locator = [AfMElementLocator locatorWithSession:session using:using value:value];
if (locator != nil)
{
NSMutableArray *matches = [NSMutableArray new];
[locator findAllUsingBaseUIElement:nil results:matches statusCode:statusCode];
if (0 == matches.count) {
return [AppiumMacHTTPJSONResponse responseWithJson:@[] status:*statusCode session:session.sessionId];
}
NSMutableArray *elements = [NSMutableArray new];
for(PFUIElement *element in matches) {
session.elementIndex++;
NSString *myKey = [NSString stringWithFormat:@"%d", session.elementIndex];
[session.elements setObject:element forKey:myKey];
[elements addObject:[NSDictionary dictionaryWithObject:myKey forKey:@"ELEMENT"]];
}
return [AppiumMacHTTPJSONResponse responseWithJson:elements status:*statusCode session:session.sessionId];
}
return [AppiumMacHTTPJSONResponse responseWithJsonError:*statusCode session:session.sessionId];
}];
}
// POST /session/:sessionId/element/active
// Get the element on the page that currently has focus.
// GET /session/:sessionId/element/:id
// Describe the identified element.
// POST /session/:sessionId/element/:id/element
// Search for an element on the page, starting from the identified element.
- (AppiumMacHTTPJSONResponse *)post_element_element:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
PFUIElement *rootUIElement = [commandParams objectForKey:@"elementObject"];
NSString *using = (NSString*)[commandParams objectForKey:@"using"];
NSString *value = (NSString*)[commandParams objectForKey:@"value"];
AfMElementLocator *locator = [AfMElementLocator locatorWithSession:session using:using value:value];
// initialize status as though no element were found
*statusCode = kAfMStatusCodeNoSuchElement;
if (locator != nil)
{
PFUIElement *uiElement = [locator findUsingBaseUIElement:rootUIElement statusCode:statusCode];
if (uiElement != nil)
{
session.elementIndex++;
NSString *myKey = [NSString stringWithFormat:@"%d", session.elementIndex];
[session.elements setValue:uiElement forKey:myKey];
return [AppiumMacHTTPJSONResponse responseWithJson:[NSDictionary dictionaryWithObject:myKey forKey:@"ELEMENT"] status:kAfMStatusCodeSuccess session:session.sessionId];
}
}
return [AppiumMacHTTPJSONResponse responseWithJsonError:*statusCode session:session.sessionId];
}];
}
// POST /session/:sessionId/element/:id/elements
// Search for multiple elements on the page, starting from the identified element.
- (AppiumMacHTTPJSONResponse *)post_element_elements:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
PFUIElement *rootUIElement = [commandParams objectForKey:@"elementObject"];
NSString *using = (NSString*)[commandParams objectForKey:@"using"];
NSString *value = (NSString*)[commandParams objectForKey:@"value"];
AfMElementLocator *locator = [AfMElementLocator locatorWithSession:session using:using value:value];
// initialize status as though no element were found
*statusCode = kAfMStatusCodeSuccess;
if (locator != nil)
{
NSMutableArray *matches = [NSMutableArray new];
[locator findAllUsingBaseUIElement:rootUIElement results:matches statusCode:statusCode];
if (0 == matches.count) {
return [AppiumMacHTTPJSONResponse responseWithJson:@[] status:*statusCode session:session.sessionId];
}
NSMutableArray *elements = [NSMutableArray new];
for(PFUIElement *element in matches) {
session.elementIndex++;
NSString *myKey = [NSString stringWithFormat:@"%d", session.elementIndex];
[session.elements setObject:element forKey:myKey];
[elements addObject:[NSDictionary dictionaryWithObject:myKey forKey:@"ELEMENT"]];
}
return [AppiumMacHTTPJSONResponse responseWithJson:elements status:*statusCode session:session.sessionId];
}
return [AppiumMacHTTPJSONResponse responseWithJsonError:*statusCode session:session.sessionId];
}];
}
// POST /session/:sessionId/element/:id/click
// Click on an element.
-(AppiumMacHTTPJSONResponse *)post_element_click:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
id element = [commandParams objectForKey:@"elementObject"];
if (![session isElementDisplayed:element]) {
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeElementNotVisible session:session.sessionId];
}
BOOL result = [session clickElement:element];
return result ? [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId] :
[AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeUnknownError session:session.sessionId];
}];
}
// POST /session/:sessionId/element/:id/submit
// Submit a FORM element. The submit command may also be applied to any element that is a descendant of a FORM element.
// GET /session/:sessionId/element/:id/text
// Returns the visible text for the element.
- (AppiumMacHTTPJSONResponse *)get_element_text:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
PFUIElement *element = [commandParams objectForKey:@"elementObject"];
id valueAttribute = element.AXValue;
if (valueAttribute != nil)
{
NSString *text = [NSString stringWithFormat:@"%@", valueAttribute];
return [AppiumMacHTTPJSONResponse responseWithJson:text status:kAfMStatusCodeSuccess session:session.sessionId];
}
return [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeUnknownError session:session.sessionId];
}];
}
// POST /session/:sessionId/element/:id/value
// Send a sequence of key strokes to an element.
- (AppiumMacHTTPJSONResponse *)post_element_value:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
PFUIElement *element = [commandParams objectForKey:@"elementObject"];
NSArray *value = [commandParams objectForKey:@"value"];
// For some reason Selenium is sending element.setValue() when a sendKeys() command was requested.
// If element is a field that must receive keystrokes to trigger other behaviors, then type the value.
if ([element.AXRole isEqualToString:@"AXTextField"]) {
[session clickElement:element];
[session sendKeys:value toElement:element];
} else {
// Not a text field so set the value programmatically, without typing.
// This is the original Appium solution for every AXRole.
[element setAXValue:[value componentsJoinedByString:@""]];
}
return [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// POST /session/:sessionId/keys
// Send a sequence of key strokes to the active element. This command is similar to the 'value' command in every aspect except the implicit termination: The modifiers are _not_ released at the end of the call. Rather, the state of the modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed.
- (AppiumMacHTTPJSONResponse *)post_keys:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
NSArray *value = [commandParams objectForKey:@"value"];
[session sendKeys:value];
return [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/element/:id/name
// Query for an element's tag name.
- (AppiumMacHTTPJSONResponse *)get_element_name:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
PFUIElement *element = [commandParams objectForKey:@"elementObject"];
return [AppiumMacHTTPJSONResponse responseWithJson:element.AXTitle status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// POST /session/:sessionId/element/:id/clear
// Clear a TEXTAREA or text INPUT element's value.
- (AppiumMacHTTPJSONResponse *)post_element_clear:(NSString*)path data:(NSData*)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
PFUIElement *element = [commandParams objectForKey:@"elementObject"];
if (![session isElementDisplayed:element]) {
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeElementNotVisible session:session.sessionId];
}
id value = [element AXValue];
if (value != nil && [value isKindOfClass:[NSString class]])
{
[element setAXValue:@""];
}
// TODO: Add error handling
return [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/element/:id/selected
// Determine if an OPTION element, or an INPUT element of type checkbox or radiobutton is currently selected.
- (AppiumMacHTTPJSONResponse *)get_element_selected:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
PFUIElement *element = [commandParams objectForKey:@"elementObject"];
return [AppiumMacHTTPJSONResponse responseWithJson:element.AXFocused status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/element/:id/enabled
// Determine if an element is currently enabled.
- (AppiumMacHTTPJSONResponse *)get_element_enabled:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
PFUIElement *element = [commandParams objectForKey:@"elementObject"];
return [AppiumMacHTTPJSONResponse responseWithJson:element.AXEnabled status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/element/:id/attribute/:name
// Get the value of an element's attribute.
- (AppiumMacHTTPJSONResponse *)get_element_attribute:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil
onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
PFUIElement *element = [commandParams objectForKey:@"elementObject"];
NSString *attributeName = [Utility getItemFromPath:path withSeparator:@"/attribute/"];
id attributeValue = [element valueForAttribute:attributeName];
// The original AfM returned "(null)" for a nil (non-existent) attribute.
// This was changed to meet the standard, which is the empty string, "".
if (attributeValue == nil) {
attributeValue = @"";
}
return [AppiumMacHTTPJSONResponse responseWithJson:[NSString stringWithFormat:@"%@", attributeValue] status:0 session:session.sessionId];
}];
}
// GET /session/:sessionId/element/:id/equals/:other
// Test if two element IDs refer to the same DOM element.
- (AppiumMacHTTPJSONResponse *)get_element_equals:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
// The first element was already validated.
PFUIElement *element = [commandParams objectForKey:@"elementObject"];
// get the second element
NSString *otherElementId = [Utility getItemFromPath:path withSeparator:@"/equals/"];
PFUIElement *otherElement = [session.elements objectForKey:otherElementId];
// check that the second element is valid
int status2 = [session checkElement:otherElement];
if (status2 != kAfMStatusCodeSuccess) {
[AppiumMacHTTPJSONResponse responseWithJsonError:status2 session:session.sessionId];
}
return [AppiumMacHTTPJSONResponse responseWithJson:[NSNumber numberWithBool:[element isEqualToElement:otherElement]] status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/element/:id/displayed
// Determine if an element is currently displayed.
- (AppiumMacHTTPJSONResponse *)get_element_displayed:(NSString*)path
{
// Can't use executeWebDriverCommandWithPath here, because it filters out elements that are not visible.
if (![NSThread isMainThread]) {
[self performSelectorOnMainThread:_cmd withObject:path waitUntilDone:YES];
}
NSString *sessionId = [Utility getSessionIDFromPath:path];
AfMSessionController *session = [self controllerForSession:sessionId];
if (!session) {
return [AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchDriver session:session.sessionId];
}
BOOL displayed;
// get the element
NSString *elementId = [Utility getElementIDFromPath:path];
PFUIElement *element = [session.elements objectForKey:elementId];
// check the element is valid
int status = [session checkElement:element];
if (status == kAfMStatusCodeSuccess) {
// By definition, usable elements are displayed.
displayed = YES;
} else if (status == kAfMStatusCodeElementNotVisible) {
displayed = NO;
} else {
// The element was not valid and its visible state is undefined.
return [AppiumMacHTTPJSONResponse responseWithJsonError:status session:sessionId];
}
return [AppiumMacHTTPJSONResponse responseWithJson:[NSNumber numberWithBool:displayed] status:kAfMStatusCodeSuccess session: sessionId];
}
// GET /session/:sessionId/element/:id/location
// Determine an element's location on the page. The point (0, 0) refers to the upper-left corner of the page. The element's coordinates are returned as a JSON object with x and y properties.
- (AppiumMacHTTPJSONResponse *)get_element_location:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
PFUIElement *element = [commandParams objectForKey:@"elementObject"];
NSPoint point = [element.AXPosition pointValue];
NSDictionary *position = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:point.x], @"x", [NSNumber numberWithFloat:point.y], @"y", nil];
return [AppiumMacHTTPJSONResponse responseWithJson:position status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/element/:id/location_in_view
// Determine an element's location on the screen once it has been scrolled into view.
// GET /session/:sessionId/element/:id/size
// Determine an element's size in pixels. The size will be returned as a JSON object with width and height properties.
- (AppiumMacHTTPJSONResponse *)get_element_size:(NSString*)path
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
PFUIElement *element = [commandParams objectForKey:@"elementObject"];
NSSize size = [element.AXSize sizeValue];
NSDictionary *sizeDict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:size.width], @"width", [NSNumber numberWithFloat:size.height], @"height", nil];
return [AppiumMacHTTPJSONResponse responseWithJson:sizeDict status:kAfMStatusCodeSuccess session:session.sessionId];
}];
}
// GET /session/:sessionId/element/:id/css/:propertyName
// Query the value of an element's computed CSS property.
// GET /session/:sessionId/orientation
// Get the current browser orientation. The server should return a valid orientation value as defined in ScreenOrientation: {LANDSCAPE|PORTRAIT}.
// POST /session/:sessionId/orientation
// Set the browser orientation. The orientation should be specified as defined in ScreenOrientation: {LANDSCAPE|PORTRAIT}.
// GET /session/:sessionId/alert_text
// Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog.
// POST /session/:sessionId/alert_text
// Sends keystrokes to a JavaScript prompt() dialog.
// POST /session/:sessionId/accept_alert
// Accepts the currently displayed alert dialog. Usually, this is equivalent to clicking on the 'OK' button in the dialog.
// POST /session/:sessionId/dismiss_alert
// Dismisses the currently displayed alert dialog. For confirm() and prompt() dialogs, this is equivalent to clicking the 'Cancel' button. For alert() dialogs, this is equivalent to clicking the 'OK' button.
// POST /session/:sessionId/moveto
// Move the mouse by an offset of the specificed element. If no element is specified, the move is relative to the current mouse cursor. If an element is provided but no offset, the mouse will be moved to the center of the element. If the element is not visible, it will be scrolled into view.
- (AppiumMacHTTPJSONResponse *)post_moveto:(NSString*)path data:(NSData *)postData;
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
if ([Utility isRunningInSandbox]) {
return [session moveMouseInsideSandbox:commandParams statusCode:statusCode];
} else {
return [session moveMouseOutsideSandbox:commandParams statusCode:statusCode];
}
}];
}
// POST /session/:sessionId/click
// Click any mouse button (at the coordinates set by the last moveto command). Note that calling this command after calling buttondown and before calling button up (or any out-of-order interactions sequence) will yield undefined behaviour).
- (AppiumMacHTTPJSONResponse *)post_click:(NSString*)path data:(NSData *)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
if ([Utility isRunningInSandbox]) {
return [session mouseButtonActionInsideSandbox:@"click" commandParams:commandParams statusCode:statusCode];
} else {
return [session mouseButtonActionOutsideSandbox:@"click" commandParams:commandParams statusCode:statusCode];
}
}];
}
// POST /session/:sessionId/buttondown
// Click and hold the left mouse button (at the coordinates set by the last moveto command). Note that the next mouse-related command that should follow is buttonup . Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour.
- (AppiumMacHTTPJSONResponse *)post_buttondown:(NSString*)path data:(NSData *)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
if ([Utility isRunningInSandbox]) {
return [session mouseButtonActionInsideSandbox:@"buttondown" commandParams:commandParams statusCode:statusCode];
} else {
return [session mouseButtonActionOutsideSandbox:@"buttondown" commandParams:commandParams statusCode:statusCode];
}
}];
}
// POST /session/:sessionId/buttonup
// Releases the mouse button previously held (where the mouse is currently at). Must be called once for every buttondown command issued. See the note in click and buttondown about implications of out-of-order commands.
- (AppiumMacHTTPJSONResponse *)post_buttonup:(NSString*)path data:(NSData *)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
if ([Utility isRunningInSandbox]) {
return [session mouseButtonActionInsideSandbox:@"buttonup" commandParams:commandParams statusCode:statusCode];
} else {
return [session mouseButtonActionOutsideSandbox:@"buttonup" commandParams:commandParams statusCode:statusCode];
}
}];
}
// POST /session/:sessionId/doubleclick
// Double-clicks at the current mouse coordinates (set by moveto).
- (AppiumMacHTTPJSONResponse *)post_doubleclick:(NSString*)path data:(NSData *)postData
{
return [self executeWebDriverCommandWithPath:path data:postData onMainThread:NO commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
if ([Utility isRunningInSandbox]) {
return [session mouseButtonActionInsideSandbox:@"doubleclick" commandParams:commandParams statusCode:statusCode];
} else {
return [session mouseButtonActionOutsideSandbox:@"doubleclick" commandParams:commandParams statusCode:statusCode];
}
}];
}
// POST /session/:sessionId/element/:id/scrollTo
// Scroll to the particular element passed to Appium. Scrolls till the bottom of the screen till the element becomes visible
// If the element is still not visible returns element not found
- (AppiumMacHTTPJSONResponse *)post_element_scrollTo:(NSString *)path data:(NSData *)postData
{
return [self executeWebDriverCommandWithPath:path data:nil onMainThread:YES commandBlock:^(AfMSessionController *session, NSDictionary *commandParams, int *statusCode)
{
id element = [commandParams objectForKey:@"elementObject"];
if ([session isElementDisplayed:element]) {
return [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId];
}
BOOL result = [session scrollPage:element];
return result ? [AppiumMacHTTPJSONResponse responseWithJson:nil status:kAfMStatusCodeSuccess session:session.sessionId] :
[AppiumMacHTTPJSONResponse responseWithJsonError:kAfMStatusCodeNoSuchElement session:session.sessionId];
}];
}
// POST /session/:sessionId/touch/click
// Single tap on the touch enabled device.
// POST /session/:sessionId/touch/down
// Finger down on the screen.
// POST /session/:sessionId/touch/up
// Finger up on the screen.
// POST /session/:sessionId/touch/move
// Finger move on the screen.
// POST /session/:sessionId/touch/scroll