forked from appium/appium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.js
838 lines (750 loc) · 23.8 KB
/
parser.js
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
import fs from 'fs';
import path from 'path';
import _ from 'lodash';
import { ArgumentParser } from 'argparse';
import { rootDir } from './utils';
const args = [
[['--shell'], {
required: false,
defaultValue: null,
help: 'Enter REPL mode',
nargs: 0,
dest: 'shell',
}],
[['--reboot'], {
defaultValue: false,
dest: 'reboot',
action: 'storeTrue',
required: false,
help: '(Android-only) reboot emulator after each session and kill it at the end',
nargs: 0,
}],
[['--ipa'], {
required: false,
defaultValue: null,
help: '(IOS-only) abs path to compiled .ipa file',
example: '/abs/path/to/my.ipa',
dest: 'ipa',
}],
[['-a', '--address'], {
defaultValue: '0.0.0.0',
required: false,
example: '0.0.0.0',
help: 'IP Address to listen on',
dest: 'address',
}],
[['-p', '--port'], {
defaultValue: 4723,
required: false,
type: 'int',
example: '4723',
help: 'port to listen on',
dest: 'port',
}],
[['-ca', '--callback-address'], {
required: false,
dest: 'callbackAddress',
defaultValue: null,
example: '127.0.0.1',
help: 'callback IP Address (default: same as --address)',
}],
[['-cp', '--callback-port'], {
required: false,
dest: 'callbackPort',
defaultValue: null,
type: 'int',
example: '4723',
help: 'callback port (default: same as port)',
}],
[['-bp', '--bootstrap-port'], {
defaultValue: 4724,
dest: 'bootstrapPort',
required: false,
type: 'int',
example: '4724',
help: '(Android-only) port to use on device to talk to Appium',
}],
[['-r', '--backend-retries'], {
defaultValue: 3,
dest: 'backendRetries',
required: false,
type: 'int',
example: '3',
help: '(iOS-only) How many times to retry launching Instruments ' +
'before saying it crashed or timed out',
}],
[['--session-override'], {
defaultValue: false,
dest: 'sessionOverride',
action: 'storeTrue',
required: false,
help: 'Enables session override (clobbering)',
nargs: 0,
}],
[['-l', '--pre-launch'], {
defaultValue: false,
dest: 'launch',
action: 'storeTrue',
required: false,
help: 'Pre-launch the application before allowing the first session ' +
'(Requires --app and, for Android, --app-pkg and --app-activity)',
nargs: 0,
}],
[['-g', '--log'], {
defaultValue: null,
dest: 'log',
required: false,
example: '/path/to/appium.log',
help: 'Also send log output to this file',
}],
[['--log-level'], {
choices: [
'info', 'info:debug', 'info:info', 'info:warn', 'info:error',
'warn', 'warn:debug', 'warn:info', 'warn:warn', 'warn:error',
'error', 'error:debug', 'error:info', 'error:warn', 'error:error',
'debug', 'debug:debug', 'debug:info', 'debug:warn', 'debug:error',
],
defaultValue: 'debug',
dest: 'loglevel',
required: false,
example: 'debug',
help: 'log level; default (console[:file]): debug[:debug]',
}],
[['--log-timestamp'], {
defaultValue: false,
required: false,
help: 'Show timestamps in console output',
nargs: 0,
action: 'storeTrue',
dest: 'logTimestamp',
}],
[['--local-timezone'], {
defaultValue: false,
required: false,
help: 'Use local timezone for timestamps',
nargs: 0,
action: 'storeTrue',
dest: 'localTimezone',
}],
[['--log-no-colors'], {
defaultValue: false,
required: false,
help: 'Do not use colors in console output',
nargs: 0,
action: 'storeTrue',
dest: 'logNoColors',
}],
[['-G', '--webhook'], {
defaultValue: null,
required: false,
example: 'localhost:9876',
dest: 'webhook',
help: 'Also send log output to this HTTP listener',
}],
[['--safari'], {
defaultValue: false,
action: 'storeTrue',
dest: 'safari',
required: false,
help: '(IOS-Only) Use the safari app',
nargs: 0,
}],
[['--default-device', '-dd'], {
dest: 'defaultDevice',
defaultValue: false,
action: 'storeTrue',
required: false,
help: '(IOS-Simulator-only) use the default simulator that instruments ' +
'launches on its own',
}],
[['--force-iphone'], {
defaultValue: false,
dest: 'forceIphone',
action: 'storeTrue',
required: false,
help: '(IOS-only) Use the iPhone Simulator no matter what the app wants',
nargs: 0,
}],
[['--force-ipad'], {
defaultValue: false,
dest: 'forceIpad',
action: 'storeTrue',
required: false,
help: '(IOS-only) Use the iPad Simulator no matter what the app wants',
nargs: 0,
}],
[['--tracetemplate'], {
defaultValue: null,
dest: 'automationTraceTemplatePath',
required: false,
example: '/Users/me/Automation.tracetemplate',
help: '(IOS-only) .tracetemplate file to use with Instruments',
}],
[['--instruments'], {
defaultValue: null,
dest: 'instrumentsPath',
require: false,
example: '/path/to/instruments',
help: '(IOS-only) path to instruments binary',
}],
[['--nodeconfig'], {
required: false,
defaultValue: null,
dest: 'nodeconfig',
help: 'Configuration JSON file to register appium with selenium grid',
example: '/abs/path/to/nodeconfig.json',
}],
[['-ra', '--robot-address'], {
defaultValue: '0.0.0.0',
dest: 'robotAddress',
required: false,
example: '0.0.0.0',
help: 'IP Address of robot',
}],
[['-rp', '--robot-port'], {
defaultValue: -1,
dest: 'robotPort',
required: false,
type: 'int',
example: '4242',
help: 'port for robot',
}],
[['--selendroid-port'], {
defaultValue: 8080,
dest: 'selendroidPort',
required: false,
type: 'int',
example: '8080',
help: 'Local port used for communication with Selendroid',
}],
[['--chromedriver-port'], {
defaultValue: null,
dest: 'chromeDriverPort',
required: false,
type: 'int',
example: '9515',
help: 'Port upon which ChromeDriver will run. If not given, Android driver will pick a random available port.',
}],
[['--chromedriver-executable'], {
defaultValue: null,
dest: 'chromedriverExecutable',
required: false,
help: 'ChromeDriver executable full path',
}],
[['--show-config'], {
defaultValue: false,
dest: 'showConfig',
action: 'storeTrue',
required: false,
help: 'Show info about the appium server configuration and exit',
}],
[['--no-perms-check'], {
defaultValue: false,
dest: 'noPermsCheck',
action: 'storeTrue',
required: false,
help: 'Bypass Appium\'s checks to ensure we can read/write necessary files',
}],
[['--strict-caps'], {
defaultValue: false,
dest: 'enforceStrictCaps',
action: 'storeTrue',
required: false,
help: 'Cause sessions to fail if desired caps are sent in that Appium ' +
'does not recognize as valid for the selected device',
nargs: 0,
}],
[['--isolate-sim-device'], {
defaultValue: false,
dest: 'isolateSimDevice',
action: 'storeTrue',
required: false,
help: 'Xcode 6 has a bug on some platforms where a certain simulator ' +
'can only be launched without error if all other simulator devices ' +
'are first deleted. This option causes Appium to delete all ' +
'devices other than the one being used by Appium. Note that this ' +
'is a permanent deletion, and you are responsible for using simctl ' +
'or xcode to manage the categories of devices used with Appium.',
nargs: 0,
}],
[['--tmp'], {
defaultValue: null,
dest: 'tmpDir',
required: false,
help: 'Absolute path to directory Appium can use to manage temporary ' +
'files, like built-in iOS apps it needs to move around. On *nix/Mac ' +
'defaults to /tmp, on Windows defaults to C:\\Windows\\Temp',
}],
[['--trace-dir'], {
defaultValue: null,
dest: 'traceDir',
required: false,
help: 'Absolute path to directory Appium use to save ios instruments ' +
'traces, defaults to <tmp dir>/appium-instruments',
}],
[['--debug-log-spacing'], {
dest: 'debugLogSpacing',
defaultValue: false,
action: 'storeTrue',
required: false,
help: 'Add exaggerated spacing in logs to help with visual inspection',
}],
[['--suppress-adb-kill-server'], {
dest: 'suppressKillServer',
defaultValue: false,
action: 'storeTrue',
required: false,
help: '(Android-only) If set, prevents Appium from killing the adb server instance',
nargs: 0,
}],
[['--long-stacktrace'], {
dest: 'longStacktrace',
defaultValue: false,
required: false,
action: 'storeTrue',
help: 'Add long stack traces to log entries. Recommended for debugging only.',
}],
[['--webkit-debug-proxy-port'], {
defaultValue: 27753,
dest: 'webkitDebugProxyPort',
required: false,
type: 'int',
example: "27753",
help: '(IOS-only) Local port used for communication with ios-webkit-debug-proxy'
}],
[['--webdriveragent-port'], {
defaultValue: 8100,
dest: 'wdaLocalPort',
required: false,
type: 'int',
example: "8100",
help: '(IOS-only, XCUITest-only) Local port used for communication with WebDriverAgent'
}],
[['-dc', '--default-capabilities'], {
dest: 'defaultCapabilities',
defaultValue: {},
type: parseDefaultCaps,
required: false,
example: '[ \'{"app": "myapp.app", "deviceName": "iPhone Simulator"}\' ' +
'| /path/to/caps.json ]',
help: 'Set the default desired capabilities, which will be set on each ' +
'session unless overridden by received capabilities.'
}],
[['--enable-heapdump'], {
defaultValue: false,
dest: 'heapdumpEnabled',
action: 'storeTrue',
required: false,
help: 'Enable collection of NodeJS memory heap dumps. This is useful for memory leaks lookup',
nargs: 0
}],
[['--relaxed-security'], {
defaultValue: false,
dest: 'relaxedSecurityEnabled',
action: 'storeTrue',
required: false,
help: 'Disable additional security checks, so it is possible to use some advanced features, provided ' +
'by drivers supporting this option. Only enable it if all the ' +
'clients are in the trusted network and it\'s not the case if a client could potentially ' +
'break out of the session sandbox.',
nargs: 0
}],
];
const deprecatedArgs = [
[['--command-timeout'], {
defaultValue: 60,
dest: 'defaultCommandTimeout',
type: 'int',
required: false,
help: '[DEPRECATED] No effect. This used to be the default command ' +
'timeout for the server to use for all sessions (in seconds and ' +
'should be less than 2147483). Use newCommandTimeout cap instead'
}],
[['-k', '--keep-artifacts'], {
defaultValue: false,
dest: 'keepArtifacts',
action: 'storeTrue',
required: false,
help: '[DEPRECATED] - no effect, trace is now in tmp dir by default and is ' +
'cleared before each run. Please also refer to the --trace-dir flag.',
nargs: 0,
}],
[['--platform-name'], {
dest: 'platformName',
defaultValue: null,
required: false,
deprecatedFor: '--default-capabilities',
example: 'iOS',
help: '[DEPRECATED] - Name of the mobile platform: iOS, Android, or FirefoxOS',
}],
[['--platform-version'], {
dest: 'platformVersion',
defaultValue: null,
required: false,
deprecatedFor: '--default-capabilities',
example: '7.1',
help: '[DEPRECATED] - Version of the mobile platform',
}],
[['--automation-name'], {
dest: 'automationName',
defaultValue: null,
required: false,
deprecatedFor: '--default-capabilities',
example: 'Appium',
help: '[DEPRECATED] - Name of the automation tool: Appium or Selendroid',
}],
[['--device-name'], {
dest: 'deviceName',
defaultValue: null,
required: false,
deprecatedFor: '--default-capabilities',
example: 'iPhone Retina (4-inch), Android Emulator',
help: '[DEPRECATED] - Name of the mobile device to use',
}],
[['--browser-name'], {
dest: 'browserName',
defaultValue: null,
required: false,
deprecatedFor: '--default-capabilities',
example: 'Safari',
help: '[DEPRECATED] - Name of the mobile browser: Safari or Chrome',
}],
[['--app'], {
dest: 'app',
required: false,
defaultValue: null,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - IOS: abs path to simulator-compiled .app file or the bundle_id of the desired target on device; Android: abs path to .apk file',
example: '/abs/path/to/my.app',
}],
[['-lt', '--launch-timeout'], {
defaultValue: 90000,
dest: 'launchTimeout',
type: 'int',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (iOS-only) how long in ms to wait for Instruments to launch',
}],
[['--language'], {
defaultValue: null,
dest: 'language',
required: false,
example: 'en',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - Language for the iOS simulator / Android Emulator',
}],
[['--locale'], {
defaultValue: null,
dest: 'locale',
required: false,
example: 'en_US',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - Locale for the iOS simulator / Android Emulator',
}],
[['-U', '--udid'], {
dest: 'udid',
required: false,
defaultValue: null,
example: '1adsf-sdfas-asdf-123sdf',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - Unique device identifier of the connected physical device',
}],
[['--orientation'], {
dest: 'orientation',
defaultValue: null,
required: false,
example: 'LANDSCAPE',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (IOS-only) use LANDSCAPE or PORTRAIT to initialize all requests ' +
'to this orientation',
}],
[['--no-reset'], {
defaultValue: false,
dest: 'noReset',
action: 'storeTrue',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - Do not reset app state between sessions (IOS: do not delete app ' +
'plist files; Android: do not uninstall app before new session)',
nargs: 0,
}],
[['--full-reset'], {
defaultValue: false,
dest: 'fullReset',
action: 'storeTrue',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (iOS) Delete the entire simulator folder. (Android) Reset app ' +
'state by uninstalling app instead of clearing app data. On ' +
'Android, this will also remove the app after the session is complete.',
nargs: 0,
}],
[['--app-pkg'], {
dest: 'appPackage',
defaultValue: null,
required: false,
deprecatedFor: '--default-capabilities',
example: 'com.example.android.myApp',
help: '[DEPRECATED] - (Android-only) Java package of the Android app you want to run ' +
'(e.g., com.example.android.myApp)',
}],
[['--app-activity'], {
dest: 'appActivity',
defaultValue: null,
required: false,
example: 'MainActivity',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Activity name for the Android activity you want ' +
'to launch from your package (e.g., MainActivity)',
}],
[['--app-wait-package'], {
dest: 'appWaitPackage',
defaultValue: false,
required: false,
example: 'com.example.android.myApp',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Package name for the Android activity you want ' +
'to wait for (e.g., com.example.android.myApp)',
}],
[['--app-wait-activity'], {
dest: 'appWaitActivity',
defaultValue: false,
required: false,
example: 'SplashActivity',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Activity name for the Android activity you want ' +
'to wait for (e.g., SplashActivity)',
}],
[['--device-ready-timeout'], {
dest: 'deviceReadyTimeout',
defaultValue: 5,
required: false,
type: 'int',
example: '5',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Timeout in seconds while waiting for device to become ready',
}],
[['--android-coverage'], {
dest: 'androidCoverage',
defaultValue: false,
required: false,
example: 'com.my.Pkg/com.my.Pkg.instrumentation.MyInstrumentation',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Fully qualified instrumentation class. Passed to -w in ' +
'adb shell am instrument -e coverage true -w ',
}],
[['--avd'], {
dest: 'avd',
defaultValue: null,
required: false,
example: '@default',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Name of the avd to launch',
}],
[['--avd-args'], {
dest: 'avdArgs',
defaultValue: null,
required: false,
example: '-no-snapshot-load',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Additional emulator arguments to launch the avd',
}],
[['--use-keystore'], {
defaultValue: false,
dest: 'useKeystore',
action: 'storeTrue',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) When set the keystore will be used to sign apks.',
}],
[['--keystore-path'], {
defaultValue: path.resolve(process.env.HOME || process.env.USERPROFILE || '', '.android', 'debug.keystore'),
dest: 'keystorePath',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Path to keystore',
}],
[['--keystore-password'], {
defaultValue: 'android',
dest: 'keystorePassword',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Password to keystore',
}],
[['--key-alias'], {
defaultValue: 'androiddebugkey',
dest: 'keyAlias',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Key alias',
}],
[['--key-password'], {
defaultValue: 'android',
dest: 'keyPassword',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Key password',
}],
[['--intent-action'], {
dest: 'intentAction',
defaultValue: 'android.intent.action.MAIN',
required: false,
example: 'android.intent.action.MAIN',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Intent action which will be used to start activity',
}],
[['--intent-category'], {
dest: 'intentCategory',
defaultValue: 'android.intent.category.LAUNCHER',
required: false,
example: 'android.intent.category.APP_CONTACTS',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Intent category which will be used to start activity',
}],
[['--intent-flags'], {
dest: 'intentFlags',
defaultValue: '0x10200000',
required: false,
example: '0x10200000',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Flags that will be used to start activity',
}],
[['--intent-args'], {
dest: 'optionalIntentArguments',
defaultValue: null,
required: false,
example: '0x10200000',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) Additional intent arguments that will be used to ' +
'start activity',
}],
[['--dont-stop-app-on-reset'], {
dest: 'dontStopAppOnReset',
defaultValue: false,
action: 'storeTrue',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (Android-only) When included, refrains from stopping the app before restart',
}],
[['--calendar-format'], {
defaultValue: null,
dest: 'calendarFormat',
required: false,
example: 'gregorian',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (IOS-only) calendar format for the iOS simulator',
}],
[['--native-instruments-lib'], {
defaultValue: false,
dest: 'nativeInstrumentsLib',
action: 'storeTrue',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (IOS-only) IOS has a weird built-in unavoidable ' +
'delay. We patch this in appium. If you do not want it patched, ' +
'pass in this flag.',
nargs: 0,
}],
[['--keep-keychains'], {
defaultValue: false,
dest: 'keepKeyChains',
action: 'storeTrue',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (iOS-only) Whether to keep keychains (Library/Keychains) when reset app between sessions',
nargs: 0,
}],
[['--localizable-strings-dir'], {
required: false,
dest: 'localizableStringsDir',
defaultValue: 'en.lproj',
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (IOS-only) the relative path of the dir where Localizable.strings file resides ',
example: 'en.lproj',
}],
[['--show-ios-log'], {
defaultValue: false,
dest: 'showIOSLog',
action: 'storeTrue',
required: false,
deprecatedFor: '--default-capabilities',
help: '[DEPRECATED] - (IOS-only) if set, the iOS system log will be written to the console',
nargs: 0,
}],
[['--async-trace'], {
dest: 'longStacktrace',
defaultValue: false,
required: false,
action: 'storeTrue',
deprecatedFor: '--long-stacktrace',
help: '[DEPRECATED] - Add long stack traces to log entries. Recommended for debugging only.',
}],
];
function updateParseArgsForDefaultCapabilities (parser) {
// here we want to update the parser.parseArgs() function
// in order to bring together all the args that are actually
// default caps.
// once those deprecated args are actually removed, this
// can also be removed
parser._parseArgs = parser.parseArgs;
parser.parseArgs = function (args) {
let parsedArgs = parser._parseArgs(args);
parsedArgs.defaultCapabilities = parsedArgs.defaultCapabilities || {};
for (let argEntry of deprecatedArgs) {
let arg = argEntry[1].dest;
if (argEntry[1].deprecatedFor === '--default-capabilities') {
if (arg in parsedArgs && parsedArgs[arg] !== argEntry[1].defaultValue) {
parsedArgs.defaultCapabilities[arg] = parsedArgs[arg];
// j s h i n t can't handle complex interpolated strings
let capDict = {[arg]: parsedArgs[arg]};
argEntry[1].deprecatedFor = `--default-capabilities ` +
`'${JSON.stringify(capDict)}'`;
}
}
}
return parsedArgs;
};
}
function parseDefaultCaps (caps) {
try {
// use synchronous file access, as `argparse` provides no way of either
// awaiting or using callbacks. This step happens in startup, in what is
// effectively command-line code, so nothing is blocked in terms of
// sessions, so holding up the event loop does not incur the usual
// drawbacks.
if (fs.statSync(caps).isFile()) {
caps = fs.readFileSync(caps, 'utf8');
}
} catch (err) {
// not a file, or not readable
}
caps = JSON.parse(caps);
if (!_.isPlainObject(caps)) {
throw 'Invalid format for default capabilities';
}
return caps;
}
function getParser () {
let parser = new ArgumentParser({
version: require(path.resolve(rootDir, 'package.json')).version,
addHelp: true,
description: 'A webdriver-compatible server for use with native and hybrid iOS and Android applications.',
prog: process.argv[1] || 'Appium'
});
let allArgs = _.union(args, deprecatedArgs);
parser.rawArgs = allArgs;
for (let arg of allArgs) {
parser.addArgument(arg[0], arg[1]);
}
updateParseArgsForDefaultCapabilities(parser);
return parser;
}
function getDefaultArgs () {
let defaults = {};
for (let [, arg] of args) {
defaults[arg.dest] = arg.defaultValue;
}
return defaults;
}
export default getParser;
export { getDefaultArgs, getParser };