This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
startActivity.js
82 lines (67 loc) · 2.25 KB
/
startActivity.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
import util from "util";
import BaseCommand from "../../base-mobile-command";
import settings from "../../settings";
const MAX_TIMEOUT = settings.COMMAND_MAX_TIMEOUT;
const WAIT_INTERVAL = settings.WAIT_INTERVAL;
const StartActivity = function (nightwatch = null) {
BaseCommand.call(this, nightwatch);
this.cmd = "startactivity";
};
util.inherits(StartActivity, BaseCommand);
StartActivity.prototype.do = function (value) {
this.pass({ actual: value });
};
/* eslint-disable no-magic-numbers */
StartActivity.prototype.checkConditions = function () {
const self = this;
const options = {
path: `/session/${this.client.sessionId}/appium/device/start_activity`,
method: "POST",
data: this.app
};
self.protocol(options, (result) => {
if (result.status === 0) {
// sucessful
self.seenCount += 1;
} else if (result.status === -1 &&
result.errorStatus === 13) {
// method not implement, fail immediately
self.fail({
code: settings.FAILURE_REASONS.BUILTIN_COMMAND_NOT_SUPPORTED,
message: self.failureMessage
});
}
const elapsed = (new Date()).getTime() - self.startTime;
if (self.seenCount >= 1 || elapsed > MAX_TIMEOUT) {
if (self.seenCount >= 1) {
const elapse = (new Date()).getTime();
self.time.executeAsyncTime = elapse - self.startTime;
self.time.seleniumCallTime = 0;
self.do(result.value);
} else {
self.fail({
code: settings.FAILURE_REASONS.BUILTIN_COMMAND_TIMEOUT,
message: self.failureMessage
});
}
} else {
setTimeout(self.checkConditions, WAIT_INTERVAL);
}
});
};
StartActivity.prototype.command = function (app, cb) {
this.app = app;
this.appPackage = app.appPackage;
this.appActivity = app.appActivity;
this.cb = cb;
this.successMessage = `Activity ${this.appPackage}.${this.appActivity}`
+ " was started after %d milliseconds";
this.failureMessage = `Activity ${this.appPackage}.${this.appActivity}`
+ " wasn't started after %d milliseconds";
this.startTime = (new Date()).getTime();
// Track how many times selector is successfully checked by /element protocol
this.seenCount = 0;
this.checkConditions();
return this;
};
module.exports = StartActivity;