appium 2.0.0-beta.7 → 2.0.0-beta.70
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/LICENSE +1 -1
- package/README.md +149 -58
- package/build/lib/appium.d.ts +229 -0
- package/build/lib/appium.d.ts.map +1 -0
- package/build/lib/appium.js +678 -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 +263 -300
- 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 +131 -81
- package/build/lib/cli/driver-command.js.map +1 -0
- package/build/lib/cli/extension-command.d.ts +402 -0
- package/build/lib/cli/extension-command.d.ts.map +1 -0
- package/build/lib/cli/extension-command.js +799 -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 -60
- 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 +252 -148
- 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 +125 -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 +262 -223
- package/build/lib/config.js.map +1 -0
- package/build/lib/constants.d.ts +56 -0
- package/build/lib/constants.d.ts.map +1 -0
- package/build/lib/constants.js +73 -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 +210 -0
- package/build/lib/extension/driver-config.js.map +1 -0
- package/build/lib/extension/extension-config.d.ts +270 -0
- package/build/lib/extension/extension-config.d.ts.map +1 -0
- package/build/lib/extension/extension-config.js +601 -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 +134 -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 +528 -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 +189 -184
- 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 +388 -234
- 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 +220 -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 +260 -0
- package/build/lib/schema/schema.d.ts.map +1 -0
- package/build/lib/schema/schema.js +640 -0
- package/build/lib/schema/schema.js.map +1 -0
- package/build/lib/utils.d.ts +266 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +349 -273
- package/build/lib/utils.js.map +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 +21 -0
- package/build/types/manifest/index.d.ts.map +1 -0
- package/build/types/manifest/index.js +42 -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/build/types/manifest/v4.d.ts +139 -0
- package/build/types/manifest/v4.d.ts.map +1 -0
- package/build/types/manifest/v4.js +3 -0
- package/build/types/manifest/v4.js.map +1 -0
- package/driver.d.ts +1 -0
- package/driver.js +14 -0
- package/index.js +11 -0
- package/lib/appium.js +558 -186
- package/lib/cli/args.js +275 -407
- package/lib/cli/driver-command.js +132 -24
- package/lib/cli/extension-command.js +751 -272
- package/lib/cli/extension.js +47 -20
- package/lib/cli/parser.js +267 -95
- package/lib/cli/plugin-command.js +122 -22
- package/lib/cli/utils.js +24 -10
- package/lib/config-file.js +220 -0
- package/lib/config.js +243 -132
- package/lib/constants.js +79 -0
- package/lib/extension/driver-config.js +247 -0
- package/lib/extension/extension-config.js +709 -0
- package/lib/extension/index.js +116 -0
- package/lib/extension/manifest-migrations.js +136 -0
- package/lib/extension/manifest.js +580 -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 +59 -36
- package/lib/main.js +369 -104
- package/lib/schema/arg-spec.js +229 -0
- package/lib/schema/cli-args.js +241 -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 +725 -0
- package/lib/utils.js +289 -167
- package/package.json +84 -83
- package/plugin.d.ts +1 -0
- package/plugin.js +13 -0
- package/scripts/autoinstall-extensions.js +243 -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 +28 -0
- package/types/manifest/v3.ts +161 -0
- package/types/manifest/v4.ts +161 -0
- package/CHANGELOG.md +0 -3594
- package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
- package/build/lib/cli/argparse-actions.js +0 -104
- package/build/lib/cli/npm.js +0 -200
- package/build/lib/cli/parser-helpers.js +0 -93
- package/build/lib/driver-config.js +0 -77
- package/build/lib/drivers.js +0 -99
- 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/argparse-actions.js +0 -77
- package/lib/cli/npm.js +0 -175
- package/lib/cli/parser-helpers.js +0 -91
- package/lib/driver-config.js +0 -46
- package/lib/drivers.js +0 -84
- 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
|
+
import {routeConfiguringFunction as makeRouter, server as baseServer} from '@appium/base-driver';
|
|
6
|
+
import {logger as logFactory, util, env, fs} from '@appium/support';
|
|
7
|
+
import {asyncify} from 'asyncbox';
|
|
6
8
|
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';
|
|
9
|
+
import {AppiumDriver} from './appium';
|
|
10
|
+
import {runExtensionCommand} from './cli/extension';
|
|
11
|
+
import {getParser} from './cli/parser';
|
|
12
12
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
getGitRev,
|
|
13
|
+
APPIUM_VER,
|
|
14
|
+
checkNodeOk,
|
|
15
|
+
getGitRev,
|
|
16
|
+
getNonDefaultServerArgs,
|
|
17
|
+
showConfig,
|
|
18
|
+
showBuildInfo,
|
|
19
|
+
validateTmpDir,
|
|
20
|
+
warnNodeDeprecations,
|
|
21
|
+
checkNpmOk,
|
|
16
22
|
} from './config';
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
import { runExtensionCommand } from './cli/extension';
|
|
21
|
-
import { AppiumDriver } from './appium';
|
|
23
|
+
import {readConfigFile} from './config-file';
|
|
24
|
+
import {loadExtensions, getActivePlugins, getActiveDrivers} from './extension';
|
|
25
|
+
import {SERVER_SUBCOMMAND, LONG_STACKTRACE_LIMIT} from './constants';
|
|
22
26
|
import registerNode from './grid-register';
|
|
23
|
-
import {
|
|
27
|
+
import {getDefaultsForSchema, validate} from './schema/schema';
|
|
28
|
+
import {
|
|
29
|
+
inspect,
|
|
30
|
+
adjustNodePath,
|
|
31
|
+
isDriverCommandArgs,
|
|
32
|
+
isExtensionCommandArgs,
|
|
33
|
+
isPluginCommandArgs,
|
|
34
|
+
isServerCommandArgs,
|
|
35
|
+
} from './utils';
|
|
36
|
+
import os from 'node:os';
|
|
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
|
+
Error.stackTraceLimit = LONG_STACKTRACE_LIMIT;
|
|
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,114 @@ async function logStartupInfo (parser, args) {
|
|
|
83
114
|
// }
|
|
84
115
|
}
|
|
85
116
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Gets a list of `updateServer` functions from all extensions
|
|
119
|
+
* @param {DriverNameMap} driverClasses
|
|
120
|
+
* @param {PluginNameMap} pluginClasses
|
|
121
|
+
* @returns {import('@appium/types').UpdateServerCallback[]}
|
|
122
|
+
*/
|
|
123
|
+
function getServerUpdaters(driverClasses, pluginClasses) {
|
|
124
|
+
return _.compact(_.map([...driverClasses.keys(), ...pluginClasses.keys()], 'updateServer'));
|
|
90
125
|
}
|
|
91
126
|
|
|
92
|
-
|
|
93
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Makes a big `MethodMap` from all the little `MethodMap`s in the extensions
|
|
129
|
+
* @param {DriverNameMap} driverClasses
|
|
130
|
+
* @param {PluginNameMap} pluginClasses
|
|
131
|
+
* @returns {import('@appium/types').MethodMap<import('@appium/types').Driver>}
|
|
132
|
+
*/
|
|
133
|
+
function getExtraMethodMap(driverClasses, pluginClasses) {
|
|
134
|
+
return [...driverClasses.keys(), ...pluginClasses.keys()].reduce(
|
|
135
|
+
(map, klass) => ({
|
|
136
|
+
...map,
|
|
137
|
+
...(klass.newMethodMap ?? {}),
|
|
138
|
+
}),
|
|
139
|
+
{}
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Prepares and validates appium home path folder
|
|
145
|
+
*
|
|
146
|
+
* @param {string} name The name of the appium home source (needed for error messages)
|
|
147
|
+
* @param {string} appiumHome The actual value to be verified
|
|
148
|
+
* @returns {Promise<string>} Same appiumHome value
|
|
149
|
+
* @throws {Error} If the validation has failed
|
|
150
|
+
*/
|
|
151
|
+
async function prepareAppiumHome(name, appiumHome) {
|
|
152
|
+
let stat;
|
|
153
|
+
try {
|
|
154
|
+
stat = await fs.stat(appiumHome);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
let err = e;
|
|
157
|
+
if (e.code === 'ENOENT') {
|
|
158
|
+
try {
|
|
159
|
+
await fs.mkdir(appiumHome, {recursive: true});
|
|
160
|
+
return appiumHome;
|
|
161
|
+
} catch (e1) {
|
|
162
|
+
err = e1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
throw new Error(
|
|
166
|
+
`The path '${appiumHome}' provided in the ${name} must point ` +
|
|
167
|
+
`to a valid folder writeable for the current user account '${os.userInfo().username}'. ` +
|
|
168
|
+
`Original error: ${err.message}`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
if (!stat.isDirectory()) {
|
|
172
|
+
throw new Error(
|
|
173
|
+
`The path '${appiumHome}' provided in the ${name} must point to a valid folder`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
await fs.access(appiumHome, fs.constants.W_OK);
|
|
178
|
+
} catch (e) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
`The folder path '${appiumHome}' provided in the ${name} must be ` +
|
|
181
|
+
`writeable for the current user account '${os.userInfo().username}. ` +
|
|
182
|
+
`Original error: ${e.message}`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
return appiumHome;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Initializes Appium, but does not start the server.
|
|
190
|
+
*
|
|
191
|
+
* Use this to get at the configuration schema.
|
|
192
|
+
*
|
|
193
|
+
* If `args` contains a non-empty `subcommand` which is not `server`, this function will return an empty object.
|
|
194
|
+
*
|
|
195
|
+
* @template {CliCommand} [Cmd=ServerCommand]
|
|
196
|
+
* @template {CliExtensionSubcommand|void} [SubCmd=void]
|
|
197
|
+
* @param {Args<Cmd, SubCmd>} [args] - Partial args (progammatic usage only)
|
|
198
|
+
* @returns {Promise<InitResult<Cmd>>}
|
|
199
|
+
* @example
|
|
200
|
+
* import {init, getSchema} from 'appium';
|
|
201
|
+
* const options = {}; // config object
|
|
202
|
+
* await init(options);
|
|
203
|
+
* const schema = getSchema(); // entire config schema including plugins and drivers
|
|
204
|
+
*/
|
|
205
|
+
async function init(args) {
|
|
206
|
+
const appiumHome = args?.appiumHome ?? (await resolveAppiumHome());
|
|
207
|
+
let appiumHomeSourceName = 'autodetected appium home path';
|
|
208
|
+
if (!_.isNil(args?.appiumHome)) {
|
|
209
|
+
appiumHomeSourceName = 'appiumHome config value';
|
|
210
|
+
} else if (process.env.APPIUM_HOME) {
|
|
211
|
+
appiumHomeSourceName = 'APPIUM_HOME environment variable';
|
|
212
|
+
}
|
|
213
|
+
await prepareAppiumHome(appiumHomeSourceName, appiumHome);
|
|
214
|
+
|
|
215
|
+
adjustNodePath();
|
|
216
|
+
|
|
217
|
+
const {driverConfig, pluginConfig} = await loadExtensions(appiumHome);
|
|
218
|
+
|
|
219
|
+
const parser = getParser();
|
|
94
220
|
let throwInsteadOfExit = false;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// with defaults
|
|
98
|
-
args = Object.assign({}, getDefaultServerArgs(), args);
|
|
221
|
+
/** @type {Args<Cmd, SubCmd>} */
|
|
222
|
+
let preConfigArgs;
|
|
99
223
|
|
|
224
|
+
if (args) {
|
|
100
225
|
// if we have a containing package instead of running as a CLI process,
|
|
101
226
|
// that package might not appreciate us calling 'process.exit' willy-
|
|
102
227
|
// nilly, so give it the option to have us throw instead of exit
|
|
@@ -105,84 +230,170 @@ async function main (args = null) {
|
|
|
105
230
|
// but remove it since it's not a real server arg per se
|
|
106
231
|
delete args.throwInsteadOfExit;
|
|
107
232
|
}
|
|
233
|
+
preConfigArgs = {...args, subcommand: args.subcommand ?? SERVER_SUBCOMMAND};
|
|
108
234
|
} else {
|
|
109
235
|
// otherwise parse from CLI
|
|
110
|
-
|
|
236
|
+
preConfigArgs = /** @type {Args<Cmd, SubCmd>} */ (parser.parseArgs());
|
|
111
237
|
}
|
|
112
|
-
await logsinkInit(args);
|
|
113
238
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
239
|
+
const configResult = await readConfigFile(preConfigArgs.configFile);
|
|
240
|
+
|
|
241
|
+
if (!_.isEmpty(configResult.errors)) {
|
|
242
|
+
throw new Error(
|
|
243
|
+
`Errors in config file ${configResult.filepath}:\n ${
|
|
244
|
+
configResult.reason ?? configResult.errors
|
|
245
|
+
}`
|
|
246
|
+
);
|
|
119
247
|
}
|
|
120
248
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
249
|
+
// merge config and apply defaults.
|
|
250
|
+
// the order of precendece is:
|
|
251
|
+
// 1. command line args
|
|
252
|
+
// 2. config file
|
|
253
|
+
// 3. defaults from config file.
|
|
254
|
+
if (isServerCommandArgs(preConfigArgs)) {
|
|
255
|
+
const defaults = getDefaultsForSchema(false);
|
|
256
|
+
|
|
257
|
+
/** @type {ParsedArgs} */
|
|
258
|
+
const serverArgs = _.defaultsDeep({}, preConfigArgs, configResult.config?.server, defaults);
|
|
259
|
+
|
|
260
|
+
if (preConfigArgs.showConfig) {
|
|
261
|
+
showConfig(getNonDefaultServerArgs(preConfigArgs), configResult, defaults, serverArgs);
|
|
262
|
+
return /** @type {InitResult<Cmd>} */ ({});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
await logsinkInit(serverArgs);
|
|
266
|
+
|
|
267
|
+
if (serverArgs.logFilters) {
|
|
268
|
+
const {issues, rules} = await logFactory.loadSecureValuesPreprocessingRules(
|
|
269
|
+
serverArgs.logFilters
|
|
270
|
+
);
|
|
271
|
+
if (!_.isEmpty(issues)) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`The log filtering rules config '${serverArgs.logFilters}' has issues: ` +
|
|
274
|
+
JSON.stringify(issues, null, 2)
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
if (_.isEmpty(rules)) {
|
|
278
|
+
logger.warn(
|
|
279
|
+
`Found no log filtering rules in '${serverArgs.logFilters}'. Is that expected?`
|
|
280
|
+
);
|
|
281
|
+
} else {
|
|
282
|
+
logger.info(
|
|
283
|
+
`Loaded ${util.pluralize('filtering rule', rules.length, true)} from '${
|
|
284
|
+
serverArgs.logFilters
|
|
285
|
+
}'`
|
|
286
|
+
);
|
|
287
|
+
}
|
|
126
288
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
289
|
+
|
|
290
|
+
const appiumDriver = new AppiumDriver(
|
|
291
|
+
/** @type {import('@appium/types').DriverOpts<import('./appium').AppiumDriverConstraints>} */ (
|
|
292
|
+
serverArgs
|
|
293
|
+
)
|
|
294
|
+
);
|
|
295
|
+
// set the config on the umbrella driver so it can match drivers to caps
|
|
296
|
+
appiumDriver.driverConfig = driverConfig;
|
|
297
|
+
await preflightChecks(serverArgs, throwInsteadOfExit);
|
|
298
|
+
|
|
299
|
+
return /** @type {InitResult<Cmd>} */ ({
|
|
300
|
+
appiumDriver,
|
|
301
|
+
parsedArgs: serverArgs,
|
|
302
|
+
driverConfig,
|
|
303
|
+
pluginConfig,
|
|
304
|
+
});
|
|
305
|
+
} else {
|
|
306
|
+
if (isExtensionCommandArgs(preConfigArgs)) {
|
|
307
|
+
// if the user has requested the 'driver' CLI, don't run the normal server,
|
|
308
|
+
// but instead pass control to the driver CLI
|
|
309
|
+
if (isDriverCommandArgs(preConfigArgs)) {
|
|
310
|
+
await runExtensionCommand(preConfigArgs, driverConfig);
|
|
311
|
+
}
|
|
312
|
+
if (isPluginCommandArgs(preConfigArgs)) {
|
|
313
|
+
await runExtensionCommand(preConfigArgs, pluginConfig);
|
|
314
|
+
}
|
|
131
315
|
}
|
|
316
|
+
return /** @type {InitResult<Cmd>} */ ({});
|
|
132
317
|
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Initializes Appium's config. Starts server if appropriate and resolves the
|
|
322
|
+
* server instance if so; otherwise resolves w/ `undefined`.
|
|
323
|
+
* @template {CliCommand} [Cmd=ServerCommand]
|
|
324
|
+
* @template {CliExtensionSubcommand|void} [SubCmd=void]
|
|
325
|
+
* @param {Args<Cmd, SubCmd>} [args] - Arguments from CLI or otherwise
|
|
326
|
+
* @returns {Promise<Cmd extends ServerCommand ? import('@appium/types').AppiumServer : void>}
|
|
327
|
+
*/
|
|
328
|
+
async function main(args) {
|
|
329
|
+
const initResult = await init(args);
|
|
330
|
+
|
|
331
|
+
if (_.isEmpty(initResult)) {
|
|
332
|
+
// if this branch is taken, we've run a different subcommand, so there's nothing
|
|
333
|
+
// left to do here.
|
|
334
|
+
return /** @type {Cmd extends ServerCommand ? import('@appium/types').AppiumServer : void} */ (
|
|
335
|
+
undefined
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const {appiumDriver, pluginConfig, driverConfig, parsedArgs} =
|
|
340
|
+
/** @type {InitResult<ServerCommand>} */ (initResult);
|
|
341
|
+
|
|
342
|
+
const pluginClasses = getActivePlugins(pluginConfig, parsedArgs.usePlugins);
|
|
343
|
+
// set the active plugins on the umbrella driver so it can use them for commands
|
|
344
|
+
appiumDriver.pluginClasses = pluginClasses;
|
|
133
345
|
|
|
134
|
-
|
|
135
|
-
const driverConfig = new DriverConfig(args.appiumHome);
|
|
136
|
-
const pluginConfig = new PluginConfig(args.appiumHome);
|
|
137
|
-
appiumDriver.driverConfig = driverConfig;
|
|
138
|
-
await preflightChecks({parser, args, driverConfig, pluginConfig, throwInsteadOfExit});
|
|
139
|
-
await logStartupInfo(parser, args);
|
|
346
|
+
await logStartupInfo(parsedArgs);
|
|
140
347
|
let routeConfiguringFunction = makeRouter(appiumDriver);
|
|
141
348
|
|
|
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;
|
|
349
|
+
const driverClasses = getActiveDrivers(driverConfig, parsedArgs.useDrivers);
|
|
350
|
+
const serverUpdaters = getServerUpdaters(driverClasses, pluginClasses);
|
|
351
|
+
const extraMethodMap = getExtraMethodMap(driverClasses, pluginClasses);
|
|
160
352
|
|
|
353
|
+
/** @type {import('@appium/base-driver').ServerOpts} */
|
|
161
354
|
const serverOpts = {
|
|
162
355
|
routeConfiguringFunction,
|
|
163
|
-
port:
|
|
164
|
-
hostname:
|
|
165
|
-
allowCors:
|
|
166
|
-
basePath:
|
|
167
|
-
|
|
356
|
+
port: parsedArgs.port,
|
|
357
|
+
hostname: parsedArgs.address,
|
|
358
|
+
allowCors: parsedArgs.allowCors,
|
|
359
|
+
basePath: parsedArgs.basePath,
|
|
360
|
+
serverUpdaters,
|
|
361
|
+
extraMethodMap,
|
|
362
|
+
cliArgs: parsedArgs,
|
|
168
363
|
};
|
|
169
|
-
if (
|
|
170
|
-
serverOpts.keepAliveTimeout =
|
|
364
|
+
if (parsedArgs.keepAliveTimeout) {
|
|
365
|
+
serverOpts.keepAliveTimeout = parsedArgs.keepAliveTimeout * 1000;
|
|
171
366
|
}
|
|
172
|
-
let server
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
367
|
+
let server;
|
|
368
|
+
try {
|
|
369
|
+
server = await baseServer(serverOpts);
|
|
370
|
+
} catch (err) {
|
|
371
|
+
logger.error(
|
|
372
|
+
`Could not configure Appium server. It's possible that a driver or plugin tried ` +
|
|
373
|
+
`to update the server and failed. Original error: ${err.message}`
|
|
374
|
+
);
|
|
375
|
+
logger.debug(err.stack);
|
|
376
|
+
return process.exit(1);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (parsedArgs.allowCors) {
|
|
380
|
+
logger.warn(
|
|
381
|
+
'You have enabled CORS requests from any host. Be careful not ' +
|
|
382
|
+
'to visit sites which could maliciously try to start Appium ' +
|
|
383
|
+
'sessions on your machine'
|
|
384
|
+
);
|
|
177
385
|
}
|
|
178
386
|
appiumDriver.server = server;
|
|
179
387
|
try {
|
|
180
|
-
// TODO prelaunch if args.launch is set
|
|
181
|
-
// TODO: startAlertSocket(server, appiumServer);
|
|
182
|
-
|
|
183
388
|
// configure as node on grid, if necessary
|
|
184
|
-
|
|
185
|
-
|
|
389
|
+
// falsy values should not cause this to run
|
|
390
|
+
if (parsedArgs.nodeconfig) {
|
|
391
|
+
await registerNode(
|
|
392
|
+
parsedArgs.nodeconfig,
|
|
393
|
+
parsedArgs.address,
|
|
394
|
+
parsedArgs.port,
|
|
395
|
+
parsedArgs.basePath
|
|
396
|
+
);
|
|
186
397
|
}
|
|
187
398
|
} catch (err) {
|
|
188
399
|
await server.close();
|
|
@@ -190,7 +401,7 @@ async function main (args = null) {
|
|
|
190
401
|
}
|
|
191
402
|
|
|
192
403
|
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
193
|
-
process.once(signal, async function onSignal
|
|
404
|
+
process.once(signal, async function onSignal() {
|
|
194
405
|
logger.info(`Received ${signal} - shutting down`);
|
|
195
406
|
try {
|
|
196
407
|
await appiumDriver.deleteAllSessions({
|
|
@@ -206,15 +417,69 @@ async function main (args = null) {
|
|
|
206
417
|
});
|
|
207
418
|
}
|
|
208
419
|
|
|
209
|
-
|
|
420
|
+
logger.info(
|
|
421
|
+
`Appium REST http interface listener started on ${parsedArgs.address}:${parsedArgs.port}${parsedArgs.basePath}`
|
|
422
|
+
);
|
|
423
|
+
|
|
210
424
|
driverConfig.print();
|
|
211
|
-
pluginConfig.print(
|
|
425
|
+
pluginConfig.print([...pluginClasses.values()]);
|
|
212
426
|
|
|
213
|
-
return
|
|
427
|
+
return /** @type {Cmd extends ServerCommand ? import('@appium/types').AppiumServer : void} */ (
|
|
428
|
+
server
|
|
429
|
+
);
|
|
214
430
|
}
|
|
215
431
|
|
|
432
|
+
// NOTE: this is here for backwards compat for any scripts referencing `main.js` directly
|
|
433
|
+
// (more specifically, `build/lib/main.js`)
|
|
434
|
+
// the executable is now `../index.js`, so that module will typically be `require.main`.
|
|
216
435
|
if (require.main === module) {
|
|
217
436
|
asyncify(main);
|
|
218
437
|
}
|
|
219
438
|
|
|
220
|
-
|
|
439
|
+
// everything below here is intended to be a public API.
|
|
440
|
+
export {readConfigFile} from './config-file';
|
|
441
|
+
export {finalizeSchema, getSchema, validate} from './schema/schema';
|
|
442
|
+
export {main, init, resolveAppiumHome};
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* @typedef {import('@appium/types').DriverType} DriverType
|
|
446
|
+
* @typedef {import('@appium/types').PluginType} PluginType
|
|
447
|
+
* @typedef {import('@appium/types').DriverClass} DriverClass
|
|
448
|
+
* @typedef {import('@appium/types').PluginClass} PluginClass
|
|
449
|
+
* @typedef {import('appium/types').CliCommand} CliCommand
|
|
450
|
+
* @typedef {import('appium/types').CliExtensionSubcommand} CliExtensionSubcommand
|
|
451
|
+
* @typedef {import('appium/types').CliExtensionCommand} CliExtensionCommand
|
|
452
|
+
* @typedef {import('appium/types').CliCommandServer} ServerCommand
|
|
453
|
+
* @typedef {import('appium/types').CliCommandDriver} DriverCommand
|
|
454
|
+
* @typedef {import('appium/types').CliCommandPlugin} PluginCommand
|
|
455
|
+
* @typedef {import('./extension').DriverNameMap} DriverNameMap
|
|
456
|
+
* @typedef {import('./extension').PluginNameMap} PluginNameMap
|
|
457
|
+
*/
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Literally an empty object
|
|
461
|
+
* @typedef { {} } ExtCommandInitResult
|
|
462
|
+
*/
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* @typedef ServerInitData
|
|
466
|
+
* @property {import('./appium').AppiumDriver} appiumDriver - The Appium driver
|
|
467
|
+
* @property {import('appium/types').ParsedArgs} parsedArgs - The parsed arguments
|
|
468
|
+
*/
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* @template {CliCommand} Cmd
|
|
472
|
+
* @typedef {Cmd extends ServerCommand ? ServerInitData & import('./extension').ExtensionConfigs : ExtCommandInitResult} InitResult
|
|
473
|
+
*/
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* @template {CliCommand} [Cmd=ServerCommand]
|
|
477
|
+
* @template {CliExtensionSubcommand|void} [SubCmd=void]
|
|
478
|
+
* @typedef {import('appium/types').Args<Cmd, SubCmd>} Args
|
|
479
|
+
*/
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* @template {CliCommand} [Cmd=ServerCommand]
|
|
483
|
+
* @template {CliExtensionSubcommand|void} [SubCmd=void]
|
|
484
|
+
* @typedef {import('appium/types').ParsedArgs<Cmd, SubCmd>} ParsedArgs
|
|
485
|
+
*/
|