forked from appium/appium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappium.js
734 lines (676 loc) · 23.1 KB
/
appium.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
// Appium webserver controller methods
// https://github.com/hugs/appium/blob/master/appium/appium.py
"use strict";
var routing = require('./server/routing.js')
, loggerjs = require('./server/logger.js')
, logger = loggerjs.get('appium')
, helpers = require('./helpers.js')
, downloadFile = helpers.downloadFile
, unzipApp = helpers.unzipApp
, checkSafari = helpers.checkSafari
, cleanSafari = helpers.cleanSafari
, copyLocalZip = helpers.copyLocalZip
, UUID = require('uuid-js')
, _ = require('underscore')
, fs = require('fs')
, ios = require('./devices/ios/ios.js')
, android = require('./devices/android/android.js')
, selendroid = require('./devices/android/selendroid.js')
, chrome = require('./devices/android/chrome.js')
, firefoxOs = require('./devices/firefoxos/firefoxos.js')
, status = require("./server/status.js")
, helpers = require('./helpers.js')
, isWindows = helpers.isWindows();
var Appium = function(args) {
this.args = args;
this.serverArgs = _.clone(args);
this.rest = null;
this.webSocket = null;
this.deviceType = null;
this.device = null;
this.sessionId = null;
this.desiredCapabilities = {};
this.session = null;
this.tempFiles = [];
this.preLaunched = false;
this.fastReset = !this.args.fullReset && !this.args.noReset;
this.sessionOverride = this.args.sessionOverride;
this.resetting = false;
this.defCommandTimeoutMs = 60 * 1000;
this.commandTimeoutMs = this.defCommandTimeoutMs;
this.origCommandTimeoutMs = this.commandTimeoutMs;
this.commandTimeout = null;
this.isSafariLauncherApp = false;
};
Appium.prototype.attachTo = function(rest, cb) {
this.rest = rest;
// Import the routing rules
routing(this);
if (cb) {
cb();
}
};
Appium.prototype.attachSocket = function(webSocket, cb) {
this.webSocket = webSocket;
if (cb) {
cb();
}
};
Appium.prototype.registerConfig = function(configObj) {
this.serverConfig = configObj;
};
Appium.prototype.preLaunch = function(cb) {
logger.info("Pre-launching app");
var caps = {};
this.start(caps, function(err) {
if (err) {
cb(err, null);
} else {
this.preLaunched = true;
cb(null, this);
}
}.bind(this));
};
Appium.prototype.start = function(desiredCaps, cb) {
this.desiredCapabilities = desiredCaps;
this.configure(desiredCaps, function(err) {
if (err) {
logger.info("Got configuration error, not starting session");
this.cleanupSession();
cb(err, null);
} else {
this.invoke(cb);
}
}.bind(this));
};
Appium.prototype.getDeviceType = function(desiredCaps) {
// yay for HACKS!!
if (desiredCaps.device) {
if (desiredCaps.device.toLowerCase().indexOf('iphone') !== -1) {
return "ios";
} else if (desiredCaps.device.toLowerCase().indexOf('ipad') !== -1) {
return "ios";
} else if (desiredCaps.device.toLowerCase().indexOf('selendroid') !== -1) {
return "selendroid";
} else if (desiredCaps.device.toLowerCase().indexOf('firefox') !== -1) {
return "firefoxos";
} else if (desiredCaps.device === "mock_ios") {
return "mock_ios";
} else {
return "android";
}
} else if (desiredCaps.app) {
if (desiredCaps.app.toLowerCase() === "safari") {
return "ios";
} else if (desiredCaps.app.toLowerCase() === "chrome") {
return "android";
} else if (desiredCaps.app.toLowerCase() === "chromium") {
return "android";
}
} else if (desiredCaps.browserName) {
logger.warn("WARNING: use of browserName is deprecated. Please migrate " +
"your tests");
if (desiredCaps.browserName[0].toLowerCase() === "i") {
return "ios";
} else if (desiredCaps.browserName.toLowerCase() === "safari") {
return "ios";
} else if (desiredCaps.browserName.toLowerCase() === "chrome") {
return "android";
} else if (desiredCaps.browserName.toLowerCase() === "chromium") {
return "android";
} else if (desiredCaps.browserName.toLowerCase().indexOf('selendroid') !== -1) {
return "selendroid";
} else {
return "android";
}
} else if (desiredCaps["app-package"] || this.args.androidPackage) {
return "android";
} else if (desiredCaps["app-activity"] || this.args.androidActivity) {
return "android";
}
return "ios";
};
Appium.prototype.getIosDeviceType = function(desiredCaps) {
if (this.args.forceIphone) {
return "iphone";
} else if (this.args.forceIpad) {
return "ipad";
} else {
var device = desiredCaps.device;
if (typeof device !== "undefined" && device.toLowerCase().indexOf("ipad") !== -1) {
return "ipad";
}
}
return "iphone";
};
Appium.prototype.isMockIos = function() {
return this.deviceType === "mock_ios";
};
Appium.prototype.isIos = function() {
return this.deviceType === "ios";
};
Appium.prototype.isAndroid = function() {
return this.deviceType === "android";
};
Appium.prototype.isChrome = function() {
return this.args.app === "chrome" ||
this.args.androidPackage === "com.android.chrome" ||
this.args.app === "chromium" ||
this.args.androidPackage === "org.chromium.chrome.testshell";
};
Appium.prototype.isSelendroid = function() {
return this.deviceType === "selendroid";
};
Appium.prototype.isFirefoxOS = function() {
return this.deviceType === "firefoxos";
};
Appium.prototype.getAppExt = function() {
return this.isIos() ? ".app" : ".apk";
};
Appium.prototype.setAndroidArgs = function(desiredCaps) {
var setArgFromCaps = function(arg, cap) {
this.args[arg] = desiredCaps[cap] || this.args[arg];
}.bind(this);
setArgFromCaps("androidPackage", "app-package");
setArgFromCaps("androidActivity", "app-activity");
setArgFromCaps("androidWaitActivity", "app-wait-activity");
setArgFromCaps("androidDeviceReadyTimeout", "device-ready-timeout");
setArgFromCaps("compressXml", "compressXml");
};
Appium.prototype.configure = function(desiredCaps, cb) {
var hasAppInCaps = (typeof desiredCaps !== "undefined" &&
typeof desiredCaps.app !== "undefined" &&
desiredCaps.app);
this.deviceType = this.getDeviceType(desiredCaps);
if (this.isMockIos()) {
return cb();
}
if (this.isIos()) {
this.iosDeviceType = this.getIosDeviceType(desiredCaps);
}
if (!_.has(this.serverConfig, this.deviceType)) {
logger.error("Trying to run a session for device " + this.deviceType + " " +
"but that device hasn't been configured. Run config");
return cb(new Error("Device " + this.deviceType + " not configured yet"));
}
if (this.isAndroid() || this.isSelendroid()) {
this.setAndroidArgs(desiredCaps);
if (!this.args.androidActivity) {
return cb(new Error("You need to pass in the app-activity desired " +
"capability or server param"));
}
if (!this.args.androidPackage) {
return cb(new Error("You need to pass in the app-package desired " +
"capability or server param"));
}
}
if (hasAppInCaps || this.args.app) {
this.configureApp(desiredCaps, hasAppInCaps, cb);
} else if (this.isAndroid() && this.args.androidPackage) {
this.args.app = null;
logger.info("Didn't get app but did get Android package, will attempt to " +
"launch it on the device");
cb(null);
} else if (this.args.safari === true) {
this.configureSafari(desiredCaps, cb);
} else {
cb("No app set; either start appium with --app or pass in an 'app' " +
"value in desired capabilities");
}
};
Appium.prototype.configureApp = function(desiredCaps, hasAppInCaps, cb) {
var appPath = (hasAppInCaps ? desiredCaps.app : this.args.app)
, isPackageOrBundle = /^([a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+)+$/.test(appPath)
, origin = (hasAppInCaps ? "desiredCaps" : "command line");
if (appPath[0] === "/" || (isWindows && appPath!== null && appPath.length > 2 && appPath[1] === ":" && appPath[2] === "\\") ) {
this.configureLocalApp(appPath, origin, cb);
} else if (appPath.substring(0, 4) === "http") {
this.configureDownloadedApp(appPath, origin, cb);
} else if (this.isIos() && appPath.toLowerCase() === "safari") {
if (this.args.udid) {
this.desiredCapabilities.safari = true;
this.isSafariLauncherApp = true;
this.configureLocalApp("./build/SafariLauncher/SafariLauncher.zip", origin, cb);
} else {
if (parseFloat(this.desiredCapabilities.version) >= 7) {
this.configureSafariForLauncher(desiredCaps, function() {
this.isSafariLauncherApp = true;
this.configureLocalApp("./build/SafariLauncher/SafariLauncherSim.zip", origin, cb);
}.bind(this));
} else {
this.configureSafari(desiredCaps, cb);
}
}
} else if (this.isIos() && isPackageOrBundle) {
// we have a bundle ID
logger.info("App is an iOS bundle, will attempt to run as pre-existing");
this.args.bundleId = appPath;
this.args.app = null;
cb(null);
} else if (this.isAndroid() && isPackageOrBundle) {
// we have a package instead of app
this.args.androidPackage = appPath;
this.args.app = null;
logger.info("App is an Android package, will attempt to run on device");
cb(null);
} else if (_.contains(["chrome", "chromium"], appPath.toLowerCase())) {
logger.info("Looks like we want chrome on android");
if (appPath.toLowerCase() === "chromium") {
this.args.chromium = true;
} else {
this.args.chromium = false;
}
this.configureChromeAndroid();
cb(null);
} else if (this.isFirefoxOS()) {
this.args.app = desiredCaps.app;
cb(null);
} else {
cb("Bad app passed in through " + origin + ": " + appPath +
". Apps need to be absolute local path or URL to zip file");
}
};
Appium.prototype.configureLocalApp = function(appPath, origin, cb) {
var ext = appPath.substring(appPath.length - 4);
if (ext === this.getAppExt()) {
this.args.app = appPath;
logger.info("Using local app from " + origin + ": " + appPath);
fs.stat(appPath, function(err) {
if (err) {
return cb(new Error("Error locating the app: " + err.message));
}
cb();
});
} else if (ext === ".zip" || ext === ".ipa") {
logger.info("Using local zip or ipa from " + origin + ": " + appPath);
this.unzipLocalApp(appPath, function(zipErr, newAppPath) {
if (zipErr) return cb(zipErr);
this.args.app = newAppPath;
logger.info("Using locally extracted app: " + this.args.app);
cb(null);
}.bind(this));
} else {
var dExt = this.getAppExt();
logger.error("Using local app, but didn't end in .zip, .ipa or " + dExt);
cb("Your app didn't end in .zip, .ipa or " + dExt);
}
};
Appium.prototype.configureDownloadedApp = function(appPath, origin, cb) {
var appUrl = appPath;
if (appUrl.substring(appUrl.length - 4) === ".apk") {
try {
downloadFile(appUrl, function(appPath) {
this.tempFiles.push(appPath);
cb(null, appPath);
}.bind(this));
} catch (e) {
var err = e.toString();
logger.error("Failed downloading app from appUrl " + appUrl);
cb(err);
}
} else if (appUrl.substring(appUrl.length - 4) === ".zip") {
try {
this.downloadAndUnzipApp(appUrl, function(zipErr, appPath) {
if (zipErr) {
cb(zipErr);
} else {
this.args.app = appPath;
logger.info("Using extracted app: " + this.args.app);
cb(null);
}
}.bind(this));
logger.info("Using downloadable app from " + origin + ": " + appUrl);
} catch (e) {
var err = e.toString();
logger.error("Failed downloading app from appUrl " + appUrl);
cb(err);
}
} else {
cb("App URL (" + appUrl + ") didn't seem to end in .zip");
}
};
Appium.prototype.configureSafari = function(desiredCaps, cb) {
this.desiredCapabilities.safari = true;
var safariVer = "6.1";
var usingDefaultVer = true;
if (typeof desiredCaps.version !== "undefined") {
safariVer = desiredCaps.version;
usingDefaultVer = false;
}
logger.info("Trying to use mobile safari, version " + safariVer);
var checkSuccess = function(attemptedApp) {
logger.info("Using mobile safari app at " + attemptedApp);
this.args.app = attemptedApp;
cleanSafariNext();
}.bind(this);
var cleanSafariNext = function() {
logger.info("Cleaning mobile safari data files");
cleanSafari(safariVer, function(err) {
if (err) {
logger.error(err.message);
cb(err);
} else {
cb(null);
}
});
};
checkSafari(safariVer, function(err, attemptedApp) {
if (err) {
logger.warn("Could not find mobile safari with version '" + safariVer +
"': " + err);
if (usingDefaultVer) {
safariVer = "6.1";
logger.info("Retrying with safari ver " + safariVer);
checkSafari(safariVer, function(err, attemptedApp) {
if (err) {
logger.warn("Could not find this one either: " + err);
cb(err);
} else {
checkSuccess(attemptedApp);
}
}.bind(this));
} else {
cb(err);
}
} else {
checkSuccess(attemptedApp);
}
}.bind(this));
};
Appium.prototype.configureSafariForLauncher = function (desiredCaps, cb) {
this.desiredCapabilities.safari = true;
var safariVer = "6.1";
var usingDefaultVer = true;
if (typeof desiredCaps.version !== "undefined") {
safariVer = desiredCaps.version;
usingDefaultVer = false;
}
cleanSafari(safariVer, function(err) {
if (err) {
logger.error(err.message);
cb(err);
} else {
cb(null);
}
});
};
Appium.prototype.configureChromeAndroid = function() {
this.deviceType = "android";
this.args.androidPackage = "com.android.chrome";
this.args.androidActivity = "com.google.android.apps.chrome.Main";
this.args.app = null;
};
Appium.prototype.downloadAndUnzipApp = function(appUrl, cb) {
downloadFile(appUrl, function(zipPath) {
this.unzipApp(zipPath, cb);
}.bind(this));
};
Appium.prototype.unzipLocalApp = function(localZipPath, cb) {
try {
copyLocalZip(localZipPath, function(err, zipPath) {
if (err) return cb(err);
this.unzipApp(zipPath, cb);
}.bind(this));
} catch (e) {
logger.error("Failed copying and unzipping local app: " + localZipPath);
cb(e);
}
};
Appium.prototype.unzipApp = function(zipPath, cb) {
this.tempFiles.push(zipPath);
unzipApp(zipPath, this.getAppExt(), function(err, appPath) {
if (err) {
cb(err, null);
} else {
this.tempFiles.push(appPath);
cb(null, appPath);
}
}.bind(this));
};
Appium.prototype.invoke = function(cb) {
if (this.sessionOverride || this.sessionId === null) {
this.sessionId = UUID.create().hex;
logger.info('Creating new appium session ' + this.sessionId);
if (this.device === null || this.sessionOverride) {
this.initDevice();
}
if (_.has(this.desiredCapabilities, 'launch') &&
this.desiredCapabilities.launch === false) {
// if user has passed in desiredCaps.launch = false
// meaning they will manage app install / launching
cb(null, this.device);
} else {
// the normal case, where we launch the device for folks
var onStart = function(err, sessionIdOverride) {
if (sessionIdOverride) {
this.sessionId = sessionIdOverride;
logger.info("Overriding session id with " + sessionIdOverride);
}
if (err) return this.cleanupSession(err, cb);
logger.info("Device launched! Ready for commands (will time out in " +
(this.commandTimeoutMs / 1000) + "secs)");
this.resetTimeout();
cb(null, this.device);
}.bind(this);
var onDie = function() {
// if we're using the safari launcher app, don't end the session when
// instruments inevitably crashes out
if (!this.isSafariLauncherApp) {
this.cleanupSession();
}
}.bind(this);
this.device.start(onStart, onDie);
}
} else {
return cb(new Error("Requested a new session but one was in progress"));
}
};
Appium.prototype.initDevice = function() {
if (this.isMockIos()) {
var device = ios({rest: this.rest});
device.start = function(cb) { cb(); };
device.stop = function(cb) { cb(); };
this.device = device;
} else if (this.isIos()) {
var iosOpts = {
rest: this.rest
, webSocket: this.webSocket
, app: this.args.app
, ipa: this.args.ipa
, bundleId: this.args.bundleId
, udid: this.args.udid
, verbose: !this.args.quiet
, automationTraceTemplatePath: this.args.automationTraceTemplatePath
, removeTraceDir: !this.args.keepArtifacts
, withoutDelay: !this.args.nativeInstrumentsLib
, reset: !this.args.noReset
, autoWebview: this.desiredCapabilities.safari
, launchTimeout: this.desiredCapabilities.launchTimeout
, version: this.desiredCapabilities.version
, deviceType: this.iosDeviceType
, language: this.desiredCapabilities.language || this.args.language
, locale: this.desiredCapabilities.locale || this.args.locale
, calendarFormat: this.desiredCapabilities.calendarFormat || this.args.calendarFormat
, startingOrientation: this.desiredCapabilities.deviceOrientation || this.args.orientation
, robotPort: this.args.robotPort
, robotAddress: this.args.robotAddress
, isSafariLauncherApp: this.isSafariLauncherApp
, desiredCapabilities: this.desiredCapabilities
};
this.device = ios(iosOpts);
} else if (this.isAndroid()) {
var androidOpts = {
rest: this.rest
, webSocket: this.webSocket
, apkPath: this.args.app
, verbose: !this.args.quiet
, udid: this.args.udid
, appPackage: this.args.androidPackage
, appActivity: this.args.androidActivity
, appWaitActivity: this.args.androidWaitActivity
, compressXml: this.args.compressXml
, avdName: this.args.avd
, appDeviceReadyTimeout: this.args.androidDeviceReadyTimeout
, reset: !this.args.noReset
, fastReset: this.fastReset
, useKeystore: this.args.useKeystore
, keystorePath: this.args.keystorePath
, keystorePassword: this.args.keystorePassword
, keyAlias: this.args.keyAlias
, keyPassword: this.args.keyPassword
, systemPort: this.args.devicePort
, desiredCapabilities: this.desiredCapabilities
};
if (this.isChrome()) {
androidOpts.chromium = this.args.chromium;
this.device = chrome(androidOpts);
} else {
this.device = android(androidOpts);
}
} else if (this.isSelendroid()) {
var selendroidOpts = {
apkPath: this.args.app
, desiredCaps: this.desiredCapabilities
, verbose: !this.args.quiet
, udid: this.args.udid
, appPackage: this.args.androidPackage
, appActivity: this.args.androidActivity
, appWaitActivity: this.args.androidWaitActivity
, avdName: this.args.avd
, appDeviceReadyTimeout: this.args.androidDeviceReadyTimeout
, reset: !this.args.noReset
, systemPort: this.args.selendroidPort
, fastReset: this.fastReset
, useKeystore: this.args.useKeystore
, keystorePath: this.args.keystorePath
, keystorePassword: this.args.keystorePassword
, keyAlias: this.args.keyAlias
, keyPassword: this.args.keyPassword
};
this.device = selendroid(selendroidOpts);
} else if (this.isFirefoxOS()) {
var firefoxOpts = {
app: this.args.app
, desiredCaps: this.desiredCapabilities
, verbose: !this.args.quiet
};
this.device = firefoxOs(firefoxOpts);
} else {
throw new Error("Tried to start a device that doesn't exist: " +
this.deviceType);
}
};
Appium.prototype.timeoutWaitingForCommand = function() {
logger.info("Didn't get a new command in " + (this.commandTimeoutMs / 1000) +
" secs, shutting down...");
this.stop(function() {
logger.info("We shut down because no new commands came in");
}.bind(this));
};
Appium.prototype.cleanupSession = function(err, cb) {
logger.info("Cleaning up appium session");
if (this.commandTimeout) {
clearTimeout(this.commandTimeout);
}
this.commandTimeoutMs = this.defCommandTimeoutMs;
var dyingSession = this.sessionId;
this.sessionId = null;
this.device = null;
this.args = _.clone(this.serverArgs);
this.desiredCapabilities = {};
if (cb) {
if (err) return cb(err);
cb(null, {status: status.codes.Success.code, value: null,
sessionId: dyingSession});
}
};
Appium.prototype.resetTimeout = function() {
if (this.commandTimeout) {
clearTimeout(this.commandTimeout);
}
this.commandTimeout = setTimeout(this.timeoutWaitingForCommand.bind(this),
this.commandTimeoutMs);
};
Appium.prototype.setCommandTimeout = function(secs, cb) {
logger.info("Setting command timeout to " + secs + " secs");
this.origCommandTimeoutMs = this.commandTimeoutMs;
this.commandTimeoutMs = secs * 1000;
this.resetTimeout();
cb(null, {
status: status.codes.Success.code
, value: secs
});
};
Appium.prototype.resetCommandTimeout = function(cb) {
this.commandTimeoutMs = this.origCommandTimeoutMs;
this.resetTimeout();
cb(null, {
status: status.codes.Success.code
, value: ''
});
};
Appium.prototype.getCommandTimeout = function(cb) {
cb(null, {
status: status.codes.Success.code
, value: this.commandTimeoutMs / 1000
});
};
Appium.prototype.stop = function(cb) {
if (this.sessionId === null || this.device === null) {
logger.info("Trying to stop appium but there's no session, doing nothing");
return cb();
}
logger.info('Shutting down appium session...');
if (this.isSafariLauncherApp === true) {
this.device.leaveWebView(function() {
if (this.device.udid === null && this.device.instruments !== null) {
this.device.instruments.shutdown(function() {
this.cleanupSession(null, cb);
}.bind(this));
} else {
this.cleanupSession(null, cb);
}
}.bind(this));
} else {
this.device.stop(function(code) {
var err;
if (code && code > 0) {
err = new Error("Device exited with code: " + code);
}
this.cleanupSession(err, cb);
}.bind(this));
}
};
Appium.prototype.reset = function(cb) {
logger.info("Resetting app mid-session");
if ((this.isIos() && !this.device.instruments.udid) || !this.fastReset) {
var oldImpWait = this.device.implicitWaitMs
, oldId = this.sessionId;
this.resetting = true;
this.stop(function() {
logger.info("Restarting app");
this.start(this.desiredCapabilities, function() {
this.resetting = false;
this.device.implicitWaitMs = oldImpWait;
this.sessionId = oldId;
cb(null, {status: status.codes.Success.code, value: null});
}.bind(this));
}.bind(this));
} else { // Android fast reset
if (this.isIos()) { // physical iOS
cb(null, {status: status.codes.Success.code, value: null});
} else {
logger.info("Android fast reset");
this.device.fastReset(function(err){
if (err) {
cb(null, {status: status.codes.UnknownError.code, value: null});
} else {
cb(null, {status: status.codes.Success.code, value: null});
}
});
}
}
};
module.exports = function(args) {
return new Appium(args);
};