forked from nightwatchjs/nightwatch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
appium.js
98 lines (79 loc) · 2.35 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
const {SeleniumServer, DriverService} = require('selenium-webdriver/remote');
const {getFreePort} = require('../../../utils');
const BaseService = require('./base-service.js');
class AppiumServer extends DriverService {
constructor(server_path, opt_options) {
const options = opt_options || {};
const {args} = options;
const port = options.port;
if (port !== AppiumServiceBuilder.defaultPort && !args.includes('--port')) {
args.unshift('--port', port);
}
let cmd = 'node';
if (server_path.startsWith('appium')) {
cmd = server_path;
} else {
args.unshift(server_path);
}
super(cmd, {
loopback: options.loopback,
port,
args,
path: '/wd/hub',
env: options.env,
stdio: options.stdio
});
}
}
class AppiumServiceBuilder extends BaseService {
static get serviceName() {
return 'Appium Server';
}
static get defaultPort() {
return 4723;
}
get npmPackageName() {
return 'appium';
}
get outputFile() {
return this._outputFile + '_appium-server.log';
}
get defaultPort() {
return AppiumServiceBuilder.defaultPort;
}
get serviceName() {
return 'Appium Server';
}
get downloadMessage() {
return 'install Appium globally with "npm i -g appium" command, \n and set ' +
'"selenium.server_path" config option to "appium".';
}
/**
* @param {Capabilities} opts
* @returns {Promise<void>}
*/
async createService(opts = {}) {
const {port} = this;
const options = new SeleniumServer.Options();
options.port = port || await getFreePort();
let {server_path, appium_version} = this.settings.webdriver;
const introMsg = `Starting Appium Server on port ${options.port}...`;
if (opts.showSpinner) {
opts.showSpinner(`${introMsg}\n\n`);
} else {
// eslint-disable-next-line
console.info(introMsg);
}
// TODO: read the log_path and add it to cliArgs
// above TODO is copied from ./selenium.js
options.args = this.cliArgs;
options.appium_version = appium_version;
if (this.hasSinkSupport() && this.needsSinkProcess()) {
this.createSinkProcess();
options.stdio = ['pipe', this.process.stdin, this.process.stdin];
}
this.service = new AppiumServer(server_path, options);
return this.service.start();
}
}
module.exports = AppiumServiceBuilder;