appium 2.0.0-beta.5 → 2.0.0-beta.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -63
- package/build/lib/appium.d.ts +226 -0
- package/build/lib/appium.d.ts.map +1 -0
- package/build/lib/appium.js +694 -439
- package/build/lib/appium.js.map +1 -0
- package/build/lib/cli/args.d.ts +17 -0
- package/build/lib/cli/args.d.ts.map +1 -0
- package/build/lib/cli/args.js +253 -319
- package/build/lib/cli/args.js.map +1 -0
- package/build/lib/cli/driver-command.d.ts +102 -0
- package/build/lib/cli/driver-command.d.ts.map +1 -0
- package/build/lib/cli/driver-command.js +126 -81
- package/build/lib/cli/driver-command.js.map +1 -0
- package/build/lib/cli/extension-command.d.ts +385 -0
- package/build/lib/cli/extension-command.d.ts.map +1 -0
- package/build/lib/cli/extension-command.js +731 -383
- package/build/lib/cli/extension-command.js.map +1 -0
- package/build/lib/cli/extension.d.ts +23 -0
- package/build/lib/cli/extension.d.ts.map +1 -0
- package/build/lib/cli/extension.js +71 -54
- package/build/lib/cli/extension.js.map +1 -0
- package/build/lib/cli/parser.d.ts +84 -0
- package/build/lib/cli/parser.d.ts.map +1 -0
- package/build/lib/cli/parser.js +240 -128
- package/build/lib/cli/parser.js.map +1 -0
- package/build/lib/cli/plugin-command.d.ts +99 -0
- package/build/lib/cli/plugin-command.d.ts.map +1 -0
- package/build/lib/cli/plugin-command.js +120 -81
- package/build/lib/cli/plugin-command.js.map +1 -0
- package/build/lib/cli/utils.d.ts +29 -0
- package/build/lib/cli/utils.d.ts.map +1 -0
- package/build/lib/cli/utils.js +72 -51
- package/build/lib/cli/utils.js.map +1 -0
- package/build/lib/config-file.d.ts +100 -0
- package/build/lib/config-file.d.ts.map +1 -0
- package/build/lib/config-file.js +207 -0
- package/build/lib/config-file.js.map +1 -0
- package/build/lib/config.d.ts +49 -0
- package/build/lib/config.d.ts.map +1 -0
- package/build/lib/config.js +265 -201
- package/build/lib/config.js.map +1 -0
- package/build/lib/constants.d.ts +49 -0
- package/build/lib/constants.d.ts.map +1 -0
- package/build/lib/constants.js +66 -0
- package/build/lib/constants.js.map +1 -0
- package/build/lib/extension/driver-config.d.ts +82 -0
- package/build/lib/extension/driver-config.d.ts.map +1 -0
- package/build/lib/extension/driver-config.js +212 -0
- package/build/lib/extension/driver-config.js.map +1 -0
- package/build/lib/extension/extension-config.d.ts +249 -0
- package/build/lib/extension/extension-config.d.ts.map +1 -0
- package/build/lib/extension/extension-config.js +581 -0
- package/build/lib/extension/extension-config.js.map +1 -0
- package/build/lib/extension/index.d.ts +48 -0
- package/build/lib/extension/index.d.ts.map +1 -0
- package/build/lib/extension/index.js +105 -0
- package/build/lib/extension/index.js.map +1 -0
- package/build/lib/extension/manifest-migrations.d.ts +27 -0
- package/build/lib/extension/manifest-migrations.d.ts.map +1 -0
- package/build/lib/extension/manifest-migrations.js +118 -0
- package/build/lib/extension/manifest-migrations.js.map +1 -0
- package/build/lib/extension/manifest.d.ts +145 -0
- package/build/lib/extension/manifest.d.ts.map +1 -0
- package/build/lib/extension/manifest.js +521 -0
- package/build/lib/extension/manifest.js.map +1 -0
- package/build/lib/extension/package-changed.d.ts +11 -0
- package/build/lib/extension/package-changed.d.ts.map +1 -0
- package/build/lib/extension/package-changed.js +62 -0
- package/build/lib/extension/package-changed.js.map +1 -0
- package/build/lib/extension/plugin-config.d.ts +56 -0
- package/build/lib/extension/plugin-config.d.ts.map +1 -0
- package/build/lib/extension/plugin-config.js +102 -0
- package/build/lib/extension/plugin-config.js.map +1 -0
- package/build/lib/grid-register.d.ts +10 -0
- package/build/lib/grid-register.d.ts.map +1 -0
- package/build/lib/grid-register.js +122 -144
- package/build/lib/grid-register.js.map +1 -0
- package/build/lib/logger.d.ts +3 -0
- package/build/lib/logger.d.ts.map +1 -0
- package/build/lib/logger.js +5 -17
- package/build/lib/logger.js.map +1 -0
- package/build/lib/logsink.d.ts +4 -0
- package/build/lib/logsink.d.ts.map +1 -0
- package/build/lib/logsink.js +190 -187
- package/build/lib/logsink.js.map +1 -0
- package/build/lib/main.d.ts +62 -0
- package/build/lib/main.d.ts.map +1 -0
- package/build/lib/main.js +348 -228
- package/build/lib/main.js.map +1 -0
- package/build/lib/schema/arg-spec.d.ts +143 -0
- package/build/lib/schema/arg-spec.d.ts.map +1 -0
- package/build/lib/schema/arg-spec.js +164 -0
- package/build/lib/schema/arg-spec.js.map +1 -0
- package/build/lib/schema/cli-args.d.ts +19 -0
- package/build/lib/schema/cli-args.d.ts.map +1 -0
- package/build/lib/schema/cli-args.js +217 -0
- package/build/lib/schema/cli-args.js.map +1 -0
- package/build/lib/schema/cli-transformers.d.ts +5 -0
- package/build/lib/schema/cli-transformers.d.ts.map +1 -0
- package/build/lib/schema/cli-transformers.js +124 -0
- package/build/lib/schema/cli-transformers.js.map +1 -0
- package/build/lib/schema/index.d.ts +3 -0
- package/build/lib/schema/index.d.ts.map +1 -0
- package/build/lib/schema/index.js +19 -0
- package/build/lib/schema/index.js.map +1 -0
- package/build/lib/schema/keywords.d.ts +24 -0
- package/build/lib/schema/keywords.d.ts.map +1 -0
- package/build/lib/schema/keywords.js +128 -0
- package/build/lib/schema/keywords.js.map +1 -0
- package/build/lib/schema/schema.d.ts +259 -0
- package/build/lib/schema/schema.d.ts.map +1 -0
- package/build/lib/schema/schema.js +615 -0
- package/build/lib/schema/schema.js.map +1 -0
- package/build/lib/utils.d.ts +121 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +351 -273
- package/build/lib/utils.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build/types/cli.d.ts +134 -0
- package/build/types/cli.d.ts.map +1 -0
- package/build/types/cli.js +3 -0
- package/build/types/cli.js.map +1 -0
- package/build/types/index.d.ts +15 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +19 -0
- package/build/types/index.js.map +1 -0
- package/build/types/manifest/base.d.ts +135 -0
- package/build/types/manifest/base.d.ts.map +1 -0
- package/build/types/manifest/base.js +3 -0
- package/build/types/manifest/base.js.map +1 -0
- package/build/types/manifest/index.d.ts +19 -0
- package/build/types/manifest/index.d.ts.map +1 -0
- package/build/types/manifest/index.js +40 -0
- package/build/types/manifest/index.js.map +1 -0
- package/build/types/manifest/v3.d.ts +139 -0
- package/build/types/manifest/v3.d.ts.map +1 -0
- package/build/types/manifest/v3.js +3 -0
- package/build/types/manifest/v3.js.map +1 -0
- package/driver.d.ts +1 -0
- package/driver.js +14 -0
- package/index.js +11 -0
- package/lib/appium.js +535 -186
- package/lib/cli/args.js +267 -422
- package/lib/cli/driver-command.js +126 -23
- package/lib/cli/extension-command.js +679 -271
- package/lib/cli/extension.js +48 -17
- package/lib/cli/parser.js +263 -83
- package/lib/cli/plugin-command.js +115 -20
- package/lib/cli/utils.js +24 -10
- package/lib/config-file.js +220 -0
- package/lib/config.js +244 -110
- package/lib/constants.js +71 -0
- package/lib/extension/driver-config.js +250 -0
- package/lib/extension/extension-config.js +682 -0
- package/lib/extension/index.js +116 -0
- package/lib/extension/manifest-migrations.js +120 -0
- package/lib/extension/manifest.js +573 -0
- package/lib/extension/package-changed.js +64 -0
- package/lib/extension/plugin-config.js +112 -0
- package/lib/grid-register.js +49 -35
- package/lib/logger.js +1 -2
- package/lib/logsink.js +64 -38
- package/lib/main.js +321 -101
- package/lib/schema/arg-spec.js +229 -0
- package/lib/schema/cli-args.js +238 -0
- package/lib/schema/cli-transformers.js +119 -0
- package/lib/schema/index.js +2 -0
- package/lib/schema/keywords.js +136 -0
- package/lib/schema/schema.js +722 -0
- package/lib/utils.js +291 -167
- package/package.json +83 -84
- package/plugin.d.ts +1 -0
- package/plugin.js +13 -0
- package/scripts/autoinstall-extensions.js +237 -0
- package/support.d.ts +1 -0
- package/support.js +13 -0
- package/tsconfig.json +25 -0
- package/types/cli.ts +193 -0
- package/types/index.ts +20 -0
- package/types/manifest/README.md +30 -0
- package/types/manifest/base.ts +158 -0
- package/types/manifest/index.ts +27 -0
- package/types/manifest/v3.ts +161 -0
- package/CHANGELOG.md +0 -3515
- package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
- package/build/lib/cli/npm.js +0 -208
- package/build/lib/cli/parser-helpers.js +0 -82
- package/build/lib/driver-config.js +0 -77
- package/build/lib/drivers.js +0 -96
- package/build/lib/extension-config.js +0 -253
- package/build/lib/plugin-config.js +0 -59
- package/build/lib/plugins.js +0 -14
- package/lib/cli/npm.js +0 -184
- package/lib/cli/parser-helpers.js +0 -79
- package/lib/driver-config.js +0 -46
- package/lib/drivers.js +0 -81
- package/lib/extension-config.js +0 -209
- package/lib/plugin-config.js +0 -34
- package/lib/plugins.js +0 -10
package/lib/main.js
CHANGED
|
@@ -1,42 +1,62 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// transpile:main
|
|
3
2
|
|
|
4
|
-
import {
|
|
5
|
-
import logger from './logger'; // logger needs to remain
|
|
3
|
+
import {init as logsinkInit} from './logsink'; // this import needs to come first since it sets up global npmlog
|
|
4
|
+
import logger from './logger'; // logger needs to remain second
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import {routeConfiguringFunction as makeRouter, server as baseServer} from '@appium/base-driver';
|
|
7
|
+
import {logger as logFactory, util, env} from '@appium/support';
|
|
8
|
+
import {asyncify} from 'asyncbox';
|
|
6
9
|
import _ from 'lodash';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { USE_ALL_PLUGINS } from './cli/args';
|
|
11
|
-
import { logger as logFactory, util } from 'appium-support';
|
|
10
|
+
import {AppiumDriver} from './appium';
|
|
11
|
+
import {runExtensionCommand} from './cli/extension';
|
|
12
|
+
import {getParser} from './cli/parser';
|
|
12
13
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
getGitRev,
|
|
14
|
+
APPIUM_VER,
|
|
15
|
+
checkNodeOk,
|
|
16
|
+
getGitRev,
|
|
17
|
+
getNonDefaultServerArgs,
|
|
18
|
+
showConfig,
|
|
19
|
+
showBuildInfo,
|
|
20
|
+
validateTmpDir,
|
|
21
|
+
warnNodeDeprecations,
|
|
22
|
+
checkNpmOk,
|
|
16
23
|
} from './config';
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
import { runExtensionCommand } from './cli/extension';
|
|
21
|
-
import { AppiumDriver } from './appium';
|
|
24
|
+
import {readConfigFile} from './config-file';
|
|
25
|
+
import {loadExtensions, getActivePlugins, getActiveDrivers} from './extension';
|
|
26
|
+
import {SERVER_SUBCOMMAND} from './constants';
|
|
22
27
|
import registerNode from './grid-register';
|
|
23
|
-
import {
|
|
28
|
+
import {getDefaultsForSchema, validate} from './schema/schema';
|
|
29
|
+
import {
|
|
30
|
+
inspect,
|
|
31
|
+
adjustNodePath,
|
|
32
|
+
isDriverCommandArgs,
|
|
33
|
+
isExtensionCommandArgs,
|
|
34
|
+
isPluginCommandArgs,
|
|
35
|
+
isServerCommandArgs,
|
|
36
|
+
} from './utils';
|
|
24
37
|
|
|
38
|
+
const {resolveAppiumHome} = env;
|
|
25
39
|
|
|
26
|
-
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param {ParsedArgs} args
|
|
43
|
+
* @param {boolean} [throwInsteadOfExit]
|
|
44
|
+
*/
|
|
45
|
+
async function preflightChecks(args, throwInsteadOfExit = false) {
|
|
27
46
|
try {
|
|
28
47
|
checkNodeOk();
|
|
48
|
+
await checkNpmOk();
|
|
29
49
|
if (args.longStacktrace) {
|
|
30
50
|
require('longjohn').async_trace_limit = -1;
|
|
31
51
|
}
|
|
32
|
-
if (args.
|
|
33
|
-
await
|
|
52
|
+
if (args.showBuildInfo) {
|
|
53
|
+
await showBuildInfo();
|
|
34
54
|
process.exit(0);
|
|
35
55
|
}
|
|
36
56
|
warnNodeDeprecations();
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
57
|
+
|
|
58
|
+
validate(args);
|
|
59
|
+
|
|
40
60
|
if (args.tmpDir) {
|
|
41
61
|
await validateTmpDir(args.tmpDir);
|
|
42
62
|
}
|
|
@@ -50,18 +70,29 @@ async function preflightChecks ({parser, args, driverConfig, pluginConfig, throw
|
|
|
50
70
|
}
|
|
51
71
|
}
|
|
52
72
|
|
|
53
|
-
|
|
73
|
+
/**
|
|
74
|
+
* @param {Args} args
|
|
75
|
+
*/
|
|
76
|
+
function logNonDefaultArgsWarning(args) {
|
|
54
77
|
logger.info('Non-default server args:');
|
|
55
|
-
|
|
78
|
+
inspect(args);
|
|
56
79
|
}
|
|
57
80
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
/**
|
|
82
|
+
* @param {Args['defaultCapabilities']} caps
|
|
83
|
+
*/
|
|
84
|
+
function logDefaultCapabilitiesWarning(caps) {
|
|
85
|
+
logger.info(
|
|
86
|
+
'Default capabilities, which will be added to each request ' +
|
|
87
|
+
'unless overridden by desired capabilities:'
|
|
88
|
+
);
|
|
89
|
+
inspect(caps);
|
|
62
90
|
}
|
|
63
91
|
|
|
64
|
-
|
|
92
|
+
/**
|
|
93
|
+
* @param {ParsedArgs} args
|
|
94
|
+
*/
|
|
95
|
+
async function logStartupInfo(args) {
|
|
65
96
|
let welcome = `Welcome to Appium v${APPIUM_VER}`;
|
|
66
97
|
let appiumRev = await getGitRev();
|
|
67
98
|
if (appiumRev) {
|
|
@@ -69,7 +100,7 @@ async function logStartupInfo (parser, args) {
|
|
|
69
100
|
}
|
|
70
101
|
logger.info(welcome);
|
|
71
102
|
|
|
72
|
-
let showArgs =
|
|
103
|
+
let showArgs = getNonDefaultServerArgs(args);
|
|
73
104
|
if (_.size(showArgs)) {
|
|
74
105
|
logNonDefaultArgsWarning(showArgs);
|
|
75
106
|
}
|
|
@@ -83,20 +114,72 @@ async function logStartupInfo (parser, args) {
|
|
|
83
114
|
// }
|
|
84
115
|
}
|
|
85
116
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Logs the address and port the server is listening on
|
|
119
|
+
* @param {string} address - Address
|
|
120
|
+
* @param {number} port - Port
|
|
121
|
+
* @returns {void}
|
|
122
|
+
*/
|
|
123
|
+
function logServerPort(address, port) {
|
|
124
|
+
let logMessage = `Appium REST http interface listener started on ` + `${address}:${port}`;
|
|
89
125
|
logger.info(logMessage);
|
|
90
126
|
}
|
|
91
127
|
|
|
92
|
-
|
|
93
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Gets a list of `updateServer` functions from all extensions
|
|
130
|
+
* @param {DriverNameMap} driverClasses
|
|
131
|
+
* @param {PluginNameMap} pluginClasses
|
|
132
|
+
* @returns {import('@appium/types').UpdateServerCallback[]}
|
|
133
|
+
*/
|
|
134
|
+
function getServerUpdaters(driverClasses, pluginClasses) {
|
|
135
|
+
return _.compact(_.map([...driverClasses.keys(), ...pluginClasses.keys()], 'updateServer'));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Makes a big `MethodMap` from all the little `MethodMap`s in the extensions
|
|
140
|
+
* @param {DriverNameMap} driverClasses
|
|
141
|
+
* @param {PluginNameMap} pluginClasses
|
|
142
|
+
* @returns {import('@appium/types').MethodMap<import('@appium/types').Driver>}
|
|
143
|
+
*/
|
|
144
|
+
function getExtraMethodMap(driverClasses, pluginClasses) {
|
|
145
|
+
return [...driverClasses.keys(), ...pluginClasses.keys()].reduce(
|
|
146
|
+
(map, klass) => ({
|
|
147
|
+
...map,
|
|
148
|
+
...(klass.newMethodMap ?? {}),
|
|
149
|
+
}),
|
|
150
|
+
{}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Initializes Appium, but does not start the server.
|
|
155
|
+
*
|
|
156
|
+
* Use this to get at the configuration schema.
|
|
157
|
+
*
|
|
158
|
+
* If `args` contains a non-empty `subcommand` which is not `server`, this function will return an empty object.
|
|
159
|
+
*
|
|
160
|
+
* @template {CliCommand} [Cmd=ServerCommand]
|
|
161
|
+
* @template {CliExtensionSubcommand|void} [SubCmd=void]
|
|
162
|
+
* @param {Args<Cmd, SubCmd>} [args] - Partial args (progammatic usage only)
|
|
163
|
+
* @returns {Promise<InitResult<Cmd>>}
|
|
164
|
+
* @example
|
|
165
|
+
* import {init, getSchema} from 'appium';
|
|
166
|
+
* const options = {}; // config object
|
|
167
|
+
* await init(options);
|
|
168
|
+
* const schema = getSchema(); // entire config schema including plugins and drivers
|
|
169
|
+
*/
|
|
170
|
+
async function init(args) {
|
|
171
|
+
const appiumHome = args?.appiumHome ?? (await resolveAppiumHome());
|
|
172
|
+
|
|
173
|
+
adjustNodePath();
|
|
174
|
+
|
|
175
|
+
const {driverConfig, pluginConfig} = await loadExtensions(appiumHome);
|
|
176
|
+
|
|
177
|
+
const parser = getParser();
|
|
94
178
|
let throwInsteadOfExit = false;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// with defaults
|
|
98
|
-
args = Object.assign({}, getDefaultServerArgs(), args);
|
|
179
|
+
/** @type {Args<Cmd, SubCmd>} */
|
|
180
|
+
let preConfigArgs;
|
|
99
181
|
|
|
182
|
+
if (args) {
|
|
100
183
|
// if we have a containing package instead of running as a CLI process,
|
|
101
184
|
// that package might not appreciate us calling 'process.exit' willy-
|
|
102
185
|
// nilly, so give it the option to have us throw instead of exit
|
|
@@ -105,80 +188,166 @@ async function main (args = null) {
|
|
|
105
188
|
// but remove it since it's not a real server arg per se
|
|
106
189
|
delete args.throwInsteadOfExit;
|
|
107
190
|
}
|
|
191
|
+
preConfigArgs = {...args, subcommand: args.subcommand ?? SERVER_SUBCOMMAND};
|
|
108
192
|
} else {
|
|
109
193
|
// otherwise parse from CLI
|
|
110
|
-
|
|
194
|
+
preConfigArgs = /** @type {Args<Cmd, SubCmd>} */ (parser.parseArgs());
|
|
111
195
|
}
|
|
112
|
-
await logsinkInit(args);
|
|
113
196
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
197
|
+
const configResult = await readConfigFile(preConfigArgs.configFile);
|
|
198
|
+
|
|
199
|
+
if (!_.isEmpty(configResult.errors)) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
`Errors in config file ${configResult.filepath}:\n ${
|
|
202
|
+
configResult.reason ?? configResult.errors
|
|
203
|
+
}`
|
|
204
|
+
);
|
|
119
205
|
}
|
|
120
206
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
207
|
+
// merge config and apply defaults.
|
|
208
|
+
// the order of precendece is:
|
|
209
|
+
// 1. command line args
|
|
210
|
+
// 2. config file
|
|
211
|
+
// 3. defaults from config file.
|
|
212
|
+
if (isServerCommandArgs(preConfigArgs)) {
|
|
213
|
+
const defaults = getDefaultsForSchema(false);
|
|
214
|
+
|
|
215
|
+
/** @type {ParsedArgs} */
|
|
216
|
+
const serverArgs = _.defaultsDeep({}, preConfigArgs, configResult.config?.server, defaults);
|
|
217
|
+
|
|
218
|
+
if (preConfigArgs.showConfig) {
|
|
219
|
+
showConfig(getNonDefaultServerArgs(preConfigArgs), configResult, defaults, serverArgs);
|
|
220
|
+
return /** @type {InitResult<Cmd>} */ ({});
|
|
126
221
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
222
|
+
|
|
223
|
+
await logsinkInit(serverArgs);
|
|
224
|
+
|
|
225
|
+
if (serverArgs.logFilters) {
|
|
226
|
+
const {issues, rules} = await logFactory.loadSecureValuesPreprocessingRules(
|
|
227
|
+
serverArgs.logFilters
|
|
228
|
+
);
|
|
229
|
+
if (!_.isEmpty(issues)) {
|
|
230
|
+
throw new Error(
|
|
231
|
+
`The log filtering rules config '${serverArgs.logFilters}' has issues: ` +
|
|
232
|
+
JSON.stringify(issues, null, 2)
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
if (_.isEmpty(rules)) {
|
|
236
|
+
logger.warn(
|
|
237
|
+
`Found no log filtering rules in '${serverArgs.logFilters}'. Is that expected?`
|
|
238
|
+
);
|
|
239
|
+
} else {
|
|
240
|
+
logger.info(
|
|
241
|
+
`Loaded ${util.pluralize('filtering rule', rules.length, true)} from '${
|
|
242
|
+
serverArgs.logFilters
|
|
243
|
+
}'`
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const appiumDriver = new AppiumDriver(serverArgs);
|
|
249
|
+
// set the config on the umbrella driver so it can match drivers to caps
|
|
250
|
+
appiumDriver.driverConfig = driverConfig;
|
|
251
|
+
await preflightChecks(serverArgs, throwInsteadOfExit);
|
|
252
|
+
|
|
253
|
+
return /** @type {InitResult<Cmd>} */ ({
|
|
254
|
+
appiumDriver,
|
|
255
|
+
parsedArgs: serverArgs,
|
|
256
|
+
driverConfig,
|
|
257
|
+
pluginConfig,
|
|
258
|
+
});
|
|
259
|
+
} else {
|
|
260
|
+
if (isExtensionCommandArgs(preConfigArgs)) {
|
|
261
|
+
// if the user has requested the 'driver' CLI, don't run the normal server,
|
|
262
|
+
// but instead pass control to the driver CLI
|
|
263
|
+
if (isDriverCommandArgs(preConfigArgs)) {
|
|
264
|
+
await runExtensionCommand(preConfigArgs, driverConfig);
|
|
265
|
+
}
|
|
266
|
+
if (isPluginCommandArgs(preConfigArgs)) {
|
|
267
|
+
await runExtensionCommand(preConfigArgs, pluginConfig);
|
|
268
|
+
}
|
|
131
269
|
}
|
|
270
|
+
return /** @type {InitResult<Cmd>} */ ({});
|
|
132
271
|
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Initializes Appium's config. Starts server if appropriate and resolves the
|
|
276
|
+
* server instance if so; otherwise resolves w/ `undefined`.
|
|
277
|
+
* @template {CliCommand} [Cmd=ServerCommand]
|
|
278
|
+
* @template {CliExtensionSubcommand|void} [SubCmd=void]
|
|
279
|
+
* @param {Args<Cmd, SubCmd>} [args] - Arguments from CLI or otherwise
|
|
280
|
+
* @returns {Promise<Cmd extends ServerCommand ? import('@appium/types').AppiumServer : void>}
|
|
281
|
+
*/
|
|
282
|
+
async function main(args) {
|
|
283
|
+
const initResult = await init(args);
|
|
133
284
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
285
|
+
if (_.isEmpty(initResult)) {
|
|
286
|
+
// if this branch is taken, we've run a different subcommand, so there's nothing
|
|
287
|
+
// left to do here.
|
|
288
|
+
return /** @type {Cmd extends ServerCommand ? import('@appium/types').AppiumServer : void} */ (
|
|
289
|
+
undefined
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const {appiumDriver, pluginConfig, driverConfig, parsedArgs} =
|
|
294
|
+
/** @type {InitResult<ServerCommand>} */ (initResult);
|
|
295
|
+
|
|
296
|
+
const pluginClasses = getActivePlugins(pluginConfig, parsedArgs.usePlugins);
|
|
297
|
+
// set the active plugins on the umbrella driver so it can use them for commands
|
|
298
|
+
appiumDriver.pluginClasses = pluginClasses;
|
|
299
|
+
|
|
300
|
+
await logStartupInfo(parsedArgs);
|
|
140
301
|
let routeConfiguringFunction = makeRouter(appiumDriver);
|
|
141
302
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// it can use them to wrap command execution
|
|
146
|
-
const plugins = Object.keys(pluginConfig.installedExtensions).filter((pluginName) =>
|
|
147
|
-
_.includes(args.plugins, pluginName) ||
|
|
148
|
-
(args.plugins.length === 1 && args.plugins[0] === USE_ALL_PLUGINS)
|
|
149
|
-
).map((pluginName) => {
|
|
150
|
-
try {
|
|
151
|
-
const PluginClass = pluginConfig.require(pluginName);
|
|
152
|
-
return new PluginClass(pluginName);
|
|
153
|
-
} catch (err) {
|
|
154
|
-
logger.error(`Could not load plugin '${pluginName}', so it will not be available. Error ` +
|
|
155
|
-
`in loading the plugin was: ${err}`);
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
}).filter(Boolean);
|
|
159
|
-
appiumDriver.plugins = plugins;
|
|
303
|
+
const driverClasses = getActiveDrivers(driverConfig, parsedArgs.useDrivers);
|
|
304
|
+
const serverUpdaters = getServerUpdaters(driverClasses, pluginClasses);
|
|
305
|
+
const extraMethodMap = getExtraMethodMap(driverClasses, pluginClasses);
|
|
160
306
|
|
|
161
|
-
|
|
307
|
+
/** @type {import('@appium/base-driver').ServerOpts} */
|
|
308
|
+
const serverOpts = {
|
|
162
309
|
routeConfiguringFunction,
|
|
163
|
-
port:
|
|
164
|
-
hostname:
|
|
165
|
-
allowCors:
|
|
166
|
-
basePath:
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
310
|
+
port: parsedArgs.port,
|
|
311
|
+
hostname: parsedArgs.address,
|
|
312
|
+
allowCors: parsedArgs.allowCors,
|
|
313
|
+
basePath: parsedArgs.basePath,
|
|
314
|
+
serverUpdaters,
|
|
315
|
+
extraMethodMap,
|
|
316
|
+
cliArgs: parsedArgs,
|
|
317
|
+
};
|
|
318
|
+
if (parsedArgs.keepAliveTimeout) {
|
|
319
|
+
serverOpts.keepAliveTimeout = parsedArgs.keepAliveTimeout * 1000;
|
|
173
320
|
}
|
|
174
|
-
|
|
321
|
+
let server;
|
|
175
322
|
try {
|
|
176
|
-
|
|
177
|
-
|
|
323
|
+
server = await baseServer(serverOpts);
|
|
324
|
+
} catch (err) {
|
|
325
|
+
logger.error(
|
|
326
|
+
`Could not configure Appium server. It's possible that a driver or plugin tried ` +
|
|
327
|
+
`to update the server and failed. Original error: ${err.message}`
|
|
328
|
+
);
|
|
329
|
+
logger.debug(err.stack);
|
|
330
|
+
return process.exit(1);
|
|
331
|
+
}
|
|
178
332
|
|
|
333
|
+
if (parsedArgs.allowCors) {
|
|
334
|
+
logger.warn(
|
|
335
|
+
'You have enabled CORS requests from any host. Be careful not ' +
|
|
336
|
+
'to visit sites which could maliciously try to start Appium ' +
|
|
337
|
+
'sessions on your machine'
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
appiumDriver.server = server;
|
|
341
|
+
try {
|
|
179
342
|
// configure as node on grid, if necessary
|
|
180
|
-
|
|
181
|
-
|
|
343
|
+
// falsy values should not cause this to run
|
|
344
|
+
if (parsedArgs.nodeconfig) {
|
|
345
|
+
await registerNode(
|
|
346
|
+
parsedArgs.nodeconfig,
|
|
347
|
+
parsedArgs.address,
|
|
348
|
+
parsedArgs.port,
|
|
349
|
+
parsedArgs.basePath
|
|
350
|
+
);
|
|
182
351
|
}
|
|
183
352
|
} catch (err) {
|
|
184
353
|
await server.close();
|
|
@@ -186,7 +355,7 @@ async function main (args = null) {
|
|
|
186
355
|
}
|
|
187
356
|
|
|
188
357
|
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
189
|
-
process.once(signal, async function onSignal
|
|
358
|
+
process.once(signal, async function onSignal() {
|
|
190
359
|
logger.info(`Received ${signal} - shutting down`);
|
|
191
360
|
try {
|
|
192
361
|
await appiumDriver.deleteAllSessions({
|
|
@@ -202,15 +371,66 @@ async function main (args = null) {
|
|
|
202
371
|
});
|
|
203
372
|
}
|
|
204
373
|
|
|
205
|
-
logServerPort(
|
|
374
|
+
logServerPort(parsedArgs.address, parsedArgs.port);
|
|
206
375
|
driverConfig.print();
|
|
207
|
-
pluginConfig.print(
|
|
376
|
+
pluginConfig.print([...pluginClasses.values()]);
|
|
208
377
|
|
|
209
|
-
return
|
|
378
|
+
return /** @type {Cmd extends ServerCommand ? import('@appium/types').AppiumServer : void} */ (
|
|
379
|
+
server
|
|
380
|
+
);
|
|
210
381
|
}
|
|
211
382
|
|
|
383
|
+
// NOTE: this is here for backwards compat for any scripts referencing `main.js` directly
|
|
384
|
+
// (more specifically, `build/lib/main.js`)
|
|
385
|
+
// the executable is now `../index.js`, so that module will typically be `require.main`.
|
|
212
386
|
if (require.main === module) {
|
|
213
387
|
asyncify(main);
|
|
214
388
|
}
|
|
215
389
|
|
|
216
|
-
|
|
390
|
+
// everything below here is intended to be a public API.
|
|
391
|
+
export {readConfigFile} from './config-file';
|
|
392
|
+
export {finalizeSchema, getSchema, validate} from './schema/schema';
|
|
393
|
+
export {main, init, resolveAppiumHome};
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* @typedef {import('@appium/types').DriverType} DriverType
|
|
397
|
+
* @typedef {import('@appium/types').PluginType} PluginType
|
|
398
|
+
* @typedef {import('@appium/types').DriverClass} DriverClass
|
|
399
|
+
* @typedef {import('@appium/types').PluginClass} PluginClass
|
|
400
|
+
* @typedef {import('appium/types').CliCommand} CliCommand
|
|
401
|
+
* @typedef {import('appium/types').CliExtensionSubcommand} CliExtensionSubcommand
|
|
402
|
+
* @typedef {import('appium/types').CliExtensionCommand} CliExtensionCommand
|
|
403
|
+
* @typedef {import('appium/types').CliCommandServer} ServerCommand
|
|
404
|
+
* @typedef {import('appium/types').CliCommandDriver} DriverCommand
|
|
405
|
+
* @typedef {import('appium/types').CliCommandPlugin} PluginCommand
|
|
406
|
+
* @typedef {import('./extension').DriverNameMap} DriverNameMap
|
|
407
|
+
* @typedef {import('./extension').PluginNameMap} PluginNameMap
|
|
408
|
+
*/
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Literally an empty object
|
|
412
|
+
* @typedef { {} } ExtCommandInitResult
|
|
413
|
+
*/
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* @typedef ServerInitData
|
|
417
|
+
* @property {import('./appium').AppiumDriver} appiumDriver - The Appium driver
|
|
418
|
+
* @property {import('appium/types').ParsedArgs} parsedArgs - The parsed arguments
|
|
419
|
+
*/
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* @template {CliCommand} Cmd
|
|
423
|
+
* @typedef {Cmd extends ServerCommand ? ServerInitData & import('./extension').ExtensionConfigs : ExtCommandInitResult} InitResult
|
|
424
|
+
*/
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* @template {CliCommand} [Cmd=ServerCommand]
|
|
428
|
+
* @template {CliExtensionSubcommand|void} [SubCmd=void]
|
|
429
|
+
* @typedef {import('appium/types').Args<Cmd, SubCmd>} Args
|
|
430
|
+
*/
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* @template {CliCommand} [Cmd=ServerCommand]
|
|
434
|
+
* @template {CliExtensionSubcommand|void} [SubCmd=void]
|
|
435
|
+
* @typedef {import('appium/types').ParsedArgs<Cmd, SubCmd>} ParsedArgs
|
|
436
|
+
*/
|