appium-mac2-driver 4.3.6 → 4.5.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.
Files changed (106) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/WebDriverAgentMac/IntegrationTests/AMSessionTests.m +14 -0
  3. package/WebDriverAgentMac/IntegrationTests/AMWindowTests.m +427 -0
  4. package/WebDriverAgentMac/WebDriverAgentLib/Commands/AMWindowCommands.m +63 -0
  5. package/WebDriverAgentMac/WebDriverAgentLib/Commands/FBDebugCommands.m +2 -0
  6. package/WebDriverAgentMac/WebDriverAgentLib/Commands/FBSessionCommands.m +17 -5
  7. package/WebDriverAgentMac/WebDriverAgentLib/Routing/FBCommandStatus.h +3 -0
  8. package/WebDriverAgentMac/WebDriverAgentLib/Routing/FBCommandStatus.m +13 -0
  9. package/WebDriverAgentMac/WebDriverAgentLib/Routing/FBSession.m +5 -1
  10. package/WebDriverAgentMac/WebDriverAgentLib/Utilities/AMScreenUtils.h +4 -0
  11. package/WebDriverAgentMac/WebDriverAgentLib/Utilities/AMScreenUtils.m +23 -0
  12. package/WebDriverAgentMac/WebDriverAgentLib/Utilities/AMSnapshotUtils.h +18 -0
  13. package/WebDriverAgentMac/WebDriverAgentLib/Utilities/AMSnapshotUtils.m +43 -28
  14. package/WebDriverAgentMac/WebDriverAgentLib/Utilities/AMWindowUtils.h +111 -0
  15. package/WebDriverAgentMac/WebDriverAgentLib/Utilities/AMWindowUtils.m +780 -0
  16. package/WebDriverAgentMac/WebDriverAgentLib/Utilities/AMXCTAccessibility.h +61 -0
  17. package/WebDriverAgentMac/WebDriverAgentLib/Utilities/AMXCTAccessibility.m +108 -0
  18. package/WebDriverAgentMac/WebDriverAgentMac.xcodeproj/project.pbxproj +20 -0
  19. package/build/lib/commands/native-record-screen.d.ts +2 -0
  20. package/build/lib/commands/native-record-screen.d.ts.map +1 -1
  21. package/build/lib/commands/native-record-screen.js.map +1 -1
  22. package/build/lib/commands/windows.d.ts +22 -0
  23. package/build/lib/commands/windows.d.ts.map +1 -0
  24. package/build/lib/commands/windows.js +32 -0
  25. package/build/lib/commands/windows.js.map +1 -0
  26. package/build/lib/driver.d.ts +15 -0
  27. package/build/lib/driver.d.ts.map +1 -1
  28. package/build/lib/driver.js +55 -32
  29. package/build/lib/driver.js.map +1 -1
  30. package/build/lib/execute-method-map.d.ts +9 -0
  31. package/build/lib/execute-method-map.d.ts.map +1 -1
  32. package/build/lib/execute-method-map.js +9 -0
  33. package/build/lib/execute-method-map.js.map +1 -1
  34. package/build/lib/session-claim-handler.d.ts +41 -0
  35. package/build/lib/session-claim-handler.d.ts.map +1 -0
  36. package/build/lib/session-claim-handler.js +236 -0
  37. package/build/lib/session-claim-handler.js.map +1 -0
  38. package/build/lib/types.d.ts +26 -0
  39. package/build/lib/types.d.ts.map +1 -1
  40. package/build/lib/wda-mac.d.ts +6 -2
  41. package/build/lib/wda-mac.d.ts.map +1 -1
  42. package/build/lib/wda-mac.js +39 -9
  43. package/build/lib/wda-mac.js.map +1 -1
  44. package/lib/commands/native-record-screen.ts +2 -0
  45. package/lib/commands/windows.ts +44 -0
  46. package/lib/driver.ts +59 -31
  47. package/lib/execute-method-map.ts +9 -0
  48. package/lib/session-claim-handler.ts +306 -0
  49. package/lib/types.ts +28 -0
  50. package/lib/wda-mac.ts +41 -10
  51. package/node_modules/appium-xcode/CHANGELOG.md +7 -0
  52. package/node_modules/appium-xcode/package.json +4 -4
  53. package/node_modules/async-lock/AUTHORS +21 -0
  54. package/node_modules/async-lock/History.md +132 -0
  55. package/node_modules/async-lock/LICENSE +22 -0
  56. package/node_modules/async-lock/README.md +177 -0
  57. package/node_modules/async-lock/index.js +2 -0
  58. package/node_modules/async-lock/lib/index.js +312 -0
  59. package/node_modules/async-lock/package.json +48 -0
  60. package/node_modules/bare-fs/binding.c +1 -1
  61. package/node_modules/bare-fs/index.js +30 -6
  62. package/node_modules/bare-fs/package.json +1 -1
  63. package/node_modules/bare-fs/prebuilds/android-arm/bare-fs.bare +0 -0
  64. package/node_modules/bare-fs/prebuilds/android-arm64/bare-fs.bare +0 -0
  65. package/node_modules/bare-fs/prebuilds/android-ia32/bare-fs.bare +0 -0
  66. package/node_modules/bare-fs/prebuilds/android-x64/bare-fs.bare +0 -0
  67. package/node_modules/bare-fs/prebuilds/darwin-arm64/bare-fs.bare +0 -0
  68. package/node_modules/bare-fs/prebuilds/darwin-x64/bare-fs.bare +0 -0
  69. package/node_modules/bare-fs/prebuilds/ios-arm64/bare-fs.bare +0 -0
  70. package/node_modules/bare-fs/prebuilds/ios-arm64-simulator/bare-fs.bare +0 -0
  71. package/node_modules/bare-fs/prebuilds/ios-x64-simulator/bare-fs.bare +0 -0
  72. package/node_modules/bare-fs/prebuilds/linux-arm64/bare-fs.bare +0 -0
  73. package/node_modules/bare-fs/prebuilds/linux-x64/bare-fs.bare +0 -0
  74. package/node_modules/bare-fs/prebuilds/win32-arm64/bare-fs.bare +0 -0
  75. package/node_modules/bare-fs/prebuilds/win32-x64/bare-fs.bare +0 -0
  76. package/node_modules/bare-url/README.md +4 -0
  77. package/node_modules/bare-url/index.d.ts +3 -0
  78. package/node_modules/bare-url/index.js +42 -18
  79. package/node_modules/bare-url/lib/errors.js +4 -0
  80. package/node_modules/bare-url/package.json +1 -1
  81. package/node_modules/bare-url/prebuilds/android-arm/bare-url.bare +0 -0
  82. package/node_modules/bare-url/prebuilds/android-arm64/bare-url.bare +0 -0
  83. package/node_modules/bare-url/prebuilds/android-ia32/bare-url.bare +0 -0
  84. package/node_modules/bare-url/prebuilds/android-x64/bare-url.bare +0 -0
  85. package/node_modules/bare-url/prebuilds/darwin-arm64/bare-url.bare +0 -0
  86. package/node_modules/bare-url/prebuilds/darwin-x64/bare-url.bare +0 -0
  87. package/node_modules/bare-url/prebuilds/ios-arm64/bare-url.bare +0 -0
  88. package/node_modules/bare-url/prebuilds/ios-arm64-simulator/bare-url.bare +0 -0
  89. package/node_modules/bare-url/prebuilds/ios-x64-simulator/bare-url.bare +0 -0
  90. package/node_modules/bare-url/prebuilds/linux-arm64/bare-url.bare +0 -0
  91. package/node_modules/bare-url/prebuilds/linux-x64/bare-url.bare +0 -0
  92. package/node_modules/bare-url/prebuilds/win32-arm64/bare-url.bare +0 -0
  93. package/node_modules/bare-url/prebuilds/win32-x64/bare-url.bare +0 -0
  94. package/node_modules/readable-stream/lib/internal/shims/process.js +19 -0
  95. package/node_modules/readable-stream/lib/internal/streams/destroy.js +1 -1
  96. package/node_modules/readable-stream/lib/internal/streams/duplexify.js +1 -1
  97. package/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +1 -1
  98. package/node_modules/readable-stream/lib/internal/streams/from.js +1 -1
  99. package/node_modules/readable-stream/lib/internal/streams/legacy.js +6 -1
  100. package/node_modules/readable-stream/lib/internal/streams/pipeline.js +1 -1
  101. package/node_modules/readable-stream/lib/internal/streams/readable.js +1 -1
  102. package/node_modules/readable-stream/lib/internal/streams/writable.js +1 -1
  103. package/node_modules/readable-stream/package.json +3 -2
  104. package/node_modules/tar-stream/package.json +7 -7
  105. package/package.json +6 -3
  106. package/scripts/setup-accessibility.mjs +175 -0
@@ -0,0 +1,175 @@
1
+ import fs from 'node:fs/promises';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import {fileURLToPath} from 'node:url';
5
+
6
+ import {logger} from 'appium/support.js';
7
+ import {exec} from 'teen_process';
8
+
9
+ const RUNNER_NAME = 'WebDriverAgentRunner-Runner.app';
10
+ const RUNNER_SCHEME = 'WebDriverAgentRunner';
11
+ // Keep the build arguments in sync with the driver, so it reuses this build without re-signing it
12
+ const DISABLE_STORE_ARG = 'COMPILER_INDEX_STORE_ENABLE=NO';
13
+ const XCODEPROJ_NAME = 'WebDriverAgentMac.xcodeproj';
14
+ const DERIVED_DATA_ROOT = path.join(os.homedir(), 'Library', 'Developer', 'Xcode', 'DerivedData');
15
+ const SETTINGS_URL = 'x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility';
16
+ const NO_OPEN_FLAG = '--no-open';
17
+ const RUNNER_PATH_ENV = 'WDA_RUNNER_PATH';
18
+ const KEEP_RUNNING_FLAG = '--keep-running';
19
+ const RUNNER_EXECUTABLE_FRAGMENT = `/${RUNNER_NAME}/Contents/MacOS/`;
20
+
21
+ const log = logger.getLogger('WDA');
22
+
23
+ async function exists(p) {
24
+ try {
25
+ await fs.access(p);
26
+ return true;
27
+ } catch {
28
+ return false;
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Xcode stores the project path of each derived data folder in its info.plist
34
+ */
35
+ async function readWorkspacePath(derivedDataDir) {
36
+ try {
37
+ const {stdout} = await exec('plutil', [
38
+ '-extract',
39
+ 'WorkspacePath',
40
+ 'raw',
41
+ '-o',
42
+ '-',
43
+ path.join(derivedDataDir, 'info.plist'),
44
+ ]);
45
+ return stdout.trim();
46
+ } catch {
47
+ return null;
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Finds the runner app built from the WebDriverAgent project of this driver.
53
+ * The newest one wins if there are many.
54
+ */
55
+ async function findRunner(projectPath) {
56
+ let entries;
57
+ try {
58
+ entries = await fs.readdir(DERIVED_DATA_ROOT);
59
+ } catch {
60
+ return null;
61
+ }
62
+ const candidates = [];
63
+ for (const entry of entries.filter((name) => name.startsWith('WebDriverAgentMac-'))) {
64
+ const derivedDataDir = path.join(DERIVED_DATA_ROOT, entry);
65
+ const runnerPath = path.join(derivedDataDir, 'Build', 'Products', 'Debug', RUNNER_NAME);
66
+ if (!(await exists(runnerPath)) || (await readWorkspacePath(derivedDataDir)) !== projectPath) {
67
+ continue;
68
+ }
69
+ candidates.push({runnerPath, mtimeMs: (await fs.stat(runnerPath)).mtimeMs});
70
+ }
71
+ return candidates.sort((a, b) => b.mtimeMs - a.mtimeMs)[0]?.runnerPath ?? null;
72
+ }
73
+
74
+ /**
75
+ * Stops the runner and the xcodebuild process that hosts it. macOS evaluates the permission
76
+ * when a process starts, so a runner started before the grant stays untrusted.
77
+ * Appium itself keeps running, but an active session loses its runner.
78
+ */
79
+ async function stopRunningRunners() {
80
+ const {stdout} = await exec('ps', ['-axo', 'pid=,command=']);
81
+ const pids = [];
82
+ for (const line of stdout.split('\n')) {
83
+ const match = line.trim().match(/^(\d+)\s+(.*)$/);
84
+ if (!match) {
85
+ continue;
86
+ }
87
+ const pid = Number(match[1]);
88
+ const command = match[2];
89
+ const isRunner = command.includes(RUNNER_EXECUTABLE_FRAGMENT);
90
+ const isHost =
91
+ /(^|\/)xcodebuild\s/.test(command) &&
92
+ command.includes('test-without-building') &&
93
+ command.includes(`-scheme ${RUNNER_SCHEME}`);
94
+ if ((isRunner || isHost) && pid !== process.pid && pid !== process.ppid) {
95
+ pids.push(pid);
96
+ }
97
+ }
98
+ for (const pid of pids) {
99
+ try {
100
+ process.kill(pid, 'SIGTERM');
101
+ } catch (e) {
102
+ log.warn(`Cannot stop the process ${pid}: ${e.message}`);
103
+ }
104
+ }
105
+ if (pids.length > 0) {
106
+ log.info(`Stopped the running WebDriverAgent processes: ${pids.join(', ')}`);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Builds the runner the same way the driver does
112
+ */
113
+ async function buildRunner(projectPath) {
114
+ log.info(`Building ${RUNNER_NAME}. This may take a few minutes`);
115
+ try {
116
+ await exec(
117
+ 'xcodebuild',
118
+ ['build-for-testing', '-project', projectPath, '-scheme', RUNNER_SCHEME, DISABLE_STORE_ARG],
119
+ {cwd: path.dirname(projectPath)},
120
+ );
121
+ } catch (e) {
122
+ const output = String(e.stdout ?? '')
123
+ .trim()
124
+ .split('\n')
125
+ .slice(-20)
126
+ .join('\n');
127
+ throw new Error(`Cannot build ${RUNNER_NAME}: ${e.stderr || e.message}\n${output}`, {cause: e});
128
+ }
129
+ }
130
+
131
+ async function setupAccessibility() {
132
+ const args = process.argv.slice(2);
133
+ const shouldOpen = !args.includes(NO_OPEN_FLAG);
134
+ const shouldStop = !args.includes(KEEP_RUNNING_FLAG);
135
+ const explicitPath = args.find((arg) => !arg.startsWith('--')) ?? process.env[RUNNER_PATH_ENV];
136
+
137
+ if (shouldStop) {
138
+ await stopRunningRunners();
139
+ }
140
+
141
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
142
+ const projectPath = path.resolve(__dirname, '..', 'WebDriverAgentMac', XCODEPROJ_NAME);
143
+ let runnerPath = explicitPath ? path.resolve(explicitPath) : await findRunner(projectPath);
144
+ if (!runnerPath && !explicitPath) {
145
+ await buildRunner(projectPath);
146
+ runnerPath = await findRunner(projectPath);
147
+ }
148
+ if (!runnerPath || !(await exists(runnerPath))) {
149
+ log.error(
150
+ `Cannot find ${RUNNER_NAME}${explicitPath ? ` at '${runnerPath}'` : ` built from '${projectPath}'`}. ` +
151
+ `If your Xcode derived data folder is not in '${DERIVED_DATA_ROOT}', ` +
152
+ `set the ${RUNNER_PATH_ENV} environment variable to the full path to ${RUNNER_NAME}.`,
153
+ );
154
+ process.exitCode = 1;
155
+ return;
156
+ }
157
+
158
+ log.info(`WebDriverAgent runner: '${runnerPath}'`);
159
+ log.info(
160
+ `Add the runner to System Settings > Privacy & Security > Accessibility and turn it on. ` +
161
+ `Then restart your Appium session. Do not rebuild the runner after granting the permission, ` +
162
+ `because the grant may be tied to the exact build.`,
163
+ );
164
+ if (!shouldOpen) {
165
+ return;
166
+ }
167
+ // Selects the runner in Finder, so it can be dragged into the Accessibility list
168
+ await exec('open', ['-R', runnerPath]);
169
+ await exec('open', [SETTINGS_URL]);
170
+ }
171
+
172
+ setupAccessibility().catch((e) => {
173
+ log.error(e.message);
174
+ process.exitCode = 1;
175
+ });