appium-chromedriver 8.1.0 → 8.2.0

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.
@@ -12,13 +12,14 @@ export const OS = {
12
12
  LINUX: 'linux',
13
13
  WINDOWS: 'win',
14
14
  MAC: 'mac',
15
- };
15
+ } as const;
16
16
  export const ARCH = {
17
17
  X64: '64',
18
18
  X86: '32',
19
- };
19
+ } as const;
20
20
  export const CPU = {
21
21
  INTEL: 'intel',
22
22
  ARM: 'arm',
23
- };
24
- export const APPLE_ARM_SUFFIXES = ['64_m1', '_arm64'];
23
+ } as const;
24
+ export const APPLE_ARM_SUFFIXES = ['64_m1', '_arm64'] as const;
25
+
@@ -0,0 +1,44 @@
1
+ import _ from 'lodash';
2
+ import {isStandardCap} from '@appium/base-driver';
3
+
4
+ const W3C_PREFIX = 'goog:';
5
+
6
+ /**
7
+ * Converts a capability name to W3C format by adding the 'goog:' prefix if needed.
8
+ * @param capName - The capability name to convert.
9
+ * @returns The W3C-formatted capability name.
10
+ */
11
+ export function toW3cCapName(capName: string): string {
12
+ return (_.isString(capName) && !capName.includes(':') && !isStandardCap(capName))
13
+ ? `${W3C_PREFIX}${capName}`
14
+ : capName;
15
+ }
16
+
17
+ /**
18
+ * Gets a capability value from a capabilities object, handling both standard and W3C format names.
19
+ * @param allCaps - The capabilities object to search in.
20
+ * @param rawCapName - The capability name to look for (can be in either format).
21
+ * @param defaultValue - Optional default value to return if the capability is not found.
22
+ * @returns The capability value or the default value.
23
+ */
24
+ export function getCapValue(allCaps: Record<string, any> = {}, rawCapName: string, defaultValue?: any): any {
25
+ for (const [capName, capValue] of _.toPairs(allCaps)) {
26
+ if (toW3cCapName(capName) === toW3cCapName(rawCapName)) {
27
+ return capValue;
28
+ }
29
+ }
30
+ return defaultValue;
31
+ }
32
+
33
+ /**
34
+ * Converts all capability names in an object to W3C format.
35
+ * @param originalCaps - The original capabilities object.
36
+ * @returns A new object with W3C-formatted capability names.
37
+ */
38
+ export function toW3cCapNames(originalCaps: Record<string, any> = {}): Record<string, any> {
39
+ return _.reduce(originalCaps, (acc, value, key) => {
40
+ acc[toW3cCapName(key)] = value;
41
+ return acc;
42
+ }, {} as Record<string, any>);
43
+ }
44
+
package/lib/utils.ts ADDED
@@ -0,0 +1,185 @@
1
+ import _ from 'lodash';
2
+ import {system, fs, node} from '@appium/support';
3
+ import {BaseDriver} from '@appium/base-driver';
4
+ import path from 'path';
5
+ import {compareVersions} from 'compare-versions';
6
+ import axios from 'axios';
7
+ import os from 'os';
8
+ import {OS, CPU} from './constants';
9
+ import type {ADB} from 'appium-adb';
10
+ import type {ChromedriverVersionMapping, OSInfo} from './types';
11
+
12
+ const CD_EXECUTABLE_PREFIX = 'chromedriver';
13
+ const MODULE_NAME = 'appium-chromedriver';
14
+
15
+ /**
16
+ * Calculates the path to the current module's root folder
17
+ * @returns The full path to module root
18
+ * @throws {Error} If the current module root folder cannot be determined
19
+ */
20
+ const getModuleRoot = _.memoize(function getModuleRoot(): string {
21
+ const root = node.getModuleRootSync(MODULE_NAME, __filename);
22
+ if (!root) {
23
+ throw new Error(`Cannot find the root folder of the ${MODULE_NAME} Node.js module`);
24
+ }
25
+ return root;
26
+ });
27
+
28
+ // Chromedriver version: minimum Chrome version
29
+ export const CHROMEDRIVER_CHROME_MAPPING: ChromedriverVersionMapping = require(path.join(
30
+ getModuleRoot(),
31
+ 'config',
32
+ 'mapping.json'
33
+ ));
34
+ export const CD_BASE_DIR = path.join(getModuleRoot(), 'chromedriver');
35
+
36
+ /**
37
+ * Gets the most recent Chromedriver version from the mapping.
38
+ * @param mapping - The Chromedriver version mapping (defaults to the static mapping).
39
+ * @returns The most recent version string.
40
+ * @throws {Error} If the mapping is empty.
41
+ */
42
+ export function getMostRecentChromedriver(mapping: ChromedriverVersionMapping = CHROMEDRIVER_CHROME_MAPPING): string {
43
+ if (_.isEmpty(mapping)) {
44
+ throw new Error('Unable to get most recent Chromedriver version from empty mapping');
45
+ }
46
+ return _.last(_.keys(mapping).sort(compareVersions)) as string;
47
+ }
48
+
49
+ export const CD_VER: string =
50
+ process.env.npm_config_chromedriver_version ||
51
+ process.env.CHROMEDRIVER_VERSION ||
52
+ getMostRecentChromedriver();
53
+
54
+ /**
55
+ * Gets the Chrome version for a given bundle ID using ADB.
56
+ * @param adb - The ADB instance to use.
57
+ * @param bundleId - The bundle ID of the Chrome/WebView app.
58
+ * @returns The version name string, or undefined if not found.
59
+ */
60
+ export async function getChromeVersion(adb: ADB, bundleId: string): Promise<string | undefined> {
61
+ const {versionName} = await adb.getPackageInfo(bundleId);
62
+ return versionName;
63
+ }
64
+
65
+ /**
66
+ * Gets the directory path for Chromedriver executables for a given OS.
67
+ * @param osName - The OS name (defaults to the current OS).
68
+ * @returns The full path to the Chromedriver directory.
69
+ */
70
+ export function getChromedriverDir(osName: string = getOsName()): string {
71
+ return path.resolve(CD_BASE_DIR, osName);
72
+ }
73
+
74
+ /**
75
+ * Gets the path to the Chromedriver binary for a given OS.
76
+ * @param osName - The OS name (defaults to the current OS).
77
+ * @returns The full path to the Chromedriver binary.
78
+ */
79
+ export async function getChromedriverBinaryPath(osName: string = getOsName()): Promise<string> {
80
+ const rootDir = getChromedriverDir(osName);
81
+ const pathSuffix = osName === OS.WINDOWS ? '.exe' : '';
82
+ const paths = await fs.glob(`${CD_EXECUTABLE_PREFIX}*${pathSuffix}`, {
83
+ cwd: rootDir,
84
+ absolute: true,
85
+ nocase: true,
86
+ nodir: true,
87
+ });
88
+ return _.isEmpty(paths)
89
+ ? path.resolve(rootDir, `${CD_EXECUTABLE_PREFIX}${pathSuffix}`)
90
+ : (_.first(paths) as string);
91
+ }
92
+
93
+ /**
94
+ * Retrieves data from a URL using axios.
95
+ * @param url - The URL to fetch from.
96
+ * @param headers - Optional HTTP headers.
97
+ * @param opts - Optional configuration (timeout, responseType).
98
+ * @returns The response data.
99
+ */
100
+ export async function retrieveData(
101
+ url: string,
102
+ headers?: import('axios').AxiosRequestConfig['headers'],
103
+ opts: Pick<import('axios').AxiosRequestConfig, 'timeout' | 'responseType'> = {}
104
+ ): Promise<any> {
105
+ const {timeout = 5000, responseType = 'text'} = opts;
106
+ return (
107
+ await axios({
108
+ url,
109
+ headers,
110
+ timeout,
111
+ responseType,
112
+ })
113
+ ).data;
114
+ }
115
+
116
+ /**
117
+ * Gets the OS name for the current system.
118
+ * @returns The OS name ('win', 'mac', or 'linux').
119
+ */
120
+ export const getOsName = _.memoize(function getOsName(): typeof OS[keyof typeof OS] {
121
+ if (system.isWindows()) {
122
+ return OS.WINDOWS;
123
+ }
124
+ if (system.isMac()) {
125
+ return OS.MAC;
126
+ }
127
+ return OS.LINUX;
128
+ });
129
+
130
+ /**
131
+ * Gets the CPU type for the current system.
132
+ * @returns The CPU type ('intel' or 'arm').
133
+ */
134
+ export const getCpuType = _.memoize(function getCpuType(): typeof CPU[keyof typeof CPU] {
135
+ return _.includes(_.toLower(os.cpus()[0].model), 'apple') ? CPU.ARM : CPU.INTEL;
136
+ });
137
+
138
+ /**
139
+ * Gets OS information including name, architecture, and CPU type.
140
+ * @returns A promise that resolves to OS information.
141
+ */
142
+ export const getOsInfo = _.memoize(async function getOsInfo(): Promise<OSInfo> {
143
+ return {
144
+ name: getOsName(),
145
+ arch: String(await system.arch()),
146
+ cpu: getCpuType(),
147
+ };
148
+ });
149
+
150
+ // @ts-expect-error to avoid error
151
+ // TS2345: Argument of type '{}' is not assignable to parameter of type 'DriverOpts<Readonly<Record<string, Constraint>>>'
152
+ // Type '{}' is missing the following properties from type 'ServerArgs': address, allowCors, allowInsecure, basePath, and 26 more.
153
+ const getBaseDriverInstance = _.memoize(() => new BaseDriver({}, false));
154
+
155
+ /**
156
+ * Generates log prefix string.
157
+ * @param obj - Log owner instance.
158
+ * @param sessionId - Optional session identifier.
159
+ * @returns The generated log prefix string.
160
+ */
161
+ export function generateLogPrefix(obj: any, sessionId: string | null = null): string {
162
+ return getBaseDriverInstance().helpers.generateDriverLogPrefix(
163
+ obj,
164
+ sessionId ? sessionId : undefined
165
+ );
166
+ }
167
+
168
+ /**
169
+ * Converts the given object to an integer number if possible.
170
+ * @param value - The value to be converted.
171
+ * @returns The integer value or null if conversion is not possible.
172
+ */
173
+ export function convertToInt(value: any): number | null {
174
+ switch (typeof value) {
175
+ case 'number':
176
+ return Number.isNaN(value) ? null : value;
177
+ case 'string': {
178
+ const parsedAsInt = parseInt(value, 10);
179
+ return Number.isNaN(parsedAsInt) ? null : parsedAsInt;
180
+ }
181
+ default:
182
+ return null;
183
+ }
184
+ }
185
+
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "chrome",
7
7
  "android"
8
8
  ],
9
- "version": "8.1.0",
9
+ "version": "8.2.0",
10
10
  "author": "Appium Contributors",
11
11
  "license": "Apache-2.0",
12
12
  "repository": {
@@ -73,6 +73,7 @@
73
73
  "@types/bluebird": "^3.5.38",
74
74
  "@types/chai": "^5.2.3",
75
75
  "@types/chai-as-promised": "^8.0.2",
76
+ "@types/express": "^5.0.6",
76
77
  "@types/lodash": "^4.14.191",
77
78
  "@types/mocha": "^10.0.1",
78
79
  "@types/node": "^25.0.0",
@@ -1,44 +0,0 @@
1
- import _ from 'lodash';
2
- import { isStandardCap } from '@appium/base-driver';
3
-
4
- const W3C_PREFIX = 'goog:';
5
-
6
- /**
7
- *
8
- * @param {string} capName
9
- */
10
- export function toW3cCapName (capName) {
11
- return (_.isString(capName) && !capName.includes(':') && !isStandardCap(capName))
12
- ? `${W3C_PREFIX}${capName}`
13
- : capName;
14
- }
15
-
16
- /**
17
- *
18
- * @param {Record<string,any>} allCaps
19
- * @param {string} rawCapName
20
- * @param {any} [defaultValue]
21
- * @returns {any}
22
- */
23
- function getCapValue (allCaps = {}, rawCapName, defaultValue) {
24
- for (const [capName, capValue] of _.toPairs(allCaps)) {
25
- if (toW3cCapName(capName) === toW3cCapName(rawCapName)) {
26
- return capValue;
27
- }
28
- }
29
- return defaultValue;
30
- }
31
-
32
- /**
33
- *
34
- * @param {any} originalCaps
35
- * @returns {Record<string,any>}
36
- */
37
- function toW3cCapNames (originalCaps = {}) {
38
- return _.reduce(originalCaps, (acc, value, key) => {
39
- acc[toW3cCapName(key)] = value;
40
- return acc;
41
- }, /** @type {Record<string,any>} */({}));
42
- }
43
-
44
- export { toW3cCapNames, getCapValue };
package/lib/utils.js DELETED
@@ -1,189 +0,0 @@
1
- import _ from 'lodash';
2
- import {system, fs, node} from '@appium/support';
3
- import {BaseDriver} from '@appium/base-driver';
4
- import path from 'path';
5
- import {compareVersions} from 'compare-versions';
6
- import axios from 'axios';
7
- import os from 'os';
8
- import {OS, CPU} from './constants';
9
-
10
- const CD_EXECUTABLE_PREFIX = 'chromedriver';
11
- const MODULE_NAME = 'appium-chromedriver';
12
-
13
- /**
14
- * Calculates the path to the current module's root folder
15
- *
16
- * @returns {string} The full path to module root
17
- * @throws {Error} If the current module root folder cannot be determined
18
- */
19
- const getModuleRoot = _.memoize(function getModuleRoot() {
20
- const root = node.getModuleRootSync(MODULE_NAME, __filename);
21
- if (!root) {
22
- throw new Error(`Cannot find the root folder of the ${MODULE_NAME} Node.js module`);
23
- }
24
- return root;
25
- });
26
-
27
- // Chromedriver version: minimum Chrome version
28
- const CHROMEDRIVER_CHROME_MAPPING = require(path.join(getModuleRoot(), 'config', 'mapping.json'));
29
- const CD_BASE_DIR = path.join(getModuleRoot(), 'chromedriver');
30
-
31
- /**
32
- *
33
- * @param {import('./types').ChromedriverVersionMapping} mapping
34
- * @returns {string}
35
- */
36
- function getMostRecentChromedriver(mapping = CHROMEDRIVER_CHROME_MAPPING) {
37
- if (_.isEmpty(mapping)) {
38
- throw new Error('Unable to get most recent Chromedriver version from empty mapping');
39
- }
40
- return /** @type {string} */ (_.last(_.keys(mapping).sort(compareVersions)));
41
- }
42
-
43
- const CD_VER =
44
- process.env.npm_config_chromedriver_version ||
45
- process.env.CHROMEDRIVER_VERSION ||
46
- getMostRecentChromedriver();
47
-
48
- /**
49
- *
50
- * @param {import('appium-adb').ADB} adb
51
- * @param {string} bundleId
52
- * @returns
53
- */
54
- async function getChromeVersion(adb, bundleId) {
55
- const {versionName} = await adb.getPackageInfo(bundleId);
56
- return versionName;
57
- }
58
-
59
- function getChromedriverDir(osName = getOsName()) {
60
- return path.resolve(CD_BASE_DIR, osName);
61
- }
62
-
63
- /**
64
- *
65
- * @param {string} osName
66
- * @returns {Promise<string>}
67
- */
68
- async function getChromedriverBinaryPath(osName = getOsName()) {
69
- const rootDir = getChromedriverDir(osName);
70
- const pathSuffix = osName === OS.WINDOWS ? '.exe' : '';
71
- const paths = await fs.glob(`${CD_EXECUTABLE_PREFIX}*${pathSuffix}`, {
72
- cwd: rootDir,
73
- absolute: true,
74
- nocase: true,
75
- nodir: true,
76
- });
77
- return _.isEmpty(paths)
78
- ? path.resolve(rootDir, `${CD_EXECUTABLE_PREFIX}${pathSuffix}`)
79
- : /** @type {string} */ (_.first(paths));
80
- }
81
-
82
- /**
83
- *
84
- * @param {string} url
85
- * @param {import('axios').AxiosRequestConfig['headers']} headers
86
- * @param {Pick<import('axios').AxiosRequestConfig, 'timeout'|'responseType'>} opts
87
- * @returns
88
- */
89
- async function retrieveData(url, headers, opts = {}) {
90
- const {timeout = 5000, responseType = 'text'} = opts;
91
- return (
92
- await axios({
93
- url,
94
- headers,
95
- timeout,
96
- responseType,
97
- })
98
- ).data;
99
- }
100
-
101
- /**
102
- * @returns {keyof OS}
103
- */
104
- const getOsName = _.memoize(function getOsName() {
105
- if (system.isWindows()) {
106
- return OS.WINDOWS;
107
- }
108
- if (system.isMac()) {
109
- return OS.MAC;
110
- }
111
- return OS.LINUX;
112
- });
113
-
114
- const getCpuType = _.memoize(
115
- /**
116
- * @returns {string}
117
- */
118
- function getCpuType() {
119
- return _.includes(_.toLower(os.cpus()[0].model), 'apple') ? CPU.ARM : CPU.INTEL;
120
- }
121
- );
122
-
123
- const getOsInfo = _.memoize(
124
- /**
125
- * @returns {Promise<import('./types').OSInfo>}
126
- */
127
- async function getOsInfo() {
128
- return {
129
- name: getOsName(),
130
- arch: String(await system.arch()),
131
- cpu: getCpuType(),
132
- };
133
- }
134
- );
135
-
136
- // @ts-expect-error to avoid error
137
- // TS2345: Argument of type '{}' is not assignable to parameter of type 'DriverOpts<Readonly<Record<string, Constraint>>>'
138
- // Type '{}' is missing the following properties from type 'ServerArgs': address, allowCors, allowInsecure, basePath, and 26 more.
139
- const getBaseDriverInstance = _.memoize(() => new BaseDriver({}, false));
140
-
141
- /**
142
- * Generates log prefix string
143
- *
144
- * @param {any} obj log owner instance
145
- * @param {string?} sessionId Optional session identifier
146
- * @returns {string}
147
- */
148
- function generateLogPrefix(obj, sessionId = null) {
149
- return getBaseDriverInstance().helpers.generateDriverLogPrefix(
150
- obj,
151
- sessionId ? sessionId : undefined
152
- );
153
- }
154
-
155
- /**
156
- * Converts the given object to an integer number if possible
157
- *
158
- * @param {any} value to be converted
159
- * @returns {number | null}
160
- */
161
- function convertToInt(value) {
162
- switch (typeof value) {
163
- case 'number':
164
- return Number.isNaN(value) ? null : value;
165
- case 'string': {
166
- const parsedAsInt = parseInt(value, 10);
167
- return Number.isNaN(parsedAsInt) ? null : parsedAsInt;
168
- }
169
- default:
170
- return null;
171
- }
172
- }
173
-
174
- export {
175
- getChromeVersion,
176
- getChromedriverDir,
177
- getChromedriverBinaryPath,
178
- getOsName,
179
- CD_BASE_DIR,
180
- CD_VER,
181
- CHROMEDRIVER_CHROME_MAPPING,
182
- getMostRecentChromedriver,
183
- retrieveData,
184
- getOsInfo,
185
- getCpuType,
186
- OS,
187
- generateLogPrefix,
188
- convertToInt,
189
- };