appium 3.2.2 → 3.3.1
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/build/lib/appium.d.ts +147 -205
- package/build/lib/appium.d.ts.map +1 -1
- package/build/lib/appium.js +169 -282
- package/build/lib/appium.js.map +1 -1
- package/build/lib/bidi-commands.d.ts.map +1 -1
- package/build/lib/bidi-commands.js +11 -11
- package/build/lib/bidi-commands.js.map +1 -1
- package/build/lib/bootstrap/appium-initializer.d.ts +21 -0
- package/build/lib/bootstrap/appium-initializer.d.ts.map +1 -0
- package/build/lib/bootstrap/appium-initializer.js +146 -0
- package/build/lib/bootstrap/appium-initializer.js.map +1 -0
- package/build/lib/bootstrap/appium-main-runner.d.ts +22 -0
- package/build/lib/bootstrap/appium-main-runner.d.ts.map +1 -0
- package/build/lib/bootstrap/appium-main-runner.js +109 -0
- package/build/lib/bootstrap/appium-main-runner.js.map +1 -0
- package/build/lib/bootstrap/config-file.d.ts +37 -0
- package/build/lib/bootstrap/config-file.d.ts.map +1 -0
- package/build/lib/{config-file.js → bootstrap/config-file.js} +62 -138
- package/build/lib/bootstrap/config-file.js.map +1 -0
- package/build/lib/bootstrap/grid-v3-register.d.ts +20 -0
- package/build/lib/bootstrap/grid-v3-register.d.ts.map +1 -0
- package/build/lib/bootstrap/grid-v3-register.js +185 -0
- package/build/lib/bootstrap/grid-v3-register.js.map +1 -0
- package/build/lib/bootstrap/init-types.d.ts +16 -0
- package/build/lib/bootstrap/init-types.d.ts.map +1 -0
- package/build/lib/bootstrap/init-types.js +3 -0
- package/build/lib/bootstrap/init-types.js.map +1 -0
- package/build/lib/bootstrap/main-helpers.d.ts +55 -0
- package/build/lib/bootstrap/main-helpers.d.ts.map +1 -0
- package/build/lib/bootstrap/main-helpers.js +187 -0
- package/build/lib/bootstrap/main-helpers.js.map +1 -0
- package/build/lib/bootstrap/node-helpers.d.ts +32 -0
- package/build/lib/bootstrap/node-helpers.d.ts.map +1 -0
- package/build/lib/bootstrap/node-helpers.js +201 -0
- package/build/lib/bootstrap/node-helpers.js.map +1 -0
- package/build/lib/bootstrap/startup-config.d.ts +22 -0
- package/build/lib/bootstrap/startup-config.d.ts.map +1 -0
- package/build/lib/bootstrap/startup-config.js +111 -0
- package/build/lib/bootstrap/startup-config.js.map +1 -0
- package/build/lib/cli/args.d.ts +16 -12
- package/build/lib/cli/args.d.ts.map +1 -1
- package/build/lib/cli/args.js +20 -40
- package/build/lib/cli/args.js.map +1 -1
- package/build/lib/cli/driver-command.d.ts +51 -93
- package/build/lib/cli/driver-command.d.ts.map +1 -1
- package/build/lib/cli/driver-command.js +11 -66
- package/build/lib/cli/driver-command.js.map +1 -1
- package/build/lib/cli/extension-command.d.ts +173 -377
- package/build/lib/cli/extension-command.d.ts.map +1 -1
- package/build/lib/cli/extension-command.js +387 -656
- package/build/lib/cli/extension-command.js.map +1 -1
- package/build/lib/cli/extension.d.ts +10 -15
- package/build/lib/cli/extension.d.ts.map +1 -1
- package/build/lib/cli/extension.js +15 -33
- package/build/lib/cli/extension.js.map +1 -1
- package/build/lib/cli/parser.d.ts +37 -66
- package/build/lib/cli/parser.d.ts.map +1 -1
- package/build/lib/cli/parser.js +69 -104
- package/build/lib/cli/parser.js.map +1 -1
- package/build/lib/cli/plugin-command.d.ts +50 -90
- package/build/lib/cli/plugin-command.d.ts.map +1 -1
- package/build/lib/cli/plugin-command.js +11 -63
- package/build/lib/cli/plugin-command.js.map +1 -1
- package/build/lib/cli/setup-command.d.ts +21 -26
- package/build/lib/cli/setup-command.d.ts.map +1 -1
- package/build/lib/cli/setup-command.js +19 -61
- package/build/lib/cli/setup-command.js.map +1 -1
- package/build/lib/cli/utils.d.ts +33 -35
- package/build/lib/cli/utils.d.ts.map +1 -1
- package/build/lib/cli/utils.js +48 -50
- package/build/lib/cli/utils.js.map +1 -1
- package/build/lib/constants.d.ts +23 -23
- package/build/lib/constants.d.ts.map +1 -1
- package/build/lib/constants.js +10 -15
- package/build/lib/constants.js.map +1 -1
- package/build/lib/doctor/doctor.d.ts +40 -57
- package/build/lib/doctor/doctor.d.ts.map +1 -1
- package/build/lib/doctor/doctor.js +31 -62
- package/build/lib/doctor/doctor.js.map +1 -1
- package/build/lib/extension/driver-config.d.ts +18 -77
- package/build/lib/extension/driver-config.d.ts.map +1 -1
- package/build/lib/extension/driver-config.js +37 -125
- package/build/lib/extension/driver-config.js.map +1 -1
- package/build/lib/extension/extension-config.d.ts +103 -210
- package/build/lib/extension/extension-config.d.ts.map +1 -1
- package/build/lib/extension/extension-config.js +180 -342
- package/build/lib/extension/extension-config.js.map +1 -1
- package/build/lib/extension/index.d.ts +12 -29
- package/build/lib/extension/index.d.ts.map +1 -1
- package/build/lib/extension/index.js +33 -75
- package/build/lib/extension/index.js.map +1 -1
- package/build/lib/extension/manifest-migrations.d.ts +3 -20
- package/build/lib/extension/manifest-migrations.d.ts.map +1 -1
- package/build/lib/extension/manifest-migrations.js +20 -101
- package/build/lib/extension/manifest-migrations.js.map +1 -1
- package/build/lib/extension/manifest.d.ts +61 -107
- package/build/lib/extension/manifest.d.ts.map +1 -1
- package/build/lib/extension/manifest.js +181 -356
- package/build/lib/extension/manifest.js.map +1 -1
- package/build/lib/extension/package-changed.d.ts +1 -3
- package/build/lib/extension/package-changed.d.ts.map +1 -1
- package/build/lib/extension/package-changed.js +8 -15
- package/build/lib/extension/package-changed.js.map +1 -1
- package/build/lib/extension/plugin-config.d.ts +10 -52
- package/build/lib/extension/plugin-config.d.ts.map +1 -1
- package/build/lib/extension/plugin-config.js +11 -63
- package/build/lib/extension/plugin-config.js.map +1 -1
- package/build/lib/helpers/build.d.ts +22 -0
- package/build/lib/helpers/build.d.ts.map +1 -0
- package/build/lib/helpers/build.js +109 -0
- package/build/lib/helpers/build.js.map +1 -0
- package/build/lib/helpers/capability.d.ts +38 -0
- package/build/lib/helpers/capability.d.ts.map +1 -0
- package/build/lib/helpers/capability.js +128 -0
- package/build/lib/helpers/capability.js.map +1 -0
- package/build/lib/helpers/network.d.ts +14 -0
- package/build/lib/helpers/network.d.ts.map +1 -0
- package/build/lib/helpers/network.js +35 -0
- package/build/lib/helpers/network.js.map +1 -0
- package/build/lib/insecure-features.js +6 -6
- package/build/lib/insecure-features.js.map +1 -1
- package/build/lib/inspector-commands.d.ts +6 -0
- package/build/lib/inspector-commands.d.ts.map +1 -1
- package/build/lib/inspector-commands.js +6 -0
- package/build/lib/inspector-commands.js.map +1 -1
- package/build/lib/logger.d.ts +2 -3
- package/build/lib/logger.d.ts.map +1 -1
- package/build/lib/logger.js +2 -3
- package/build/lib/logger.js.map +1 -1
- package/build/lib/logsink.d.ts +13 -22
- package/build/lib/logsink.d.ts.map +1 -1
- package/build/lib/logsink.js +48 -103
- package/build/lib/logsink.js.map +1 -1
- package/build/lib/main.d.ts +15 -58
- package/build/lib/main.d.ts.map +1 -1
- package/build/lib/main.js +25 -425
- package/build/lib/main.js.map +1 -1
- package/build/lib/schema/arg-spec.d.ts +32 -107
- package/build/lib/schema/arg-spec.d.ts.map +1 -1
- package/build/lib/schema/arg-spec.js +11 -107
- package/build/lib/schema/arg-spec.js.map +1 -1
- package/build/lib/schema/cli-args-guards.d.ts +34 -0
- package/build/lib/schema/cli-args-guards.d.ts.map +1 -0
- package/build/lib/schema/cli-args-guards.js +49 -0
- package/build/lib/schema/cli-args-guards.js.map +1 -0
- package/build/lib/schema/cli-args.d.ts +3 -15
- package/build/lib/schema/cli-args.d.ts.map +1 -1
- package/build/lib/schema/cli-args.js +17 -107
- package/build/lib/schema/cli-args.js.map +1 -1
- package/build/lib/schema/cli-transformers.d.ts +15 -12
- package/build/lib/schema/cli-transformers.d.ts.map +1 -1
- package/build/lib/schema/cli-transformers.js +15 -45
- package/build/lib/schema/cli-transformers.js.map +1 -1
- package/build/lib/schema/format-errors.d.ts +28 -0
- package/build/lib/schema/format-errors.d.ts.map +1 -0
- package/build/lib/schema/format-errors.js +29 -0
- package/build/lib/schema/format-errors.js.map +1 -0
- package/build/lib/schema/index.d.ts +4 -2
- package/build/lib/schema/index.d.ts.map +1 -1
- package/build/lib/schema/index.js +2 -0
- package/build/lib/schema/index.js.map +1 -1
- package/build/lib/schema/keywords.d.ts +12 -20
- package/build/lib/schema/keywords.d.ts.map +1 -1
- package/build/lib/schema/keywords.js +6 -51
- package/build/lib/schema/keywords.js.map +1 -1
- package/build/lib/schema/schema.d.ts +106 -231
- package/build/lib/schema/schema.d.ts.map +1 -1
- package/build/lib/schema/schema.js +88 -358
- package/build/lib/schema/schema.js.map +1 -1
- package/build/lib/utils.d.ts +7 -267
- package/build/lib/utils.d.ts.map +1 -1
- package/build/lib/utils.js +10 -409
- package/build/lib/utils.js.map +1 -1
- package/lib/{appium.js → appium.ts} +297 -341
- package/lib/bidi-commands.ts +10 -14
- package/lib/bootstrap/appium-initializer.ts +212 -0
- package/lib/bootstrap/appium-main-runner.ts +172 -0
- package/lib/bootstrap/config-file.ts +178 -0
- package/lib/bootstrap/grid-v3-register.ts +250 -0
- package/lib/bootstrap/init-types.ts +31 -0
- package/lib/bootstrap/main-helpers.ts +223 -0
- package/lib/bootstrap/node-helpers.ts +180 -0
- package/lib/bootstrap/startup-config.ts +143 -0
- package/lib/cli/{args.js → args.ts} +45 -56
- package/lib/cli/driver-command.ts +122 -0
- package/lib/cli/{extension-command.js → extension-command.ts} +827 -906
- package/lib/cli/extension.ts +65 -0
- package/lib/cli/{parser.js → parser.ts} +93 -116
- package/lib/cli/plugin-command.ts +117 -0
- package/lib/cli/{setup-command.js → setup-command.ts} +59 -74
- package/lib/cli/utils.ts +97 -0
- package/lib/{constants.js → constants.ts} +30 -41
- package/lib/doctor/{doctor.js → doctor.ts} +82 -92
- package/lib/extension/driver-config.ts +165 -0
- package/lib/extension/{extension-config.js → extension-config.ts} +291 -405
- package/lib/extension/index.ts +143 -0
- package/lib/extension/manifest-migrations.ts +57 -0
- package/lib/extension/manifest.ts +369 -0
- package/lib/extension/{package-changed.js → package-changed.ts} +9 -18
- package/lib/extension/plugin-config.ts +62 -0
- package/lib/helpers/build.ts +111 -0
- package/lib/helpers/capability.ts +171 -0
- package/lib/helpers/network.ts +30 -0
- package/lib/insecure-features.ts +1 -1
- package/lib/inspector-commands.ts +6 -1
- package/lib/{logger.js → logger.ts} +1 -2
- package/lib/{logsink.js → logsink.ts} +91 -137
- package/lib/main.ts +60 -0
- package/lib/schema/arg-spec.ts +131 -0
- package/lib/schema/cli-args-guards.ts +67 -0
- package/lib/schema/cli-args.ts +171 -0
- package/lib/schema/cli-transformers.ts +83 -0
- package/lib/schema/format-errors.ts +43 -0
- package/lib/schema/index.ts +4 -0
- package/lib/schema/keywords.ts +96 -0
- package/lib/schema/schema.ts +448 -0
- package/lib/utils.ts +73 -0
- package/package.json +17 -18
- package/scripts/autoinstall-extensions.js +3 -0
- package/build/lib/config-file.d.ts +0 -100
- package/build/lib/config-file.d.ts.map +0 -1
- package/build/lib/config-file.js.map +0 -1
- package/build/lib/config.d.ts +0 -70
- package/build/lib/config.d.ts.map +0 -1
- package/build/lib/config.js +0 -390
- package/build/lib/config.js.map +0 -1
- package/build/lib/grid-register.d.ts +0 -10
- package/build/lib/grid-register.d.ts.map +0 -1
- package/build/lib/grid-register.js +0 -134
- package/build/lib/grid-register.js.map +0 -1
- package/lib/cli/driver-command.js +0 -174
- package/lib/cli/extension.js +0 -74
- package/lib/cli/plugin-command.js +0 -164
- package/lib/cli/utils.js +0 -91
- package/lib/config-file.js +0 -228
- package/lib/config.js +0 -389
- package/lib/extension/driver-config.js +0 -245
- package/lib/extension/index.js +0 -169
- package/lib/extension/manifest-migrations.js +0 -136
- package/lib/extension/manifest.js +0 -550
- package/lib/extension/plugin-config.js +0 -112
- package/lib/grid-register.js +0 -146
- package/lib/main.js +0 -545
- package/lib/schema/arg-spec.js +0 -229
- package/lib/schema/cli-args.js +0 -254
- package/lib/schema/cli-transformers.js +0 -113
- package/lib/schema/index.js +0 -2
- package/lib/schema/keywords.js +0 -136
- package/lib/schema/schema.js +0 -725
- package/lib/utils.js +0 -512
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import {exec} from 'teen_process';
|
|
4
|
+
import {system, fs} from '@appium/support';
|
|
5
|
+
import type {BuildInfo} from 'appium/types';
|
|
6
|
+
import {npmPackage} from '../utils';
|
|
7
|
+
|
|
8
|
+
export const APPIUM_VER = npmPackage.version;
|
|
9
|
+
export const rootDir = fs.findRoot(__dirname);
|
|
10
|
+
|
|
11
|
+
const GIT_BINARY = `git${system.isWindows() ? '.exe' : ''}`;
|
|
12
|
+
const GITHUB_API = 'https://api.github.com/repos/appium/appium';
|
|
13
|
+
|
|
14
|
+
const getFullGitPath = _.memoize(async function getFullGitPath(): Promise<string | null> {
|
|
15
|
+
try {
|
|
16
|
+
return await fs.which(GIT_BINARY);
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns the current git commit SHA for this Appium checkout.
|
|
24
|
+
*
|
|
25
|
+
* Attempts to read from local git first; when unavailable and fallback is enabled,
|
|
26
|
+
* queries the GitHub API for the tag matching the current Appium version.
|
|
27
|
+
*/
|
|
28
|
+
export async function getGitRev(useGithubApiFallback = false): Promise<string | null> {
|
|
29
|
+
const fullGitPath = await getFullGitPath();
|
|
30
|
+
if (fullGitPath) {
|
|
31
|
+
try {
|
|
32
|
+
const {stdout} = await exec(fullGitPath, ['rev-parse', 'HEAD'], {
|
|
33
|
+
cwd: __dirname,
|
|
34
|
+
});
|
|
35
|
+
return stdout.trim();
|
|
36
|
+
} catch {}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!useGithubApiFallback) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// If the package folder is not a valid git repository
|
|
44
|
+
// then fetch the corresponding tag info from GitHub
|
|
45
|
+
try {
|
|
46
|
+
return (
|
|
47
|
+
await axios.get(`${GITHUB_API}/git/refs/tags/appium@${APPIUM_VER}`, {
|
|
48
|
+
headers: {
|
|
49
|
+
'User-Agent': `Appium ${APPIUM_VER}`,
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
).data?.object?.sha;
|
|
53
|
+
} catch {}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function getGitTimestamp(commitSha: string, useGithubApiFallback = false): Promise<string | null> {
|
|
58
|
+
const fullGitPath = await getFullGitPath();
|
|
59
|
+
if (fullGitPath) {
|
|
60
|
+
try {
|
|
61
|
+
const {stdout} = await exec(fullGitPath, ['show', '-s', '--format=%ci', commitSha], {
|
|
62
|
+
cwd: __dirname,
|
|
63
|
+
});
|
|
64
|
+
return stdout.trim();
|
|
65
|
+
} catch {}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!useGithubApiFallback) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
return (
|
|
74
|
+
await axios.get(`${GITHUB_API}/git/tags/${commitSha}`, {
|
|
75
|
+
headers: {
|
|
76
|
+
'User-Agent': `Appium ${APPIUM_VER}`,
|
|
77
|
+
},
|
|
78
|
+
})
|
|
79
|
+
).data?.tagger?.date;
|
|
80
|
+
} catch {}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const BUILD_INFO: BuildInfo = {
|
|
85
|
+
version: APPIUM_VER,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Update mutable build info metadata from local git or GitHub fallback.
|
|
90
|
+
*/
|
|
91
|
+
export async function updateBuildInfo(useGithubApiFallback = false): Promise<void> {
|
|
92
|
+
const sha = await getGitRev(useGithubApiFallback);
|
|
93
|
+
if (!sha) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
BUILD_INFO['git-sha'] = sha;
|
|
97
|
+
const buildTimestamp = await getGitTimestamp(sha, useGithubApiFallback);
|
|
98
|
+
if (buildTimestamp) {
|
|
99
|
+
BUILD_INFO.built = buildTimestamp;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Mutable object containing Appium build information. By default it
|
|
105
|
+
* only contains the Appium version, but is updated with the build timestamp
|
|
106
|
+
* and git commit hash asynchronously as soon as `updateBuildInfo` is called
|
|
107
|
+
* and succeeds.
|
|
108
|
+
*/
|
|
109
|
+
export function getBuildInfo(): BuildInfo {
|
|
110
|
+
return BUILD_INFO;
|
|
111
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BaseDriverCapConstraints,
|
|
3
|
+
Capabilities,
|
|
4
|
+
Constraints,
|
|
5
|
+
NSCapabilities,
|
|
6
|
+
W3CCapabilities,
|
|
7
|
+
} from '@appium/types';
|
|
8
|
+
import _ from 'lodash';
|
|
9
|
+
import {log as logger} from '../logger';
|
|
10
|
+
import {
|
|
11
|
+
processCapabilities,
|
|
12
|
+
STANDARD_CAPS,
|
|
13
|
+
errors,
|
|
14
|
+
isW3cCaps,
|
|
15
|
+
} from '@appium/base-driver';
|
|
16
|
+
|
|
17
|
+
const W3C_APPIUM_PREFIX = 'appium';
|
|
18
|
+
const STANDARD_CAPS_LOWERCASE = new Set([...STANDARD_CAPS].map((cap) => cap.toLowerCase()));
|
|
19
|
+
|
|
20
|
+
/** Result of successfully parsing W3C capabilities for the inner driver. */
|
|
21
|
+
export interface ParsedDriverCaps<C extends Constraints = BaseDriverCapConstraints> {
|
|
22
|
+
desiredCaps: Capabilities<C>;
|
|
23
|
+
processedW3CCapabilities: W3CCapabilities<C>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Result when capability parsing fails or caps are invalid. */
|
|
27
|
+
export interface InvalidCaps<C extends Constraints = BaseDriverCapConstraints> {
|
|
28
|
+
error: Error;
|
|
29
|
+
desiredCaps?: Capabilities<C>;
|
|
30
|
+
processedW3CCapabilities?: W3CCapabilities<C>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Creates an error when a session receives non-W3C capabilities.
|
|
35
|
+
*/
|
|
36
|
+
export function makeNonW3cCapsError(): Error {
|
|
37
|
+
return new errors.SessionNotCreatedError(
|
|
38
|
+
'Session capabilities format must comply to the W3C standard. Make sure your client is up to date. ' +
|
|
39
|
+
'See https://www.w3.org/TR/webdriver/#new-session for more details.'
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Parses W3C capabilities for the inner driver and applies defaults.
|
|
45
|
+
*
|
|
46
|
+
* @returns Parsed caps or an invalid result with an error.
|
|
47
|
+
*/
|
|
48
|
+
export function parseCapsForInnerDriver<C extends Constraints = BaseDriverCapConstraints>(
|
|
49
|
+
w3cCapabilities: W3CCapabilities<C>,
|
|
50
|
+
constraints: C = {} as C,
|
|
51
|
+
defaultCapabilities: NSCapabilities<C> = {}
|
|
52
|
+
): ParsedDriverCaps<C> | InvalidCaps<C> {
|
|
53
|
+
if (!isW3cCaps(w3cCapabilities)) {
|
|
54
|
+
return {error: makeNonW3cCapsError()};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let desiredCaps: Capabilities<C> = {} as Capabilities<C>;
|
|
58
|
+
// eslint-disable-next-line prefer-const -- assigned in success path after try
|
|
59
|
+
let processedW3CCapabilities: W3CCapabilities<C> | undefined;
|
|
60
|
+
|
|
61
|
+
w3cCapabilities = _.cloneDeep(w3cCapabilities);
|
|
62
|
+
defaultCapabilities = _.cloneDeep(defaultCapabilities);
|
|
63
|
+
|
|
64
|
+
if (!_.isEmpty(defaultCapabilities)) {
|
|
65
|
+
for (const [defaultCapKey, defaultCapValue] of _.toPairs(defaultCapabilities)) {
|
|
66
|
+
let isCapAlreadySet = false;
|
|
67
|
+
for (const firstMatchEntry of w3cCapabilities.firstMatch ?? []) {
|
|
68
|
+
if (
|
|
69
|
+
_.isPlainObject(firstMatchEntry) &&
|
|
70
|
+
_.has(removeAppiumPrefixes(firstMatchEntry as NSCapabilities<C>), removeAppiumPrefix(defaultCapKey))
|
|
71
|
+
) {
|
|
72
|
+
isCapAlreadySet = true;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
isCapAlreadySet =
|
|
77
|
+
isCapAlreadySet ||
|
|
78
|
+
(_.isPlainObject(w3cCapabilities.alwaysMatch) &&
|
|
79
|
+
_.has(
|
|
80
|
+
removeAppiumPrefixes(w3cCapabilities.alwaysMatch),
|
|
81
|
+
removeAppiumPrefix(defaultCapKey)
|
|
82
|
+
));
|
|
83
|
+
if (isCapAlreadySet) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (_.isEmpty(w3cCapabilities.firstMatch)) {
|
|
88
|
+
w3cCapabilities.firstMatch = [{[defaultCapKey]: defaultCapValue}] as W3CCapabilities<C>['firstMatch'];
|
|
89
|
+
} else {
|
|
90
|
+
(w3cCapabilities.firstMatch[0] as Record<string, unknown>)[defaultCapKey] = defaultCapValue;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
desiredCaps = processCapabilities(w3cCapabilities, constraints, true) as Capabilities<C>;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
logger.info(`Could not parse W3C capabilities: ${(error as Error).message}`);
|
|
99
|
+
return {
|
|
100
|
+
desiredCaps,
|
|
101
|
+
processedW3CCapabilities,
|
|
102
|
+
error: error as Error,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
processedW3CCapabilities = {
|
|
107
|
+
alwaysMatch: {...insertAppiumPrefixes(desiredCaps)},
|
|
108
|
+
firstMatch: [{}],
|
|
109
|
+
} as W3CCapabilities<C>;
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
desiredCaps,
|
|
113
|
+
processedW3CCapabilities,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Prefixes capability keys with `appium:` where appropriate.
|
|
119
|
+
*/
|
|
120
|
+
export function insertAppiumPrefixes<C extends Constraints = BaseDriverCapConstraints>(
|
|
121
|
+
caps: Capabilities<C>
|
|
122
|
+
): NSCapabilities<C> {
|
|
123
|
+
return _.mapKeys(caps, (_, key) =>
|
|
124
|
+
STANDARD_CAPS_LOWERCASE.has(key.toLowerCase()) || key.includes(':')
|
|
125
|
+
? key
|
|
126
|
+
: `${W3C_APPIUM_PREFIX}:${key}`
|
|
127
|
+
) as NSCapabilities<C>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Removes `appium:` prefix from capability keys.
|
|
132
|
+
*/
|
|
133
|
+
export function removeAppiumPrefixes<C extends Constraints = BaseDriverCapConstraints>(
|
|
134
|
+
caps: NSCapabilities<C>
|
|
135
|
+
): Capabilities<C> {
|
|
136
|
+
return _.mapKeys(caps, (_, key) => removeAppiumPrefix(key)) as Capabilities<C>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Pulls Appium settings from capabilities (mutates caps). Supports
|
|
141
|
+
* `settings[key]: value` and `settings: { key: value }`.
|
|
142
|
+
*
|
|
143
|
+
* @returns Parsed settings object; empty if none found.
|
|
144
|
+
*/
|
|
145
|
+
export function pullSettings(caps: Record<string, unknown> | null | undefined): Record<string, unknown> {
|
|
146
|
+
if (!_.isPlainObject(caps) || _.isEmpty(caps)) {
|
|
147
|
+
return {};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const result: Record<string, unknown> = {};
|
|
151
|
+
const singleSettings: Record<string, unknown> = {};
|
|
152
|
+
for (const [key, value] of _.toPairs(caps)) {
|
|
153
|
+
let match: RegExpExecArray | null;
|
|
154
|
+
if (/^(s|appium:s)ettings$/.test(key) && _.isPlainObject(value)) {
|
|
155
|
+
Object.assign(result, value);
|
|
156
|
+
delete caps[key];
|
|
157
|
+
} else if ((match = /^(s|appium:s)ettings\[(\S+)\]$/.exec(key))) {
|
|
158
|
+
singleSettings[match[2]] = value;
|
|
159
|
+
delete caps[key];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (!_.isEmpty(singleSettings)) {
|
|
163
|
+
Object.assign(result, singleSettings);
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function removeAppiumPrefix(key: string): string {
|
|
169
|
+
const prefix = `${W3C_APPIUM_PREFIX}:`;
|
|
170
|
+
return _.startsWith(key, prefix) ? key.substring(prefix.length) : key;
|
|
171
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
|
|
4
|
+
export const V4_BROADCAST_IP = '0.0.0.0';
|
|
5
|
+
export const V6_BROADCAST_IP = '::';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns network interfaces for the given IP family.
|
|
9
|
+
*
|
|
10
|
+
* @param family - 4 for IPv4, 6 for IPv6, or null for all.
|
|
11
|
+
*/
|
|
12
|
+
export function fetchInterfaces(family: 4 | 6 | null = null): os.NetworkInterfaceInfo[] {
|
|
13
|
+
let familyValue: (4 | 6 | string)[] | null = null;
|
|
14
|
+
if (family === 4) {
|
|
15
|
+
familyValue = [4, 'IPv4'];
|
|
16
|
+
} else if (family === 6) {
|
|
17
|
+
familyValue = [6, 'IPv6'];
|
|
18
|
+
}
|
|
19
|
+
const ifaces = _.values(os.networkInterfaces()).filter(Boolean) as os.NetworkInterfaceInfo[][];
|
|
20
|
+
return _.flatMap(ifaces).filter(
|
|
21
|
+
(info) => !familyValue || familyValue.includes(info.family as 4 | 6 | string)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns true if the address is a broadcast IP (0.0.0.0 or ::).
|
|
27
|
+
*/
|
|
28
|
+
export function isBroadcastIp(address: string): boolean {
|
|
29
|
+
return [V4_BROADCAST_IP, V6_BROADCAST_IP, `[${V6_BROADCAST_IP}]`].includes(address);
|
|
30
|
+
}
|
package/lib/insecure-features.ts
CHANGED
|
@@ -21,7 +21,9 @@ import type {
|
|
|
21
21
|
} from '@appium/types';
|
|
22
22
|
import type {AppiumDriver} from './appium';
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Returns available REST and BiDi commands for base, driver and plugins.
|
|
26
|
+
*/
|
|
25
27
|
export async function listCommands(this: AppiumDriver, sessionId?: string): Promise<ListCommandsResponse> {
|
|
26
28
|
let driverRestMethodMap: MethodMap<any> = {};
|
|
27
29
|
let driverBiDiCommands: BidiModuleMap = {};
|
|
@@ -46,6 +48,9 @@ export async function listCommands(this: AppiumDriver, sessionId?: string): Prom
|
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Returns available execute methods exposed by driver and plugins.
|
|
53
|
+
*/
|
|
49
54
|
export async function listExtensions(this: AppiumDriver, sessionId?: string): Promise<ListExtensionsResponse> {
|
|
50
55
|
let driverExecuteMethodMap: ExecuteMethodMap<any> = {};
|
|
51
56
|
let pluginExecuteMethodMaps: Record<string, ExecuteMethodMap<any>> = {};
|