appium-espresso-driver 9.0.4 → 9.0.6

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.
Files changed (100) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +2 -2
  3. package/build/lib/commands/actions.d.ts +1 -1
  4. package/build/lib/commands/actions.d.ts.map +1 -1
  5. package/build/lib/commands/actions.js.map +1 -1
  6. package/build/lib/commands/app-install.d.ts.map +1 -1
  7. package/build/lib/commands/app-install.js +4 -9
  8. package/build/lib/commands/app-install.js.map +1 -1
  9. package/build/lib/commands/app-management.d.ts.map +1 -1
  10. package/build/lib/commands/app-management.js.map +1 -1
  11. package/build/lib/commands/context.d.ts +1 -1
  12. package/build/lib/commands/context.d.ts.map +1 -1
  13. package/build/lib/commands/context.js.map +1 -1
  14. package/build/lib/commands/element.d.ts.map +1 -1
  15. package/build/lib/commands/element.js.map +1 -1
  16. package/build/lib/commands/idling-resources.d.ts.map +1 -1
  17. package/build/lib/commands/idling-resources.js.map +1 -1
  18. package/build/lib/commands/misc.d.ts.map +1 -1
  19. package/build/lib/commands/misc.js +1 -1
  20. package/build/lib/commands/misc.js.map +1 -1
  21. package/build/lib/commands/screenshot.d.ts.map +1 -1
  22. package/build/lib/commands/screenshot.js.map +1 -1
  23. package/build/lib/commands/server/builder.d.ts.map +1 -1
  24. package/build/lib/commands/server/builder.js +8 -15
  25. package/build/lib/commands/server/builder.js.map +1 -1
  26. package/build/lib/commands/server/runner.d.ts +2 -2
  27. package/build/lib/commands/server/runner.d.ts.map +1 -1
  28. package/build/lib/commands/server/runner.js +8 -14
  29. package/build/lib/commands/server/runner.js.map +1 -1
  30. package/build/lib/commands/server/startup.d.ts.map +1 -1
  31. package/build/lib/commands/server/startup.js.map +1 -1
  32. package/build/lib/commands/services.d.ts.map +1 -1
  33. package/build/lib/commands/services.js.map +1 -1
  34. package/build/lib/doctor/required-checks.d.ts +1 -1
  35. package/build/lib/doctor/required-checks.d.ts.map +1 -1
  36. package/build/lib/doctor/required-checks.js +2 -2
  37. package/build/lib/doctor/required-checks.js.map +1 -1
  38. package/build/lib/driver.d.ts +7 -7
  39. package/build/lib/driver.d.ts.map +1 -1
  40. package/build/lib/driver.js +14 -18
  41. package/build/lib/driver.js.map +1 -1
  42. package/build/lib/execute-method-map.d.ts.map +1 -1
  43. package/build/lib/execute-method-map.js +1 -7
  44. package/build/lib/execute-method-map.js.map +1 -1
  45. package/build/lib/method-map.js.map +1 -1
  46. package/build/lib/types.d.ts.map +1 -1
  47. package/build/lib/utils/package.d.ts.map +1 -1
  48. package/build/lib/utils/package.js +2 -2
  49. package/build/lib/utils/package.js.map +1 -1
  50. package/espresso-server/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk +0 -0
  51. package/espresso-server/buildSrc/.gradle/9.6.1/executionHistory/executionHistory.bin +0 -0
  52. package/espresso-server/buildSrc/.gradle/9.6.1/executionHistory/executionHistory.lock +0 -0
  53. package/espresso-server/buildSrc/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  54. package/espresso-server/buildSrc/.gradle/buildOutputCleanup/cache.properties +1 -1
  55. package/espresso-server/buildSrc/.gradle/file-system.probe +0 -0
  56. package/espresso-server/buildSrc/build/kotlin/compileKotlin/cacheable/last-build.bin +0 -0
  57. package/espresso-server/library/src/main/java/io/appium/espressoserver/lib/helpers/Version.kt +1 -1
  58. package/lib/commands/actions.ts +2 -1
  59. package/lib/commands/app-install.ts +9 -19
  60. package/lib/commands/app-management.ts +2 -1
  61. package/lib/commands/context.ts +2 -1
  62. package/lib/commands/element.ts +31 -76
  63. package/lib/commands/idling-resources.ts +9 -26
  64. package/lib/commands/misc.ts +14 -36
  65. package/lib/commands/screenshot.ts +1 -4
  66. package/lib/commands/server/builder.ts +13 -28
  67. package/lib/commands/server/runner.ts +24 -70
  68. package/lib/commands/server/startup.ts +2 -8
  69. package/lib/commands/services.ts +1 -5
  70. package/lib/doctor/required-checks.ts +6 -11
  71. package/lib/driver.ts +24 -37
  72. package/lib/execute-method-map.ts +1 -7
  73. package/lib/method-map.ts +1 -1
  74. package/lib/types.ts +1 -0
  75. package/lib/utils/package.ts +3 -2
  76. package/npm-shrinkwrap.json +166 -249
  77. package/package.json +57 -72
  78. package/scripts/build-espresso.mjs +7 -10
  79. package/scripts/diagnose-app.mjs +8 -13
  80. package/scripts/lib/dependency-versions/apk-dex.mjs +2 -1
  81. package/scripts/lib/dependency-versions/apk-kotlin-metadata.mjs +4 -2
  82. package/scripts/lib/dependency-versions/apk-meta-inf.mjs +4 -3
  83. package/scripts/lib/dependency-versions/apk-scan.mjs +4 -3
  84. package/scripts/lib/dependency-versions/comparison.mjs +3 -3
  85. package/scripts/lib/dependency-versions/gradle-scan.mjs +9 -11
  86. package/scripts/lib/dependency-versions/index.mjs +2 -9
  87. package/scripts/lib/dependency-versions/report.mjs +2 -5
  88. package/scripts/lib/dependency-versions/server-versions.mjs +3 -1
  89. package/scripts/lib/dependency-versions/tracked-modules.mjs +3 -12
  90. package/scripts/lib/dependency-versions/version-utils.mjs +1 -0
  91. package/scripts/lib/diagnose/app-input.mjs +4 -4
  92. package/scripts/lib/diagnose/checks/compile-sdk.mjs +1 -0
  93. package/scripts/lib/diagnose/checks/internet-permission.mjs +1 -2
  94. package/scripts/lib/diagnose/checks/startup-provider.mjs +2 -1
  95. package/scripts/lib/diagnose/diagnosis.mjs +2 -2
  96. package/scripts/lib/diagnose/gradle-utils.mjs +1 -5
  97. package/scripts/lib/diagnose/index.mjs +1 -5
  98. package/scripts/lib/diagnose/report.mjs +12 -4
  99. package/scripts/print-espresso-path.mjs +1 -0
  100. package/scripts/sync-version.mjs +8 -13
@@ -16,17 +16,10 @@ import type {EspressoDriver} from '../driver.js';
16
16
  * @throws {Error} If there was a failure while parsing options or registering
17
17
  * the actual instances
18
18
  */
19
- export async function mobileRegisterIdlingResources(
20
- this: EspressoDriver,
21
- classNames: string,
22
- ): Promise<any> {
23
- return await this.espresso.jwproxy.command(
24
- '/appium/execute_mobile/register_idling_resources',
25
- 'POST',
26
- {
27
- classNames,
28
- },
29
- );
19
+ export async function mobileRegisterIdlingResources(this: EspressoDriver, classNames: string): Promise<any> {
20
+ return await this.espresso.jwproxy.command('/appium/execute_mobile/register_idling_resources', 'POST', {
21
+ classNames,
22
+ });
30
23
  }
31
24
 
32
25
  /**
@@ -44,17 +37,10 @@ export async function mobileRegisterIdlingResources(
44
37
  * @throws {Error} If there was a failure while parsing options or unregistering
45
38
  * the actual instances
46
39
  */
47
- export async function mobileUnregisterIdlingResources(
48
- this: EspressoDriver,
49
- classNames: string,
50
- ): Promise<any> {
51
- return await this.espresso.jwproxy.command(
52
- '/appium/execute_mobile/unregister_idling_resources',
53
- 'POST',
54
- {
55
- classNames,
56
- },
57
- );
40
+ export async function mobileUnregisterIdlingResources(this: EspressoDriver, classNames: string): Promise<any> {
41
+ return await this.espresso.jwproxy.command('/appium/execute_mobile/unregister_idling_resources', 'POST', {
42
+ classNames,
43
+ });
58
44
  }
59
45
 
60
46
  /**
@@ -64,10 +50,7 @@ export async function mobileUnregisterIdlingResources(
64
50
  * @returns Promise that resolves to the list of fully qualified class names
65
51
  */
66
52
  export async function mobileListIdlingResources(this: EspressoDriver): Promise<string[]> {
67
- return (await this.espresso.jwproxy.command(
68
- '/appium/execute_mobile/list_idling_resources',
69
- 'GET',
70
- )) as string[];
53
+ return (await this.espresso.jwproxy.command('/appium/execute_mobile/list_idling_resources', 'GET')) as string[];
71
54
  }
72
55
 
73
56
  /**
@@ -1,6 +1,7 @@
1
- import {util} from 'appium/support.js';
2
- import {errors} from 'appium/driver.js';
3
1
  import type {StringRecord} from '@appium/types';
2
+ import {errors} from 'appium/driver.js';
3
+ import {util} from 'appium/support.js';
4
+
4
5
  import type {EspressoDriver} from '../driver.js';
5
6
  import type {DeviceInfo} from '../types.js';
6
7
 
@@ -30,15 +31,11 @@ export async function mobilePressKey(
30
31
  flags?: number,
31
32
  isLongPress: boolean = false,
32
33
  ): Promise<void> {
33
- await this.espresso.jwproxy.command(
34
- `/appium/device/${isLongPress ? 'long_' : ''}press_keycode`,
35
- 'POST',
36
- {
37
- keycode,
38
- metastate,
39
- flags,
40
- },
41
- );
34
+ await this.espresso.jwproxy.command(`/appium/device/${isLongPress ? 'long_' : ''}press_keycode`, 'POST', {
35
+ keycode,
36
+ metastate,
37
+ flags,
38
+ });
42
39
  }
43
40
 
44
41
  /**
@@ -58,11 +55,7 @@ export async function mobileGetDeviceInfo(this: EspressoDriver): Promise<DeviceI
58
55
  * @returns Promise that resolves to true if the toast is visible, false otherwise
59
56
  * @throws {errors.InvalidArgumentError} If text is not provided
60
57
  */
61
- export async function mobileIsToastVisible(
62
- this: EspressoDriver,
63
- text: string,
64
- isRegexp?: boolean,
65
- ): Promise<any> {
58
+ export async function mobileIsToastVisible(this: EspressoDriver, text: string, isRegexp?: boolean): Promise<any> {
66
59
  if (!util.hasValue(text)) {
67
60
  throw new errors.InvalidArgumentError(`'text' argument is mandatory`);
68
61
  }
@@ -76,11 +69,7 @@ export async function mobileIsToastVisible(
76
69
  * @returns Promise that resolves to the display density value
77
70
  */
78
71
  export async function getDisplayDensity(this: EspressoDriver): Promise<number> {
79
- return (await this.espresso.jwproxy.command(
80
- '/appium/device/display_density',
81
- 'GET',
82
- {},
83
- )) as number;
72
+ return (await this.espresso.jwproxy.command('/appium/device/display_density', 'GET', {})) as number;
84
73
  }
85
74
 
86
75
  /**
@@ -138,9 +127,7 @@ export async function mobileBackdoor(
138
127
  elementId?: string,
139
128
  ): Promise<any> {
140
129
  if (target === 'element' && !elementId) {
141
- throw new errors.InvalidArgumentError(
142
- `'elementId' is required if 'target' equals to 'element'`,
143
- );
130
+ throw new errors.InvalidArgumentError(`'elementId' is required if 'target' equals to 'element'`);
144
131
  }
145
132
  return await this.espresso.jwproxy.command(`/appium/execute_mobile/backdoor`, 'POST', {
146
133
  target,
@@ -186,10 +173,7 @@ export async function mobileUiautomator(
186
173
  * @returns {Promise<string>} uiautomator DOM xml as string
187
174
  */
188
175
  export async function mobileUiautomatorPageSource(this: EspressoDriver): Promise<string> {
189
- return (await this.espresso.jwproxy.command(
190
- `/appium/execute_mobile/uiautomator_page_source`,
191
- 'GET',
192
- )) as string;
176
+ return (await this.espresso.jwproxy.command(`/appium/execute_mobile/uiautomator_page_source`, 'GET')) as string;
193
177
  }
194
178
 
195
179
  /**
@@ -198,10 +182,7 @@ export async function mobileUiautomatorPageSource(this: EspressoDriver): Promise
198
182
  * @param settings - Settings object containing key-value pairs of settings to apply
199
183
  * @returns Promise that resolves when settings are updated
200
184
  */
201
- export async function updateSettings(
202
- this: EspressoDriver,
203
- settings: SettingsOptions,
204
- ): Promise<void> {
185
+ export async function updateSettings(this: EspressoDriver, settings: SettingsOptions): Promise<void> {
205
186
  await this.settings.update(settings);
206
187
  try {
207
188
  await this.espresso.jwproxy.command(`/appium/settings`, 'POST', {settings});
@@ -216,9 +197,6 @@ export async function updateSettings(
216
197
  */
217
198
  export async function getSettings(this: EspressoDriver): Promise<Record<string, any>> {
218
199
  const driverSettings = this.settings.getSettings();
219
- const serverSettings = (await this.espresso.jwproxy.command(`/appium/settings`, 'GET')) as Record<
220
- string,
221
- any
222
- >;
200
+ const serverSettings = (await this.espresso.jwproxy.command(`/appium/settings`, 'GET')) as Record<string, any>;
223
201
  return {...driverSettings, ...serverSettings};
224
202
  }
@@ -15,10 +15,7 @@ const DISPLAY_PATTERN = /^Display\s+(\d+)\s+\(.+display\s+(\d+)\).+displayName="
15
15
  * and values contain display information and base64-encoded PNG screenshot data
16
16
  * @throws {Error} If display information cannot be determined or if a provided displayId is not found
17
17
  */
18
- export async function mobileScreenshots(
19
- this: EspressoDriver,
20
- displayId?: number | string,
21
- ): Promise<ScreenshotsInfo> {
18
+ export async function mobileScreenshots(this: EspressoDriver, displayId?: number | string): Promise<ScreenshotsInfo> {
22
19
  const displaysInfo = await this.adb.shell(['dumpsys', 'SurfaceFlinger', '--display-id']);
23
20
  const infos: Record<string, {id: string; isDefault: boolean; name: string}> = {};
24
21
  let match;
@@ -1,18 +1,16 @@
1
- import {SubProcess} from 'teen_process';
2
- import {fs, system} from 'appium/support.js';
3
- import path from 'node:path';
4
1
  import {EOL} from 'node:os';
5
- import {escapeRegExp} from '../../utils/index.js';
2
+ import path from 'node:path';
3
+
6
4
  import type {AppiumLogger} from '@appium/types';
5
+ import {fs, system} from 'appium/support.js';
6
+ import {SubProcess} from 'teen_process';
7
+
8
+ import {escapeRegExp} from '../../utils/index.js';
7
9
 
8
10
  const GRADLE_VERSION_KEY = 'gradle';
9
11
  const GRADLE_URL_PREFIX = 'distributionUrl=';
10
- export const GRADLE_URL_TEMPLATE =
11
- 'https\\://services.gradle.org/distributions/gradle-VERSION-all.zip';
12
- const DEPENDENCY_PROP_NAMES = [
13
- 'additionalAppDependencies',
14
- 'additionalAndroidTestDependencies',
15
- ] as const;
12
+ export const GRADLE_URL_TEMPLATE = 'https\\://services.gradle.org/distributions/gradle-VERSION-all.zip';
13
+ const DEPENDENCY_PROP_NAMES = ['additionalAppDependencies', 'additionalAndroidTestDependencies'] as const;
16
14
 
17
15
  export const VERSION_KEYS = [
18
16
  GRADLE_VERSION_KEY,
@@ -114,8 +112,7 @@ export class ServerBuilder {
114
112
 
115
113
  private getCommand(): {cmd: string; args: string[]} {
116
114
  const cmd = system.isWindows() ? 'gradlew.bat' : path.resolve(this.serverPath, 'gradlew');
117
- const buildProperty = (key: string, value?: string): string | null =>
118
- value ? `-P${key}=${value}` : null;
115
+ const buildProperty = (key: string, value?: string): string | null => (value ? `-P${key}=${value}` : null);
119
116
  const args: string[] = VERSION_KEYS.filter((key) => key !== GRADLE_VERSION_KEY)
120
117
  .map((key) => {
121
118
  const serverVersion = this.serverVersions[key];
@@ -157,12 +154,7 @@ export class ServerBuilder {
157
154
  }
158
155
 
159
156
  private async setGradleWrapperVersion(version: string): Promise<void> {
160
- const propertiesPath = path.resolve(
161
- this.serverPath,
162
- 'gradle',
163
- 'wrapper',
164
- 'gradle-wrapper.properties',
165
- );
157
+ const propertiesPath = path.resolve(this.serverPath, 'gradle', 'wrapper', 'gradle-wrapper.properties');
166
158
  const originalProperties = await fs.readFile(propertiesPath, 'utf8');
167
159
  const newProperties = this.updateGradleDistUrl(originalProperties, version);
168
160
  await fs.writeFile(propertiesPath, newProperties, 'utf8');
@@ -204,9 +196,7 @@ export class ServerBuilder {
204
196
  let configuration = await fs.readFile(buildPath, 'utf8');
205
197
  for (const propName of DEPENDENCY_PROP_NAMES) {
206
198
  const prefix = propName === DEPENDENCY_PROP_NAMES[0] ? 'api' : 'androidTestImplementation';
207
- const deps = this[propName]
208
- .filter((line) => line.trim())
209
- .map((line) => `${prefix}("${line}")`);
199
+ const deps = this[propName].filter((line) => line.trim()).map((line) => `${prefix}("${line}")`);
210
200
  if (deps.length === 0) {
211
201
  continue;
212
202
  }
@@ -219,10 +209,7 @@ export class ServerBuilder {
219
209
 
220
210
  private async runBuildProcess(): Promise<void> {
221
211
  const {cmd, args} = this.getCommand();
222
- this.log.debug(
223
- `Beginning build with command '${cmd} ${args.join(' ')}' ` +
224
- `in directory '${this.serverPath}'`,
225
- );
212
+ this.log.debug(`Beginning build with command '${cmd} ${args.join(' ')}' in directory '${this.serverPath}'`);
226
213
  const gradlebuild = new SubProcess(cmd, args, {
227
214
  cwd: this.serverPath,
228
215
  stdio: ['ignore', 'pipe', 'pipe'],
@@ -244,9 +231,7 @@ export class ServerBuilder {
244
231
  await gradlebuild.start();
245
232
  await gradlebuild.join();
246
233
  } catch (err: any) {
247
- const msg =
248
- `Unable to build Espresso server - ${err.message}\n` +
249
- `Gradle error message:${EOL}${gradleError.join('\n')}`;
234
+ const msg = `Unable to build Espresso server - ${err.message}\nGradle error message:${EOL}${gradleError.join('\n')}`;
250
235
  throw this.log.errorWithException(msg);
251
236
  } finally {
252
237
  gradlebuild.removeAllListeners();
@@ -1,28 +1,19 @@
1
- import {JWProxy, errors} from 'appium/driver.js';
2
- import {sleep, waitForCondition} from 'asyncbox';
3
1
  import path from 'node:path';
4
2
  import {fileURLToPath} from 'node:url';
3
+
4
+ import type {AppiumLogger, StringRecord, HTTPMethod, HTTPBody, ProxyResponse, ProxyOptions} from '@appium/types';
5
+ import type {ADB} from 'appium-adb';
6
+ import {JWProxy, errors} from 'appium/driver.js';
5
7
  import {fs, node, util, timing} from 'appium/support.js';
6
- import {getPackageInfoSync, getPackageInfo, isPlainObject} from '../../utils/index.js';
7
- import {ServerBuilder, buildServerSigningConfig, type ServerSigningConfig} from './builder.js';
8
- import {
9
- ESPRESSO_SERVER_LAUNCH_TIMEOUT_MS,
10
- TARGET_PACKAGE_CONTAINER,
11
- TEST_APK_PKG,
12
- } from './constants.js';
8
+ import {sleep, waitForCondition} from 'asyncbox';
13
9
  import axios from 'axios';
14
10
  import * as semver from 'semver';
15
- import type {
16
- AppiumLogger,
17
- StringRecord,
18
- HTTPMethod,
19
- HTTPBody,
20
- ProxyResponse,
21
- ProxyOptions,
22
- } from '@appium/types';
23
- import type {ADB} from 'appium-adb';
24
11
  import type {SubProcess} from 'teen_process';
25
12
 
13
+ import {getPackageInfoSync, getPackageInfo, isPlainObject} from '../../utils/index.js';
14
+ import {ServerBuilder, buildServerSigningConfig, type ServerSigningConfig} from './builder.js';
15
+ import {ESPRESSO_SERVER_LAUNCH_TIMEOUT_MS, TARGET_PACKAGE_CONTAINER, TEST_APK_PKG} from './constants.js';
16
+
26
17
  export interface EspressoRunnerOptions {
27
18
  adb: ADB;
28
19
  tmpDir: string;
@@ -146,13 +137,7 @@ export class EspressoRunner {
146
137
  this.disableSuppressAccessibilityService = opts.disableSuppressAccessibilityService;
147
138
 
148
139
  // Espresso Server app needs to be signed with same keyStore as appPackage
149
- if (
150
- opts.useKeystore &&
151
- opts.keystorePath &&
152
- opts.keystorePassword &&
153
- opts.keyAlias &&
154
- opts.keyPassword
155
- ) {
140
+ if (opts.useKeystore && opts.keystorePath && opts.keystorePassword && opts.keyAlias && opts.keyPassword) {
156
141
  this.signingConfig = buildServerSigningConfig({
157
142
  keystoreFile: opts.keystorePath,
158
143
  keystorePassword: opts.keystorePassword,
@@ -188,13 +173,10 @@ export class EspressoRunner {
188
173
  this.adb.APP_INSTALL_STATE.OLDER_VERSION_INSTALLED,
189
174
  this.adb.APP_INSTALL_STATE.NEWER_VERSION_INSTALLED,
190
175
  ].includes(appState);
191
- const shouldInstallApp =
192
- shouldUninstallApp || [this.adb.APP_INSTALL_STATE.NOT_INSTALLED].includes(appState);
176
+ const shouldInstallApp = shouldUninstallApp || [this.adb.APP_INSTALL_STATE.NOT_INSTALLED].includes(appState);
193
177
 
194
178
  if (shouldUninstallApp) {
195
- this.log.info(
196
- `Uninstalling Espresso Test Server apk from the target device (pkg: '${TEST_APK_PKG}')`,
197
- );
179
+ this.log.info(`Uninstalling Espresso Test Server apk from the target device (pkg: '${TEST_APK_PKG}')`);
198
180
  try {
199
181
  await this.adb.uninstallApk(TEST_APK_PKG);
200
182
  } catch (err: any) {
@@ -203,21 +185,15 @@ export class EspressoRunner {
203
185
  }
204
186
 
205
187
  if (shouldInstallApp) {
206
- this.log.info(
207
- `Installing Espresso Test Server apk from the target device (path: '${this.modServerPath}')`,
208
- );
188
+ this.log.info(`Installing Espresso Test Server apk from the target device (path: '${this.modServerPath}')`);
209
189
  try {
210
190
  await this.adb.install(this.modServerPath, {
211
191
  replace: false,
212
192
  timeout: this.androidInstallTimeout,
213
193
  });
214
- this.log.info(
215
- `Installed Espresso Test Server apk '${this.modServerPath}' (pkg: '${TEST_APK_PKG}')`,
216
- );
194
+ this.log.info(`Installed Espresso Test Server apk '${this.modServerPath}' (pkg: '${TEST_APK_PKG}')`);
217
195
  } catch (err: any) {
218
- throw this.log.errorWithException(
219
- `Cannot install '${this.modServerPath}' because of '${err.message}'`,
220
- );
196
+ throw this.log.errorWithException(`Cannot install '${this.modServerPath}' because of '${err.message}'`);
221
197
  }
222
198
  }
223
199
  }
@@ -275,9 +251,7 @@ export class EspressoRunner {
275
251
  this.log.debug(`The build folder root could be customized by changing the 'tmpDir' capability`);
276
252
  await fs.rimraf(serverPath);
277
253
  await fs.mkdirp(serverPath);
278
- this.log.debug(
279
- `Copying espresso server template from ('${getTestServerRoot()}' to '${serverPath}')`,
280
- );
254
+ this.log.debug(`Copying espresso server template from ('${getTestServerRoot()}' to '${serverPath}')`);
281
255
  await copyGradleProjectRecursively(getTestServerRoot(), serverPath);
282
256
  this.log.debug('Bulding espresso server');
283
257
  await new ServerBuilder(this.log, {
@@ -318,19 +292,13 @@ export class EspressoRunner {
318
292
  ];
319
293
 
320
294
  if (typeof this.disableSuppressAccessibilityService === 'boolean') {
321
- cmd.push(
322
- '-e',
323
- 'DISABLE_SUPPRESS_ACCESSIBILITY_SERVICES',
324
- String(this.disableSuppressAccessibilityService),
325
- );
295
+ cmd.push('-e', 'DISABLE_SUPPRESS_ACCESSIBILITY_SERVICES', String(this.disableSuppressAccessibilityService));
326
296
  }
327
297
 
328
298
  cmd.push(`${TEST_APK_PKG}/androidx.test.runner.AndroidJUnitRunner`);
329
299
 
330
300
  const {manifestPayload} = await getPackageInfo();
331
- this.log.info(
332
- `Starting Espresso Server v${manifestPayload.version} with cmd: adb ${cmd.join(' ')}`,
333
- );
301
+ this.log.info(`Starting Espresso Server v${manifestPayload.version} with cmd: adb ${cmd.join(' ')}`);
334
302
 
335
303
  let hasSocketError = false;
336
304
  // start the instrumentation process
@@ -423,9 +391,7 @@ export class EspressoRunner {
423
391
  try {
424
392
  await this.jwproxy.command('/', 'DELETE');
425
393
  } catch (err: any) {
426
- this.log.warn(
427
- `Did not get confirmation Espresso deleteSession worked; ` + `Error was: ${err}`,
428
- );
394
+ this.log.warn(`Did not get confirmation Espresso deleteSession worked; Error was: ${err}`);
429
395
  }
430
396
 
431
397
  if (this.instProcess?.isRunning) {
@@ -445,9 +411,7 @@ export class EspressoRunner {
445
411
  ).data as SessionsResponse;
446
412
  const activeSessionIds = value.map((sess) => sess.id);
447
413
  if (activeSessionIds.length) {
448
- this.log.debug(
449
- `The following obsolete sessions are still running: ${JSON.stringify(activeSessionIds)}`,
450
- );
414
+ this.log.debug(`The following obsolete sessions are still running: ${JSON.stringify(activeSessionIds)}`);
451
415
  this.log.debug('Cleaning up the obsolete sessions');
452
416
  await Promise.all(
453
417
  activeSessionIds.map((id) =>
@@ -469,15 +433,10 @@ export class EspressoRunner {
469
433
 
470
434
  private async recordTargetAppPackage(): Promise<void> {
471
435
  await this.adb.shell([`echo "${this.appPackage}" > "${TARGET_PACKAGE_CONTAINER}"`]);
472
- this.log.info(
473
- `Recorded the target application package '${this.appPackage}' to ${TARGET_PACKAGE_CONTAINER}`,
474
- );
436
+ this.log.info(`Recorded the target application package '${this.appPackage}' to ${TARGET_PACKAGE_CONTAINER}`);
475
437
  }
476
438
 
477
- private async _verifyServerStatus(
478
- driverVersion: string,
479
- serverStatus: ServerStatus,
480
- ): Promise<boolean> {
439
+ private async _verifyServerStatus(driverVersion: string, serverStatus: ServerStatus): Promise<boolean> {
481
440
  if (!isPlainObject(serverStatus) || !isPlainObject(serverStatus.build)) {
482
441
  throw this.log.errorWithException(
483
442
  `The Espresso server version integrated with the application under test is not compatible ` +
@@ -487,9 +446,7 @@ export class EspressoRunner {
487
446
  const {
488
447
  build: {version: serverVersion, packageName: serverPackageName},
489
448
  } = serverStatus;
490
- const appLabel = serverPackageName
491
- ? `'${serverPackageName}' application`
492
- : 'application under test';
449
+ const appLabel = serverPackageName ? `'${serverPackageName}' application` : 'application under test';
493
450
  const parsedServerVersion = semver.coerce(serverVersion);
494
451
  const parsedDriverVersion = semver.coerce(driverVersion);
495
452
  if (parsedServerVersion && parsedDriverVersion) {
@@ -544,10 +501,7 @@ let testServerRoot: string | undefined;
544
501
  * @param sourceBaseDir directory to copy files from
545
502
  * @param targetBaseDir directory to copy files to
546
503
  */
547
- export async function copyGradleProjectRecursively(
548
- sourceBaseDir: string,
549
- targetBaseDir: string,
550
- ): Promise<void> {
504
+ export async function copyGradleProjectRecursively(sourceBaseDir: string, targetBaseDir: string): Promise<void> {
551
505
  // @ts-ignore it is ok to have the async callback
552
506
  await fs.walkDir(sourceBaseDir, true, async (itemPath: string, isDirectory: boolean) => {
553
507
  const relativePath = path.relative(sourceBaseDir, itemPath);
@@ -99,15 +99,9 @@ export async function startSession(this: EspressoDriver): Promise<void> {
99
99
  // launch espresso and wait till its online and we have a session
100
100
  await this.espresso.startSession(this.caps);
101
101
  if (this.caps.autoLaunch === false) {
102
- this.log.info(
103
- `Not waiting for the application activity to start because 'autoLaunch' is disabled`,
104
- );
102
+ this.log.info(`Not waiting for the application activity to start because 'autoLaunch' is disabled`);
105
103
  } else {
106
- await this.adb.waitForActivity(
107
- appWaitPackage,
108
- this.caps.appWaitActivity,
109
- this.opts.appWaitDuration,
110
- );
104
+ await this.adb.waitForActivity(appWaitPackage, this.caps.appWaitActivity, this.opts.appWaitDuration);
111
105
  }
112
106
  // if we want to immediately get into a webview, set our context
113
107
  // appropriately
@@ -39,11 +39,7 @@ export async function mobileStartService(
39
39
  * @throws {Error} If there was a failure while stopping the service
40
40
  * or required options are missing
41
41
  */
42
- export async function mobileStopService(
43
- this: EspressoDriver,
44
- intent: string,
45
- user?: string | number,
46
- ): Promise<string> {
42
+ export async function mobileStopService(this: EspressoDriver, intent: string, user?: string | number): Promise<string> {
47
43
  return (await this.espresso.jwproxy.command('/appium/execute_mobile/stop_service', 'POST', {
48
44
  intent,
49
45
  user,
@@ -1,8 +1,9 @@
1
- import {doctor as doctorCommon} from 'appium-android-driver';
2
- import {exec} from 'teen_process';
3
- import {fs, system, doctor} from 'appium/support.js';
4
1
  import path from 'node:path';
2
+
5
3
  import type {AppiumLogger, IDoctorCheck} from '@appium/types';
4
+ import {doctor as doctorCommon} from 'appium-android-driver';
5
+ import {fs, system, doctor} from 'appium/support.js';
6
+ import {exec} from 'teen_process';
6
7
 
7
8
  export const androidHomeCheck = doctorCommon.androidHomeCheck;
8
9
  export const javaHomeCheck = doctorCommon.javaHomeCheck;
@@ -16,15 +17,9 @@ export class JavaVersionCheck implements IDoctorCheck {
16
17
 
17
18
  async diagnose() {
18
19
  const javaHome = process.env.JAVA_HOME;
19
- const fullJavaPath = path.join(
20
- javaHome ?? '',
21
- 'bin',
22
- `java${system.isWindows() ? '.exe' : ''}`,
23
- );
20
+ const fullJavaPath = path.join(javaHome ?? '', 'bin', `java${system.isWindows() ? '.exe' : ''}`);
24
21
  if (!javaHome || !(await fs.exists(fullJavaPath))) {
25
- return doctor.nok(
26
- `Cannot retrieve Java version. Is Java installed and JAVA_HOME set to a proper path?`,
27
- );
22
+ return doctor.nok(`Cannot retrieve Java version. Is Java installed and JAVA_HOME set to a proper path?`);
28
23
  }
29
24
  let javaVerMatch: RegExpExecArray | null;
30
25
  try {
package/lib/driver.ts CHANGED
@@ -8,29 +8,30 @@ import type {
8
8
  SingularSessionData,
9
9
  SessionCapabilities,
10
10
  } from '@appium/types';
11
- import type {EspressoConstraints} from './constraints.js';
11
+ import {DEFAULT_ADB_PORT} from 'appium-adb';
12
+ import {AndroidDriver} from 'appium-android-driver';
12
13
  import {errors, isErrorType, DeviceSettings, BaseDriver} from 'appium/driver.js';
13
- import * as serverCmds from './commands/server/index.js';
14
- import type {EspressoRunner} from './commands/server/index.js';
14
+ import {retryInterval} from 'asyncbox';
15
+ import {findAPortNotInUse} from 'portscanner';
16
+
17
+ import * as actionsCmds from './commands/actions.js';
18
+ import * as appInstallCmds from './commands/app-install.js';
15
19
  import * as appManagementCmds from './commands/app-management.js';
20
+ import * as clipboardCmds from './commands/clipboard.js';
16
21
  import * as contextCmds from './commands/context.js';
17
22
  import * as elementCmds from './commands/element.js';
23
+ import * as idlingResourcesCmds from './commands/idling-resources.js';
18
24
  import * as miscCmds from './commands/misc.js';
19
- import * as servicesCmds from './commands/services.js';
20
25
  import * as screenshotCmds from './commands/screenshot.js';
21
- import * as idlingResourcesCmds from './commands/idling-resources.js';
22
- import * as actionsCmds from './commands/actions.js';
23
- import * as clipboardCmds from './commands/clipboard.js';
24
- import * as appInstallCmds from './commands/app-install.js';
25
- import {DEFAULT_ADB_PORT} from 'appium-adb';
26
- import {AndroidDriver} from 'appium-android-driver';
26
+ import * as serverCmds from './commands/server/index.js';
27
+ import type {EspressoRunner} from './commands/server/index.js';
28
+ import * as servicesCmds from './commands/services.js';
29
+ import type {EspressoConstraints} from './constraints.js';
27
30
  import {ESPRESSO_CONSTRAINTS} from './constraints.js';
28
- import {findAPortNotInUse} from 'portscanner';
29
- import {retryInterval} from 'asyncbox';
30
- import {isEmptyValue} from './utils/index.js';
31
+ import {executeMethodMap} from './execute-method-map.js';
31
32
  import {newMethodMap} from './method-map.js';
32
33
  import type {EspressoDriverCaps, EspressoDriverOpts, W3CEspressoDriverCaps} from './types.js';
33
- import {executeMethodMap} from './execute-method-map.js';
34
+ import {isEmptyValue} from './utils/index.js';
34
35
 
35
36
  // NO_PROXY contains the paths that we never want to proxy to espresso server.
36
37
  // TODO: Add the list of paths that we never want to proxy to espresso server.
@@ -130,10 +131,7 @@ const CHROME_NO_PROXY: RouteMatcher[] = [
130
131
  ['POST', new RegExp('^/session/[^/]+/se/log')],
131
132
  ];
132
133
 
133
- export class EspressoDriver
134
- extends AndroidDriver
135
- implements ExternalDriver<EspressoConstraints, string, StringRecord>
136
- {
134
+ export class EspressoDriver extends AndroidDriver implements ExternalDriver<EspressoConstraints, string, StringRecord> {
137
135
  static newMethodMap = newMethodMap;
138
136
  static executeMethodMap = executeMethodMap as unknown as typeof AndroidDriver.executeMethodMap;
139
137
 
@@ -152,15 +150,12 @@ export class EspressoDriver
152
150
  performActions = actionsCmds.performActions as AndroidDriver['performActions'];
153
151
 
154
152
  startActivity = appManagementCmds.startActivity;
155
- mobileStartActivity =
156
- appManagementCmds.mobileStartActivity as unknown as AndroidDriver['mobileStartActivity'];
153
+ mobileStartActivity = appManagementCmds.mobileStartActivity as unknown as AndroidDriver['mobileStartActivity'];
157
154
 
158
155
  mobileWebAtoms = contextCmds.mobileWebAtoms;
159
- suspendChromedriverProxy =
160
- contextCmds.suspendChromedriverProxy as AndroidDriver['suspendChromedriverProxy'];
156
+ suspendChromedriverProxy = contextCmds.suspendChromedriverProxy as AndroidDriver['suspendChromedriverProxy'];
161
157
 
162
- mobilePerformEditorAction =
163
- elementCmds.mobilePerformEditorAction as AndroidDriver['mobilePerformEditorAction'];
158
+ mobilePerformEditorAction = elementCmds.mobilePerformEditorAction as AndroidDriver['mobilePerformEditorAction'];
164
159
  mobileSwipe = elementCmds.mobileSwipe;
165
160
  mobileOpenDrawer = elementCmds.mobileOpenDrawer;
166
161
  mobileCloseDrawer = elementCmds.mobileCloseDrawer;
@@ -186,10 +181,8 @@ export class EspressoDriver
186
181
  mobileGetClipboard = clipboardCmds.getClipboard;
187
182
  mobileSetClipboard = clipboardCmds.mobileSetClipboard;
188
183
 
189
- mobileStartService =
190
- servicesCmds.mobileStartService as unknown as AndroidDriver['mobileStartService'];
191
- mobileStopService =
192
- servicesCmds.mobileStopService as unknown as AndroidDriver['mobileStopService'];
184
+ mobileStartService = servicesCmds.mobileStartService as unknown as AndroidDriver['mobileStartService'];
185
+ mobileStopService = servicesCmds.mobileStopService as unknown as AndroidDriver['mobileStopService'];
193
186
 
194
187
  getScreenshot = screenshotCmds.getScreenshot;
195
188
  mobileScreenshots = screenshotCmds.mobileScreenshots;
@@ -318,8 +311,7 @@ export class EspressoDriver
318
311
  // the app isn't an actual app file but rather something we want to
319
312
  // assume is on the device and just launch via the appPackage
320
313
  this.log.info(
321
- `App file was not listed, instead we're going to run ` +
322
- `${this.opts.appPackage} directly on the device`,
314
+ `App file was not listed, instead we're going to run ${this.opts.appPackage} directly on the device`,
323
315
  );
324
316
  if (!(await this.adb.isAppInstalled(this.opts.appPackage as string))) {
325
317
  throw this.log.errorWithException(
@@ -429,9 +421,7 @@ export class EspressoDriver
429
421
  await this.settingsApp.setAnimationState(false);
430
422
  this.wasAnimationEnabled = true;
431
423
  } else if (shouldEnableAnimation) {
432
- this.log.debug(
433
- 'Enabling window animation as "disableWindowAnimation" capability is set to false',
434
- );
424
+ this.log.debug('Enabling window animation as "disableWindowAnimation" capability is set to false');
435
425
  await this.settingsApp.setAnimationState(true);
436
426
  this.wasAnimationEnabled = false;
437
427
  } else {
@@ -480,10 +470,7 @@ export class EspressoDriver
480
470
  // and one for Espresso(NO_PROXY), based on current context will return related NO_PROXY list
481
471
  this.jwpProxyAvoid = this.chromedriver == null ? NO_PROXY : CHROME_NO_PROXY;
482
472
  if (this.opts.nativeWebScreenshot) {
483
- this.jwpProxyAvoid = [
484
- ...this.jwpProxyAvoid,
485
- ['GET', new RegExp('^/session/[^/]+/screenshot')],
486
- ];
473
+ this.jwpProxyAvoid = [...this.jwpProxyAvoid, ['GET', new RegExp('^/session/[^/]+/screenshot')]];
487
474
  }
488
475
 
489
476
  return this.jwpProxyAvoid;
@@ -28,13 +28,7 @@ export const executeMethodMap = {
28
28
  command: 'mobileClickAction',
29
29
  params: {
30
30
  required: ['elementId'],
31
- optional: [
32
- 'tapper',
33
- 'coordinatesProvider',
34
- 'precisionDescriber',
35
- 'inputDevice',
36
- 'buttonState',
37
- ],
31
+ optional: ['tapper', 'coordinatesProvider', 'precisionDescriber', 'inputDevice', 'buttonState'],
38
32
  },
39
33
  },
40
34
 
package/lib/method-map.ts CHANGED
@@ -1,5 +1,5 @@
1
- import {AndroidDriver} from 'appium-android-driver';
2
1
  import type {MethodMap} from '@appium/types';
2
+ import {AndroidDriver} from 'appium-android-driver';
3
3
 
4
4
  export const newMethodMap = {
5
5
  ...AndroidDriver.newMethodMap,
package/lib/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type {DriverCaps, DriverOpts, W3CDriverCaps} from '@appium/types';
2
+
2
3
  import type {EspressoConstraints} from './constraints.js';
3
4
 
4
5
  export type EspressoDriverOpts = DriverOpts<EspressoConstraints>;