spana-test 0.0.1 → 0.1.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.
- package/.agents/skills/spana-testing/SKILL.md +301 -0
- package/README.md +276 -0
- package/dist/agent/index.d.ts +81 -0
- package/dist/agent/index.js +21 -0
- package/dist/allure-PTTVORQ6.js +124 -0
- package/dist/allure-PTTVORQ6.js.map +1 -0
- package/dist/android-PAPJJWVN.js +34 -0
- package/dist/android-PAPJJWVN.js.map +1 -0
- package/dist/chunk-3FSZNKEF.js +62 -0
- package/dist/chunk-3FSZNKEF.js.map +1 -0
- package/dist/chunk-53MUJUJY.js +113 -0
- package/dist/chunk-53MUJUJY.js.map +1 -0
- package/dist/chunk-5XO6S7AI.js +134 -0
- package/dist/chunk-5XO6S7AI.js.map +1 -0
- package/dist/chunk-BZRLA4Z3.js +82 -0
- package/dist/chunk-BZRLA4Z3.js.map +1 -0
- package/dist/{chunk-PF7V37UD.js → chunk-CKJQX73M.js} +897 -845
- package/dist/chunk-CKJQX73M.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/{chunk-HKDZMXD7.js → chunk-GZK22EIE.js} +76 -102
- package/dist/chunk-GZK22EIE.js.map +1 -0
- package/dist/chunk-PANFRTIU.js +310 -0
- package/dist/chunk-PANFRTIU.js.map +1 -0
- package/dist/chunk-PWEOJKUF.js +473 -0
- package/dist/chunk-PWEOJKUF.js.map +1 -0
- package/dist/chunk-RJ5VPHVX.js +127 -0
- package/dist/chunk-RJ5VPHVX.js.map +1 -0
- package/dist/chunk-RK4Z6C7M.js +248 -0
- package/dist/chunk-RK4Z6C7M.js.map +1 -0
- package/dist/chunk-U564GCO2.js +259 -0
- package/dist/chunk-U564GCO2.js.map +1 -0
- package/dist/chunk-V62HFH6E.js +269 -0
- package/dist/chunk-V62HFH6E.js.map +1 -0
- package/dist/chunk-VDWWIVM6.js +303 -0
- package/dist/chunk-VDWWIVM6.js.map +1 -0
- package/dist/{discover-4EZKZ5RO.js → chunk-WIJYK22K.js} +12 -5
- package/dist/{discover-4EZKZ5RO.js.map → chunk-WIJYK22K.js.map} +1 -1
- package/dist/cli.js +135 -17
- package/dist/cli.js.map +1 -1
- package/dist/compiler-G75RIIYS.js +312 -0
- package/dist/compiler-G75RIIYS.js.map +1 -0
- package/dist/config-Dg9O0rcQ.d.ts +219 -0
- package/dist/config-loader-JJ5RPP53.js +9 -0
- package/dist/config-loader-JJ5RPP53.js.map +1 -0
- package/dist/console-FV4RJPO4.js +132 -0
- package/dist/console-FV4RJPO4.js.map +1 -0
- package/dist/discover-RWBKI5IB.js +14 -0
- package/dist/discover-RWBKI5IB.js.map +1 -0
- package/dist/element-CGteXiXB.d.ts +23 -0
- package/dist/flow-D-_tlLpp.d.ts +99 -0
- package/dist/gherkin/steps.d.ts +32 -0
- package/dist/gherkin/steps.js +39 -0
- package/dist/gherkin/steps.js.map +1 -0
- package/dist/{html-OGRQ5NIX.js → html-JP2HBIJQ.js} +54 -20
- package/dist/html-JP2HBIJQ.js.map +1 -0
- package/dist/index.d.ts +4 -157
- package/dist/index.js +36 -165
- package/dist/index.js.map +1 -1
- package/dist/init-command-CELKL2CX.js +105 -0
- package/dist/init-command-CELKL2CX.js.map +1 -0
- package/dist/installer-R6NX7BYQ.js +20 -0
- package/dist/installer-R6NX7BYQ.js.map +1 -0
- package/dist/ios-ZZU6DHH7.js +48 -0
- package/dist/ios-ZZU6DHH7.js.map +1 -0
- package/dist/{json-3TZD6FI5.js → json-JMRPUVY2.js} +2 -2
- package/dist/{junit-ES66OYVX.js → junit-UDY5JG22.js} +14 -3
- package/dist/junit-UDY5JG22.js.map +1 -0
- package/dist/provider-CUWPULGC.js +10 -0
- package/dist/provider-CUWPULGC.js.map +1 -0
- package/dist/redact-IDA3C4UH.js +77 -0
- package/dist/redact-IDA3C4UH.js.map +1 -0
- package/dist/runner-QEF6PJOE.js +20 -0
- package/dist/runner-QEF6PJOE.js.map +1 -0
- package/dist/server-MMK7PZIH.js +505 -0
- package/dist/server-MMK7PZIH.js.map +1 -0
- package/dist/session-FBJABNXL.js +16 -0
- package/dist/session-FBJABNXL.js.map +1 -0
- package/dist/studio-command-CDVPREMG.js +24 -0
- package/dist/studio-command-CDVPREMG.js.map +1 -0
- package/dist/test-command-SB5KYPQI.js +1929 -0
- package/dist/test-command-SB5KYPQI.js.map +1 -0
- package/dist/validator-CFQ55NUQ.js +13 -0
- package/dist/validator-CFQ55NUQ.js.map +1 -0
- package/package.json +43 -5
- package/studio-dist/assets/index-CPdpC9i-.css +1 -0
- package/studio-dist/assets/index-L1Wd0vop.js +183 -0
- package/studio-dist/index.html +13 -0
- package/dist/chunk-HKDZMXD7.js.map +0 -1
- package/dist/chunk-PF7V37UD.js.map +0 -1
- package/dist/chunk-Y7MNYLGH.js +0 -64
- package/dist/chunk-Y7MNYLGH.js.map +0 -1
- package/dist/console-ZH3SUKUO.js +0 -71
- package/dist/console-ZH3SUKUO.js.map +0 -1
- package/dist/html-OGRQ5NIX.js.map +0 -1
- package/dist/junit-ES66OYVX.js.map +0 -1
- package/dist/runner-NGLCXD2E.js +0 -12
- package/dist/session-NWNZWWNI.js +0 -122
- package/dist/session-NWNZWWNI.js.map +0 -1
- package/dist/test-command-F3AEHF2E.js +0 -636
- package/dist/test-command-F3AEHF2E.js.map +0 -1
- package/dist/validator-LHN66ZH7.js +0 -33
- package/dist/validator-LHN66ZH7.js.map +0 -1
- /package/dist/{runner-NGLCXD2E.js.map → agent/index.js.map} +0 -0
- /package/dist/{json-3TZD6FI5.js.map → json-JMRPUVY2.js.map} +0 -0
|
@@ -0,0 +1,1929 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadConfig
|
|
3
|
+
} from "./chunk-53MUJUJY.js";
|
|
4
|
+
import {
|
|
5
|
+
createCloudProviderHelper,
|
|
6
|
+
detectProvider
|
|
7
|
+
} from "./chunk-PWEOJKUF.js";
|
|
8
|
+
import {
|
|
9
|
+
createPromiseApp,
|
|
10
|
+
createPromiseExpect
|
|
11
|
+
} from "./chunk-PANFRTIU.js";
|
|
12
|
+
import "./chunk-RJ5VPHVX.js";
|
|
13
|
+
import {
|
|
14
|
+
createUiAutomator2Driver,
|
|
15
|
+
createWDADriver,
|
|
16
|
+
makePlaywrightDriver,
|
|
17
|
+
parseAndroidHierarchy,
|
|
18
|
+
parseIOSHierarchy,
|
|
19
|
+
parseWebHierarchy,
|
|
20
|
+
setupUiAutomator2
|
|
21
|
+
} from "./chunk-CKJQX73M.js";
|
|
22
|
+
import {
|
|
23
|
+
applyShard,
|
|
24
|
+
discoverFlows,
|
|
25
|
+
discoverStepFiles,
|
|
26
|
+
filterFlows,
|
|
27
|
+
loadStepFiles,
|
|
28
|
+
loadTestSource
|
|
29
|
+
} from "./chunk-5XO6S7AI.js";
|
|
30
|
+
import {
|
|
31
|
+
DriverError,
|
|
32
|
+
flattenElements
|
|
33
|
+
} from "./chunk-U564GCO2.js";
|
|
34
|
+
import {
|
|
35
|
+
allocatePort,
|
|
36
|
+
setupWDA
|
|
37
|
+
} from "./chunk-RK4Z6C7M.js";
|
|
38
|
+
import {
|
|
39
|
+
ensureAndroidDevice
|
|
40
|
+
} from "./chunk-GZK22EIE.js";
|
|
41
|
+
import {
|
|
42
|
+
connectPhysicalDevice,
|
|
43
|
+
ensureAppInstalled,
|
|
44
|
+
ensureIOSSimulator,
|
|
45
|
+
firstIOSPhysicalDevice
|
|
46
|
+
} from "./chunk-V62HFH6E.js";
|
|
47
|
+
import "./chunk-DGUM43GV.js";
|
|
48
|
+
|
|
49
|
+
// src/cli/test-command.ts
|
|
50
|
+
import { resolve, dirname } from "path";
|
|
51
|
+
|
|
52
|
+
// src/core/artifacts.ts
|
|
53
|
+
import { writeFileSync, mkdirSync } from "fs";
|
|
54
|
+
import { join } from "path";
|
|
55
|
+
import { Effect } from "effect";
|
|
56
|
+
var DEFAULT_ARTIFACT_CONFIG = {
|
|
57
|
+
outputDir: "./spana-output",
|
|
58
|
+
captureOnFailure: true,
|
|
59
|
+
captureOnSuccess: false,
|
|
60
|
+
captureSteps: false,
|
|
61
|
+
screenshot: true,
|
|
62
|
+
uiHierarchy: true
|
|
63
|
+
};
|
|
64
|
+
function safeName(value) {
|
|
65
|
+
return value.replace(/[^a-zA-Z0-9-_]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "").slice(0, 80) || "artifact";
|
|
66
|
+
}
|
|
67
|
+
function flowArtifactDir(config, flowName, platform) {
|
|
68
|
+
const dir = join(config.outputDir, `${safeName(flowName)}-${platform}`);
|
|
69
|
+
mkdirSync(dir, { recursive: true });
|
|
70
|
+
return dir;
|
|
71
|
+
}
|
|
72
|
+
function createAttachment(name, contentType, path) {
|
|
73
|
+
return { name, contentType, path };
|
|
74
|
+
}
|
|
75
|
+
function resolveArtifactConfig(...configs) {
|
|
76
|
+
return configs.reduce(
|
|
77
|
+
(resolved, config) => ({
|
|
78
|
+
...resolved,
|
|
79
|
+
...config
|
|
80
|
+
}),
|
|
81
|
+
{ ...DEFAULT_ARTIFACT_CONFIG }
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
async function captureArtifacts(driver, config, flowName, platform, status) {
|
|
85
|
+
const shouldCapture = status === "failed" && config.captureOnFailure || status === "passed" && config.captureOnSuccess;
|
|
86
|
+
if (!shouldCapture) return [];
|
|
87
|
+
const attachments = [];
|
|
88
|
+
const dir = flowArtifactDir(config, flowName, platform);
|
|
89
|
+
if (config.screenshot) {
|
|
90
|
+
try {
|
|
91
|
+
const screenshot = await Effect.runPromise(Effect.orDie(driver.takeScreenshot()));
|
|
92
|
+
const path = join(dir, "screenshot.png");
|
|
93
|
+
writeFileSync(path, screenshot);
|
|
94
|
+
attachments.push(createAttachment(`${status}-screenshot`, "image/png", path));
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (config.uiHierarchy) {
|
|
99
|
+
try {
|
|
100
|
+
const hierarchy = await Effect.runPromise(Effect.orDie(driver.dumpHierarchy()));
|
|
101
|
+
const path = join(dir, "hierarchy.json");
|
|
102
|
+
writeFileSync(path, hierarchy, "utf-8");
|
|
103
|
+
attachments.push(createAttachment(`${status}-hierarchy`, "application/json", path));
|
|
104
|
+
} catch {
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return attachments;
|
|
108
|
+
}
|
|
109
|
+
async function captureStepScreenshot(driver, config, flowName, platform, stepIndex, stepName, screenshot) {
|
|
110
|
+
if (!config.screenshot) return void 0;
|
|
111
|
+
try {
|
|
112
|
+
const dir = join(flowArtifactDir(config, flowName, platform), "steps");
|
|
113
|
+
mkdirSync(dir, { recursive: true });
|
|
114
|
+
const fileName = `${String(stepIndex).padStart(3, "0")}-${safeName(stepName)}.png`;
|
|
115
|
+
const path = join(dir, fileName);
|
|
116
|
+
const bytes = screenshot ?? await Effect.runPromise(Effect.orDie(driver.takeScreenshot()));
|
|
117
|
+
writeFileSync(path, bytes);
|
|
118
|
+
return createAttachment(stepName, "image/png", path);
|
|
119
|
+
} catch {
|
|
120
|
+
return void 0;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/core/debug-repl.ts
|
|
125
|
+
import * as repl from "repl";
|
|
126
|
+
import { Effect as Effect2 } from "effect";
|
|
127
|
+
var didStartDebugRepl = false;
|
|
128
|
+
function toSuggestedSelectors(root) {
|
|
129
|
+
return flattenElements(root).filter((el) => el.visible !== false && (el.id || el.text || el.accessibilityLabel)).map((el) => ({
|
|
130
|
+
suggestedSelector: el.id ? { testID: el.id } : el.accessibilityLabel ? { accessibilityLabel: el.accessibilityLabel } : el.text ? { text: el.text } : "",
|
|
131
|
+
elementType: el.elementType,
|
|
132
|
+
text: el.text,
|
|
133
|
+
accessibilityLabel: el.accessibilityLabel,
|
|
134
|
+
bounds: el.bounds,
|
|
135
|
+
id: el.id
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
async function runDebugReplOnce(context) {
|
|
139
|
+
if (didStartDebugRepl) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
didStartDebugRepl = true;
|
|
143
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
144
|
+
console.log("Skipping debug REPL because stdin/stdout is not interactive.");
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
const hierarchy = async () => context.parseHierarchy(await Effect2.runPromise(context.driver.dumpHierarchy()));
|
|
148
|
+
const selectors = async () => toSuggestedSelectors(await hierarchy());
|
|
149
|
+
console.log("");
|
|
150
|
+
console.log(`Entering debug REPL for failed flow "${context.flowName}" on ${context.platform}.`);
|
|
151
|
+
console.log(
|
|
152
|
+
"Available bindings: app, expect, driver, platform, flowName, error, hierarchy(), selectors(), help()"
|
|
153
|
+
);
|
|
154
|
+
console.log('Use top-level await for async calls, for example: await app.tap({ text: "Login" })');
|
|
155
|
+
const replServer = repl.start({
|
|
156
|
+
prompt: `spana:${context.platform}> `,
|
|
157
|
+
ignoreUndefined: true,
|
|
158
|
+
useGlobal: false
|
|
159
|
+
});
|
|
160
|
+
replServer.context.app = context.app;
|
|
161
|
+
replServer.context.expect = context.expect;
|
|
162
|
+
replServer.context.driver = context.driver;
|
|
163
|
+
replServer.context.platform = context.platform;
|
|
164
|
+
replServer.context.flowName = context.flowName;
|
|
165
|
+
replServer.context.error = context.error;
|
|
166
|
+
replServer.context.hierarchy = hierarchy;
|
|
167
|
+
replServer.context.selectors = selectors;
|
|
168
|
+
replServer.context.help = () => {
|
|
169
|
+
console.log("app Promise-based app API with auto-waiting");
|
|
170
|
+
console.log("expect Assertion helper, e.g. await expect({ text: 'Done' }).toBeVisible()");
|
|
171
|
+
console.log("driver Raw driver service");
|
|
172
|
+
console.log("hierarchy Async helper returning the parsed UI tree");
|
|
173
|
+
console.log("selectors Async helper returning suggested selectors");
|
|
174
|
+
console.log(".exit Leave the REPL");
|
|
175
|
+
};
|
|
176
|
+
await new Promise((resolve2) => replServer.on("exit", resolve2));
|
|
177
|
+
console.log("");
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/core/step-recorder.ts
|
|
182
|
+
function errorMessage(error) {
|
|
183
|
+
return error instanceof Error ? error.message : String(error);
|
|
184
|
+
}
|
|
185
|
+
function createStepResult(command, durationMs, status, selector, error, attachments) {
|
|
186
|
+
return {
|
|
187
|
+
command,
|
|
188
|
+
selector,
|
|
189
|
+
status,
|
|
190
|
+
durationMs,
|
|
191
|
+
error,
|
|
192
|
+
attachments: attachments && attachments.length > 0 ? attachments : void 0
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function createStepRecorder(driver, artifactConfig, flowName, platform) {
|
|
196
|
+
const steps = [];
|
|
197
|
+
return {
|
|
198
|
+
async runStep(command, action, opts) {
|
|
199
|
+
const startedAt = Date.now();
|
|
200
|
+
try {
|
|
201
|
+
const result = await action();
|
|
202
|
+
const attachments = [];
|
|
203
|
+
if (opts?.captureScreenshot && artifactConfig.captureSteps) {
|
|
204
|
+
const attachment = await captureStepScreenshot(
|
|
205
|
+
driver,
|
|
206
|
+
artifactConfig,
|
|
207
|
+
flowName,
|
|
208
|
+
platform,
|
|
209
|
+
steps.length + 1,
|
|
210
|
+
command
|
|
211
|
+
);
|
|
212
|
+
if (attachment) attachments.push(attachment);
|
|
213
|
+
}
|
|
214
|
+
steps.push(
|
|
215
|
+
createStepResult(
|
|
216
|
+
command,
|
|
217
|
+
Date.now() - startedAt,
|
|
218
|
+
"passed",
|
|
219
|
+
opts?.selector,
|
|
220
|
+
void 0,
|
|
221
|
+
attachments
|
|
222
|
+
)
|
|
223
|
+
);
|
|
224
|
+
return result;
|
|
225
|
+
} catch (error) {
|
|
226
|
+
steps.push(
|
|
227
|
+
createStepResult(
|
|
228
|
+
command,
|
|
229
|
+
Date.now() - startedAt,
|
|
230
|
+
"failed",
|
|
231
|
+
opts?.selector,
|
|
232
|
+
errorMessage(error)
|
|
233
|
+
)
|
|
234
|
+
);
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
async runScreenshotStep(command, action, opts) {
|
|
239
|
+
const startedAt = Date.now();
|
|
240
|
+
try {
|
|
241
|
+
const screenshot = await action();
|
|
242
|
+
const attachment = await captureStepScreenshot(
|
|
243
|
+
driver,
|
|
244
|
+
artifactConfig,
|
|
245
|
+
flowName,
|
|
246
|
+
platform,
|
|
247
|
+
steps.length + 1,
|
|
248
|
+
opts?.name ?? command,
|
|
249
|
+
screenshot
|
|
250
|
+
);
|
|
251
|
+
steps.push(
|
|
252
|
+
createStepResult(
|
|
253
|
+
command,
|
|
254
|
+
Date.now() - startedAt,
|
|
255
|
+
"passed",
|
|
256
|
+
opts?.selector,
|
|
257
|
+
void 0,
|
|
258
|
+
attachment ? [attachment] : void 0
|
|
259
|
+
)
|
|
260
|
+
);
|
|
261
|
+
return screenshot;
|
|
262
|
+
} catch (error) {
|
|
263
|
+
steps.push(
|
|
264
|
+
createStepResult(
|
|
265
|
+
command,
|
|
266
|
+
Date.now() - startedAt,
|
|
267
|
+
"failed",
|
|
268
|
+
opts?.selector,
|
|
269
|
+
errorMessage(error)
|
|
270
|
+
)
|
|
271
|
+
);
|
|
272
|
+
throw error;
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
getSteps() {
|
|
276
|
+
return steps;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/report/classify-error.ts
|
|
282
|
+
var TAG_KEY = "_tag";
|
|
283
|
+
function selectorHint(selector) {
|
|
284
|
+
if (selector && typeof selector === "object") {
|
|
285
|
+
const s = selector;
|
|
286
|
+
if (s.testID) return `testID="${s.testID}"`;
|
|
287
|
+
if (s.text) return `text="${s.text}"`;
|
|
288
|
+
if (s.accessibilityLabel) return `accessibilityLabel="${s.accessibilityLabel}"`;
|
|
289
|
+
}
|
|
290
|
+
return JSON.stringify(selector);
|
|
291
|
+
}
|
|
292
|
+
function categorize(error) {
|
|
293
|
+
const tag = error[TAG_KEY];
|
|
294
|
+
if (tag === "ElementNotFoundError" || tag === "WaitTimeoutError") {
|
|
295
|
+
const sel = selectorHint(error.selector);
|
|
296
|
+
return {
|
|
297
|
+
category: "element-not-found",
|
|
298
|
+
suggestion: [
|
|
299
|
+
`Selector ${sel} was not found within ${error.timeoutMs ?? "?"}ms.`,
|
|
300
|
+
"Try: run `spana selectors` to see available selectors on the current screen,",
|
|
301
|
+
"or increase the timeout with `{ timeout: 10000 }` on the assertion."
|
|
302
|
+
].join("\n")
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
if (tag === "TextMismatchError") {
|
|
306
|
+
const e = error;
|
|
307
|
+
return {
|
|
308
|
+
category: "text-mismatch",
|
|
309
|
+
suggestion: [
|
|
310
|
+
`Expected text "${e.expected}" but found "${e.actual ?? "(empty)"}".`,
|
|
311
|
+
"The element exists but its content differs. Check for whitespace, truncation,",
|
|
312
|
+
"or platform-specific text rendering differences."
|
|
313
|
+
].join("\n")
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
if (tag === "TimeoutError") {
|
|
317
|
+
return {
|
|
318
|
+
category: "timeout",
|
|
319
|
+
suggestion: [
|
|
320
|
+
"The operation took longer than the allowed timeout.",
|
|
321
|
+
"Try increasing `defaults.waitTimeout` in spana.config.ts,",
|
|
322
|
+
"or set a per-flow timeout: `flow('name', { timeout: 30000 }, ...)`."
|
|
323
|
+
].join("\n")
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
if (tag === "DeviceDisconnectedError") {
|
|
327
|
+
const id = error.deviceId ? ` (${error.deviceId})` : "";
|
|
328
|
+
return {
|
|
329
|
+
category: "device-disconnected",
|
|
330
|
+
suggestion: [
|
|
331
|
+
`The device${id} disconnected during the test.`,
|
|
332
|
+
"Check the physical connection or emulator/simulator stability.",
|
|
333
|
+
"Run `spana devices` to verify available devices."
|
|
334
|
+
].join("\n")
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
if (tag === "AppCrashedError") {
|
|
338
|
+
const app = error.appId ? ` (${error.appId})` : "";
|
|
339
|
+
return {
|
|
340
|
+
category: "app-crashed",
|
|
341
|
+
suggestion: [
|
|
342
|
+
`The app${app} crashed during the test.`,
|
|
343
|
+
"Check the device logs for a crash stack trace:",
|
|
344
|
+
" Android: `adb logcat -d | grep FATAL`",
|
|
345
|
+
" iOS: Check Console.app or `log show --predicate 'process == \"your-app\"'`"
|
|
346
|
+
].join("\n")
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
if (tag === "AppNotInstalledError") {
|
|
350
|
+
return {
|
|
351
|
+
category: "app-not-installed",
|
|
352
|
+
suggestion: [
|
|
353
|
+
`App "${error.appId}" is not installed on the device.`,
|
|
354
|
+
"Install it before running tests, or configure `apps.android.appPath`",
|
|
355
|
+
"/ `apps.ios.appPath` in spana.config.ts for auto-install."
|
|
356
|
+
].join("\n")
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
if (tag === "DriverError") {
|
|
360
|
+
return {
|
|
361
|
+
category: "driver-error",
|
|
362
|
+
suggestion: error.command ? `Driver command "${error.command}" failed. Check the device connection and driver logs.` : "A low-level driver operation failed. Check the device connection and driver logs."
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
if (tag === "ConfigError" || tag === "FlowSyntaxError") {
|
|
366
|
+
return {
|
|
367
|
+
category: "config-error",
|
|
368
|
+
suggestion: "Run `spana validate-config` to check your configuration."
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
const msg = error.message ?? "";
|
|
372
|
+
if (msg.includes("timed out") || msg.includes("Timed out")) {
|
|
373
|
+
return {
|
|
374
|
+
category: "timeout",
|
|
375
|
+
suggestion: "The operation timed out. Try increasing `defaults.waitTimeout` in spana.config.ts."
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
if (msg.includes("not found") || msg.includes("not visible")) {
|
|
379
|
+
return {
|
|
380
|
+
category: "element-not-found",
|
|
381
|
+
suggestion: "An element was not found. Run `spana selectors` to check available selectors on the current screen."
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
if (msg.includes("ECONNREFUSED") || msg.includes("ECONNRESET") || msg.includes("disconnected")) {
|
|
385
|
+
return {
|
|
386
|
+
category: "device-disconnected",
|
|
387
|
+
suggestion: "The connection was lost. Check the device or emulator/simulator is still running."
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
return { category: "unknown" };
|
|
391
|
+
}
|
|
392
|
+
function classifyError(error) {
|
|
393
|
+
const tagged = error;
|
|
394
|
+
const { category, suggestion } = categorize(tagged);
|
|
395
|
+
return {
|
|
396
|
+
message: error.message,
|
|
397
|
+
stack: error.stack,
|
|
398
|
+
category,
|
|
399
|
+
suggestion
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// src/core/engine.ts
|
|
404
|
+
async function executeFlow(flow, driver, config) {
|
|
405
|
+
const start2 = Date.now();
|
|
406
|
+
const { platform, coordinatorConfig, appId } = config;
|
|
407
|
+
const autoLaunch = flow.config.autoLaunch ?? config.autoLaunch ?? true;
|
|
408
|
+
const timeout = flow.config.timeout ?? config.flowTimeout ?? 6e4;
|
|
409
|
+
const artifactConfig = resolveArtifactConfig(config.artifactConfig, flow.config.artifacts);
|
|
410
|
+
const stepRecorder = createStepRecorder(driver, artifactConfig, flow.name, platform);
|
|
411
|
+
const flowDefaults = flow.config.defaults;
|
|
412
|
+
const mergedCoordinatorConfig = flowDefaults ? {
|
|
413
|
+
...coordinatorConfig,
|
|
414
|
+
defaults: {
|
|
415
|
+
...coordinatorConfig.defaults,
|
|
416
|
+
timeout: flowDefaults.waitTimeout ?? coordinatorConfig.defaults?.timeout,
|
|
417
|
+
pollInterval: flowDefaults.pollInterval ?? coordinatorConfig.defaults?.pollInterval,
|
|
418
|
+
settleTimeout: flowDefaults.settleTimeout ?? coordinatorConfig.defaults?.settleTimeout
|
|
419
|
+
},
|
|
420
|
+
waitForIdleTimeout: flowDefaults.waitForIdleTimeout ?? coordinatorConfig.waitForIdleTimeout,
|
|
421
|
+
typingDelay: flowDefaults.typingDelay ?? coordinatorConfig.typingDelay
|
|
422
|
+
} : coordinatorConfig;
|
|
423
|
+
const app = createPromiseApp(driver, appId, mergedCoordinatorConfig, stepRecorder);
|
|
424
|
+
const expect = createPromiseExpect(driver, mergedCoordinatorConfig, stepRecorder);
|
|
425
|
+
const flowCtx = { app, expect, platform };
|
|
426
|
+
if (config.hooks?.beforeEach) {
|
|
427
|
+
try {
|
|
428
|
+
await config.hooks.beforeEach({ app, platform });
|
|
429
|
+
} catch (error) {
|
|
430
|
+
return {
|
|
431
|
+
name: flow.name,
|
|
432
|
+
platform,
|
|
433
|
+
status: "failed",
|
|
434
|
+
durationMs: Date.now() - start2,
|
|
435
|
+
error: classifyError(error instanceof Error ? error : new Error(String(error)))
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
let result;
|
|
440
|
+
try {
|
|
441
|
+
if (autoLaunch) {
|
|
442
|
+
await app.launch(config.launchOptions);
|
|
443
|
+
}
|
|
444
|
+
await Promise.race([
|
|
445
|
+
flow.fn(flowCtx),
|
|
446
|
+
new Promise(
|
|
447
|
+
(_, reject) => setTimeout(
|
|
448
|
+
() => reject(new Error(`Flow "${flow.name}" timed out after ${timeout}ms`)),
|
|
449
|
+
timeout
|
|
450
|
+
)
|
|
451
|
+
)
|
|
452
|
+
]);
|
|
453
|
+
const attachments = await captureArtifacts(
|
|
454
|
+
driver,
|
|
455
|
+
artifactConfig,
|
|
456
|
+
flow.name,
|
|
457
|
+
platform,
|
|
458
|
+
"passed"
|
|
459
|
+
);
|
|
460
|
+
result = {
|
|
461
|
+
name: flow.name,
|
|
462
|
+
platform,
|
|
463
|
+
status: "passed",
|
|
464
|
+
durationMs: Date.now() - start2,
|
|
465
|
+
attachments,
|
|
466
|
+
steps: stepRecorder.getSteps(),
|
|
467
|
+
scenarioSteps: flowCtx.__scenarioSteps
|
|
468
|
+
};
|
|
469
|
+
} catch (error) {
|
|
470
|
+
const attachments = await captureArtifacts(
|
|
471
|
+
driver,
|
|
472
|
+
artifactConfig,
|
|
473
|
+
flow.name,
|
|
474
|
+
platform,
|
|
475
|
+
"failed"
|
|
476
|
+
);
|
|
477
|
+
const flowError = error instanceof Error ? error : new Error(String(error));
|
|
478
|
+
result = {
|
|
479
|
+
name: flow.name,
|
|
480
|
+
platform,
|
|
481
|
+
status: "failed",
|
|
482
|
+
durationMs: Date.now() - start2,
|
|
483
|
+
error: classifyError(flowError),
|
|
484
|
+
attachments,
|
|
485
|
+
steps: stepRecorder.getSteps(),
|
|
486
|
+
scenarioSteps: flowCtx.__scenarioSteps
|
|
487
|
+
};
|
|
488
|
+
if (config.debugOnFailure) {
|
|
489
|
+
await runDebugReplOnce({
|
|
490
|
+
app,
|
|
491
|
+
expect,
|
|
492
|
+
driver,
|
|
493
|
+
error: flowError,
|
|
494
|
+
flowName: flow.name,
|
|
495
|
+
platform,
|
|
496
|
+
parseHierarchy: coordinatorConfig.parse
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (config.hooks?.afterEach) {
|
|
501
|
+
try {
|
|
502
|
+
await config.hooks.afterEach({ app, platform, result });
|
|
503
|
+
} catch (hookError) {
|
|
504
|
+
console.warn(
|
|
505
|
+
`afterEach hook failed: ${hookError instanceof Error ? hookError.message : hookError}`
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return result;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// src/core/orchestrator.ts
|
|
513
|
+
async function orchestrate(flows, platforms, options) {
|
|
514
|
+
const start2 = Date.now();
|
|
515
|
+
const retries = options?.retries ?? 0;
|
|
516
|
+
const bail = options?.bail;
|
|
517
|
+
let failureCount = 0;
|
|
518
|
+
let bailedOut = false;
|
|
519
|
+
const shouldBail = () => bail !== void 0 && failureCount >= bail;
|
|
520
|
+
const noteFailure = (count = 1) => {
|
|
521
|
+
failureCount += count;
|
|
522
|
+
if (shouldBail()) {
|
|
523
|
+
bailedOut = true;
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
const platformResults = [];
|
|
527
|
+
for (const { platform, driver, engineConfig } of platforms) {
|
|
528
|
+
const results = [];
|
|
529
|
+
const platformFlows = flows.filter((f) => {
|
|
530
|
+
const fp = f.config.platforms;
|
|
531
|
+
return !fp || fp.includes(platform);
|
|
532
|
+
});
|
|
533
|
+
if (shouldBail()) {
|
|
534
|
+
bailedOut = true;
|
|
535
|
+
for (const flow of platformFlows) {
|
|
536
|
+
results.push({
|
|
537
|
+
name: flow.name,
|
|
538
|
+
platform,
|
|
539
|
+
status: "skipped",
|
|
540
|
+
durationMs: 0
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
platformResults.push(results);
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
const hooks = engineConfig.hooks;
|
|
547
|
+
if (hooks?.beforeAll) {
|
|
548
|
+
try {
|
|
549
|
+
await hooks.beforeAll({ app: void 0, platform });
|
|
550
|
+
} catch (error) {
|
|
551
|
+
for (const flow of platformFlows) {
|
|
552
|
+
results.push({
|
|
553
|
+
name: flow.name,
|
|
554
|
+
platform,
|
|
555
|
+
status: "failed",
|
|
556
|
+
durationMs: 0,
|
|
557
|
+
error: classifyError(error instanceof Error ? error : new Error(String(error)))
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
noteFailure(platformFlows.length);
|
|
561
|
+
platformResults.push(results);
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
for (let index = 0; index < platformFlows.length; index++) {
|
|
566
|
+
const flow = platformFlows[index];
|
|
567
|
+
if (shouldBail()) {
|
|
568
|
+
bailedOut = true;
|
|
569
|
+
for (const skippedFlow of platformFlows.slice(index)) {
|
|
570
|
+
results.push({
|
|
571
|
+
name: skippedFlow.name,
|
|
572
|
+
platform,
|
|
573
|
+
status: "skipped",
|
|
574
|
+
durationMs: 0
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
options?.onFlowStart?.(flow.name, platform);
|
|
580
|
+
let result = await executeFlow(flow, driver, engineConfig);
|
|
581
|
+
let attempts = 1;
|
|
582
|
+
if (result.status === "failed" && retries > 0) {
|
|
583
|
+
for (let retry = 0; retry < retries; retry++) {
|
|
584
|
+
if (shouldBail()) {
|
|
585
|
+
bailedOut = true;
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
const retryResult = await executeFlow(flow, driver, engineConfig);
|
|
589
|
+
attempts++;
|
|
590
|
+
if (retryResult.status === "passed") {
|
|
591
|
+
result = { ...retryResult, flaky: true, attempts };
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
result = { ...retryResult, attempts };
|
|
595
|
+
}
|
|
596
|
+
if (result.status === "failed") {
|
|
597
|
+
result = { ...result, attempts };
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
results.push(result);
|
|
601
|
+
options?.onResult?.(result);
|
|
602
|
+
if (result.status === "failed") {
|
|
603
|
+
noteFailure();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
if (hooks?.afterAll) {
|
|
607
|
+
try {
|
|
608
|
+
await hooks.afterAll({ app: void 0, platform, summary: { results } });
|
|
609
|
+
} catch (hookError) {
|
|
610
|
+
console.warn(
|
|
611
|
+
`afterAll hook failed: ${hookError instanceof Error ? hookError.message : hookError}`
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
platformResults.push(results);
|
|
616
|
+
}
|
|
617
|
+
const allResults = platformResults.flat();
|
|
618
|
+
return {
|
|
619
|
+
results: allResults,
|
|
620
|
+
totalDurationMs: Date.now() - start2,
|
|
621
|
+
passed: allResults.filter((r) => r.status === "passed").length,
|
|
622
|
+
failed: allResults.filter((r) => r.status === "failed").length,
|
|
623
|
+
skipped: allResults.filter((r) => r.status === "skipped").length,
|
|
624
|
+
flaky: allResults.filter((r) => r.flaky).length,
|
|
625
|
+
bailedOut,
|
|
626
|
+
bailLimit: bail
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// src/runtime/capabilities.ts
|
|
631
|
+
import { readFile } from "fs/promises";
|
|
632
|
+
async function resolveCapabilities(config, opts) {
|
|
633
|
+
const configCaps = config.capabilities ?? {};
|
|
634
|
+
let fileCaps = {};
|
|
635
|
+
const capsFilePath = opts.capsPath ?? config.capabilitiesFile;
|
|
636
|
+
if (capsFilePath) {
|
|
637
|
+
const raw = await readFile(capsFilePath, "utf-8");
|
|
638
|
+
fileCaps = JSON.parse(raw);
|
|
639
|
+
}
|
|
640
|
+
let cliCaps = {};
|
|
641
|
+
if (opts.capsJson) {
|
|
642
|
+
cliCaps = JSON.parse(opts.capsJson);
|
|
643
|
+
}
|
|
644
|
+
return { ...configCaps, ...fileCaps, ...cliCaps };
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// src/runtime/local.ts
|
|
648
|
+
import { Effect as Effect3 } from "effect";
|
|
649
|
+
async function safeCleanup(...fns) {
|
|
650
|
+
for (const fn of fns) {
|
|
651
|
+
try {
|
|
652
|
+
await fn();
|
|
653
|
+
} catch {
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function buildEngineConfig(appId, platform, parseFn, config) {
|
|
658
|
+
return {
|
|
659
|
+
appId,
|
|
660
|
+
platform,
|
|
661
|
+
coordinatorConfig: {
|
|
662
|
+
parse: parseFn,
|
|
663
|
+
defaults: {
|
|
664
|
+
timeout: config.defaults?.waitTimeout,
|
|
665
|
+
pollInterval: config.defaults?.pollInterval
|
|
666
|
+
},
|
|
667
|
+
waitForIdleTimeout: config.defaults?.waitForIdleTimeout,
|
|
668
|
+
typingDelay: config.defaults?.typingDelay
|
|
669
|
+
},
|
|
670
|
+
autoLaunch: true,
|
|
671
|
+
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
672
|
+
artifactConfig: config.artifacts,
|
|
673
|
+
launchOptions: config.launchOptions,
|
|
674
|
+
hooks: config.hooks
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
async function buildWebRuntime(config) {
|
|
678
|
+
const webUrl = config.apps?.web?.url ?? "http://localhost:3000";
|
|
679
|
+
const webExecution = config.execution?.web;
|
|
680
|
+
const driver = await Effect3.runPromise(
|
|
681
|
+
makePlaywrightDriver({
|
|
682
|
+
browser: webExecution?.browser,
|
|
683
|
+
headless: webExecution?.headless ?? true,
|
|
684
|
+
baseUrl: webUrl,
|
|
685
|
+
storageState: webExecution?.storageState
|
|
686
|
+
})
|
|
687
|
+
);
|
|
688
|
+
return {
|
|
689
|
+
runtime: {
|
|
690
|
+
driver,
|
|
691
|
+
cleanup: () => safeCleanup(() => Effect3.runPromise(driver.killApp(""))),
|
|
692
|
+
metadata: {
|
|
693
|
+
platform: "web",
|
|
694
|
+
mode: "local"
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
engineConfig: buildEngineConfig(webUrl, "web", parseWebHierarchy, config)
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
async function buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig) {
|
|
701
|
+
const device = targetDevice?.platform === "android" ? {
|
|
702
|
+
serial: targetDevice.id,
|
|
703
|
+
state: "device",
|
|
704
|
+
type: targetDevice.type
|
|
705
|
+
} : ensureAndroidDevice();
|
|
706
|
+
if (!device) {
|
|
707
|
+
console.log("No Android device/emulator available. Skipping android platform.");
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
const packageName = config.apps?.android?.packageName ?? "";
|
|
711
|
+
const androidAppPath = config.apps?.android?.appPath;
|
|
712
|
+
if (androidAppPath && packageName) {
|
|
713
|
+
try {
|
|
714
|
+
const { adbShell, adbInstall } = await import("./android-PAPJJWVN.js");
|
|
715
|
+
const output = adbShell(device.serial, `pm list packages ${packageName}`);
|
|
716
|
+
if (!output.includes(packageName)) {
|
|
717
|
+
console.log(`Installing ${packageName} on Android device...`);
|
|
718
|
+
adbInstall(device.serial, resolveFromConfig(androidAppPath));
|
|
719
|
+
}
|
|
720
|
+
} catch {
|
|
721
|
+
console.log(`Installing ${packageName} on Android device...`);
|
|
722
|
+
const { adbInstall } = await import("./android-PAPJJWVN.js");
|
|
723
|
+
adbInstall(device.serial, resolveFromConfig(androidAppPath));
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
const hostPort = allocatePort(8200);
|
|
727
|
+
try {
|
|
728
|
+
const conn = await setupUiAutomator2(device.serial, hostPort);
|
|
729
|
+
const driver = await Effect3.runPromise(
|
|
730
|
+
createUiAutomator2Driver(conn.host, conn.port, device.serial, packageName)
|
|
731
|
+
);
|
|
732
|
+
return {
|
|
733
|
+
runtime: {
|
|
734
|
+
driver,
|
|
735
|
+
cleanup: () => safeCleanup(
|
|
736
|
+
() => Effect3.runPromise(driver.killApp("")),
|
|
737
|
+
() => conn.cleanup?.() ?? Promise.resolve()
|
|
738
|
+
),
|
|
739
|
+
metadata: {
|
|
740
|
+
platform: "android",
|
|
741
|
+
mode: "local",
|
|
742
|
+
deviceId: device.serial
|
|
743
|
+
}
|
|
744
|
+
},
|
|
745
|
+
engineConfig: buildEngineConfig(packageName, "android", parseAndroidHierarchy, config)
|
|
746
|
+
};
|
|
747
|
+
} catch (e) {
|
|
748
|
+
console.log(`Android setup failed on ${device.serial}: ${e instanceof Error ? e.message : e}`);
|
|
749
|
+
return null;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
|
|
753
|
+
const bundleId = config.apps?.ios?.bundleId ?? "";
|
|
754
|
+
const iosAppPath = config.apps?.ios?.appPath;
|
|
755
|
+
if (targetDevice?.platform === "ios" && targetDevice.type === "simulator") {
|
|
756
|
+
if (iosAppPath && bundleId) {
|
|
757
|
+
ensureAppInstalled({
|
|
758
|
+
udid: targetDevice.id,
|
|
759
|
+
bundleId,
|
|
760
|
+
appPath: resolveFromConfig(iosAppPath),
|
|
761
|
+
isPhysicalDevice: false
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
const wdaPort2 = allocatePort(8100);
|
|
765
|
+
try {
|
|
766
|
+
const conn = await setupWDA(targetDevice.id, wdaPort2);
|
|
767
|
+
const driver = await Effect3.runPromise(
|
|
768
|
+
createWDADriver(conn.host, conn.port, bundleId, targetDevice.id)
|
|
769
|
+
);
|
|
770
|
+
return {
|
|
771
|
+
runtime: {
|
|
772
|
+
driver,
|
|
773
|
+
cleanup: () => safeCleanup(
|
|
774
|
+
() => Effect3.runPromise(driver.killApp("")),
|
|
775
|
+
() => conn.cleanup?.() ?? Promise.resolve()
|
|
776
|
+
),
|
|
777
|
+
metadata: {
|
|
778
|
+
platform: "ios",
|
|
779
|
+
mode: "local",
|
|
780
|
+
deviceId: targetDevice.id
|
|
781
|
+
}
|
|
782
|
+
},
|
|
783
|
+
engineConfig: buildEngineConfig(bundleId, "ios", parseIOSHierarchy, config)
|
|
784
|
+
};
|
|
785
|
+
} catch (e) {
|
|
786
|
+
console.log(
|
|
787
|
+
`iOS setup failed for device ${targetDevice.id}: ${e instanceof Error ? e.message : e}`
|
|
788
|
+
);
|
|
789
|
+
return null;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
const physicalDevice = firstIOSPhysicalDevice();
|
|
793
|
+
const signing = config.apps?.ios?.signing;
|
|
794
|
+
if (physicalDevice) {
|
|
795
|
+
let conn;
|
|
796
|
+
try {
|
|
797
|
+
console.log(`Found physical iOS device: ${physicalDevice.name} (${physicalDevice.udid})`);
|
|
798
|
+
if (iosAppPath && bundleId) {
|
|
799
|
+
ensureAppInstalled({
|
|
800
|
+
udid: physicalDevice.udid,
|
|
801
|
+
bundleId,
|
|
802
|
+
appPath: resolveFromConfig(iosAppPath),
|
|
803
|
+
isPhysicalDevice: true
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
if (signing?.teamId) {
|
|
807
|
+
const { setupWDAForDevice } = await import("./installer-R6NX7BYQ.js");
|
|
808
|
+
const wdaPort2 = allocatePort(8100);
|
|
809
|
+
conn = await setupWDAForDevice(
|
|
810
|
+
physicalDevice.udid,
|
|
811
|
+
wdaPort2,
|
|
812
|
+
signing.teamId,
|
|
813
|
+
signing.signingIdentity
|
|
814
|
+
);
|
|
815
|
+
} else {
|
|
816
|
+
conn = connectPhysicalDevice(physicalDevice.udid);
|
|
817
|
+
}
|
|
818
|
+
const activeConn = conn;
|
|
819
|
+
const driver = await Effect3.runPromise(
|
|
820
|
+
createWDADriver(activeConn.host, activeConn.port, bundleId)
|
|
821
|
+
);
|
|
822
|
+
return {
|
|
823
|
+
runtime: {
|
|
824
|
+
driver,
|
|
825
|
+
cleanup: () => safeCleanup(
|
|
826
|
+
() => Effect3.runPromise(driver.killApp("")),
|
|
827
|
+
() => activeConn.cleanup?.() ?? Promise.resolve()
|
|
828
|
+
),
|
|
829
|
+
metadata: {
|
|
830
|
+
platform: "ios",
|
|
831
|
+
mode: "local",
|
|
832
|
+
deviceId: physicalDevice.udid
|
|
833
|
+
}
|
|
834
|
+
},
|
|
835
|
+
engineConfig: buildEngineConfig(bundleId, "ios", parseIOSHierarchy, config)
|
|
836
|
+
};
|
|
837
|
+
} catch (e) {
|
|
838
|
+
if (conn?.cleanup) {
|
|
839
|
+
try {
|
|
840
|
+
await conn.cleanup();
|
|
841
|
+
} catch (cleanupError) {
|
|
842
|
+
console.warn(
|
|
843
|
+
`Failed to clean up physical device tunnel: ${cleanupError instanceof Error ? cleanupError.message : cleanupError}`
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
console.log(
|
|
848
|
+
`Physical device setup failed (${physicalDevice.name}): ${e instanceof Error ? e.message : e}. Falling back to simulator.`
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
const simulator = ensureIOSSimulator(bundleId);
|
|
853
|
+
if (!simulator) {
|
|
854
|
+
console.log("No iOS simulator or physical device available. Skipping ios platform.");
|
|
855
|
+
return null;
|
|
856
|
+
}
|
|
857
|
+
if (iosAppPath && bundleId) {
|
|
858
|
+
ensureAppInstalled({
|
|
859
|
+
udid: simulator.udid,
|
|
860
|
+
bundleId,
|
|
861
|
+
appPath: resolveFromConfig(iosAppPath),
|
|
862
|
+
isPhysicalDevice: false
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
const wdaPort = allocatePort(8100);
|
|
866
|
+
try {
|
|
867
|
+
const conn = await setupWDA(simulator.udid, wdaPort);
|
|
868
|
+
const driver = await Effect3.runPromise(
|
|
869
|
+
createWDADriver(conn.host, conn.port, bundleId, simulator.udid)
|
|
870
|
+
);
|
|
871
|
+
return {
|
|
872
|
+
runtime: {
|
|
873
|
+
driver,
|
|
874
|
+
cleanup: () => safeCleanup(
|
|
875
|
+
() => Effect3.runPromise(driver.killApp("")),
|
|
876
|
+
() => conn.cleanup?.() ?? Promise.resolve()
|
|
877
|
+
),
|
|
878
|
+
metadata: {
|
|
879
|
+
platform: "ios",
|
|
880
|
+
mode: "local",
|
|
881
|
+
deviceId: simulator.udid
|
|
882
|
+
}
|
|
883
|
+
},
|
|
884
|
+
engineConfig: buildEngineConfig(bundleId, "ios", parseIOSHierarchy, config)
|
|
885
|
+
};
|
|
886
|
+
} catch (e) {
|
|
887
|
+
console.log(`iOS setup failed on ${simulator.name}: ${e instanceof Error ? e.message : e}`);
|
|
888
|
+
return null;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// src/runtime/appium.ts
|
|
893
|
+
import { Effect as Effect6 } from "effect";
|
|
894
|
+
|
|
895
|
+
// src/drivers/appium/client.ts
|
|
896
|
+
var AppiumClient = class {
|
|
897
|
+
baseUrl;
|
|
898
|
+
sessionId = null;
|
|
899
|
+
sessionCaps = {};
|
|
900
|
+
constructor(serverUrl) {
|
|
901
|
+
this.baseUrl = serverUrl.replace(/\/+$/, "");
|
|
902
|
+
}
|
|
903
|
+
// ---------------------------------------------------------------------------
|
|
904
|
+
// HTTP helpers
|
|
905
|
+
// ---------------------------------------------------------------------------
|
|
906
|
+
async request(method, path, body) {
|
|
907
|
+
const url = `${this.baseUrl}${path}`;
|
|
908
|
+
const init = {
|
|
909
|
+
method,
|
|
910
|
+
headers: { "Content-Type": "application/json" }
|
|
911
|
+
};
|
|
912
|
+
if (body !== void 0) {
|
|
913
|
+
init.body = JSON.stringify(body);
|
|
914
|
+
}
|
|
915
|
+
const res = await fetch(url, init);
|
|
916
|
+
const text = await res.text();
|
|
917
|
+
let parsed;
|
|
918
|
+
try {
|
|
919
|
+
parsed = JSON.parse(text);
|
|
920
|
+
} catch {
|
|
921
|
+
throw new Error(`Appium: failed to parse response: ${text}`);
|
|
922
|
+
}
|
|
923
|
+
if (!res.ok) {
|
|
924
|
+
const val = parsed.value;
|
|
925
|
+
const msg = val?.message ?? val?.error ?? text;
|
|
926
|
+
throw new Error(`Appium ${method} ${path} -> ${res.status}: ${msg}`);
|
|
927
|
+
}
|
|
928
|
+
if (parsed.value !== null && typeof parsed.value === "object" && "error" in parsed.value) {
|
|
929
|
+
const val = parsed.value;
|
|
930
|
+
throw new Error(`Appium error: ${val.message ?? val.error}`);
|
|
931
|
+
}
|
|
932
|
+
return parsed.value;
|
|
933
|
+
}
|
|
934
|
+
sessionPath(suffix) {
|
|
935
|
+
if (this.sessionId === null) {
|
|
936
|
+
throw new Error("Appium: no active session");
|
|
937
|
+
}
|
|
938
|
+
return `/session/${this.sessionId}${suffix}`;
|
|
939
|
+
}
|
|
940
|
+
// ---------------------------------------------------------------------------
|
|
941
|
+
// Session management
|
|
942
|
+
// ---------------------------------------------------------------------------
|
|
943
|
+
async createSession(capabilities) {
|
|
944
|
+
const body = {
|
|
945
|
+
capabilities: {
|
|
946
|
+
alwaysMatch: capabilities
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
const res = await fetch(`${this.baseUrl}/session`, {
|
|
950
|
+
method: "POST",
|
|
951
|
+
headers: { "Content-Type": "application/json" },
|
|
952
|
+
body: JSON.stringify(body)
|
|
953
|
+
});
|
|
954
|
+
const text = await res.text();
|
|
955
|
+
let parsed;
|
|
956
|
+
try {
|
|
957
|
+
parsed = JSON.parse(text);
|
|
958
|
+
} catch {
|
|
959
|
+
throw new Error(`Appium: failed to parse session response: ${text}`);
|
|
960
|
+
}
|
|
961
|
+
if (!res.ok) {
|
|
962
|
+
const val = parsed["value"];
|
|
963
|
+
throw new Error(`Appium: failed to create session: ${val?.message ?? text}`);
|
|
964
|
+
}
|
|
965
|
+
const value = parsed["value"];
|
|
966
|
+
const sessionId = value?.["sessionId"] ?? parsed["sessionId"];
|
|
967
|
+
if (!sessionId) {
|
|
968
|
+
throw new Error("Appium: no sessionId in session response");
|
|
969
|
+
}
|
|
970
|
+
this.sessionId = sessionId;
|
|
971
|
+
this.sessionCaps = value?.["capabilities"] ?? {};
|
|
972
|
+
return sessionId;
|
|
973
|
+
}
|
|
974
|
+
async deleteSession() {
|
|
975
|
+
if (this.sessionId === null) return;
|
|
976
|
+
const path = `/session/${this.sessionId}`;
|
|
977
|
+
this.sessionId = null;
|
|
978
|
+
this.sessionCaps = {};
|
|
979
|
+
await fetch(`${this.baseUrl}${path}`, { method: "DELETE" });
|
|
980
|
+
}
|
|
981
|
+
getSessionId() {
|
|
982
|
+
return this.sessionId;
|
|
983
|
+
}
|
|
984
|
+
getSessionCaps() {
|
|
985
|
+
return this.sessionCaps;
|
|
986
|
+
}
|
|
987
|
+
// ---------------------------------------------------------------------------
|
|
988
|
+
// WebView / hybrid context switching
|
|
989
|
+
// ---------------------------------------------------------------------------
|
|
990
|
+
async getContexts() {
|
|
991
|
+
return this.request("GET", this.sessionPath("/contexts"));
|
|
992
|
+
}
|
|
993
|
+
async getCurrentContext() {
|
|
994
|
+
return this.request("GET", this.sessionPath("/context"));
|
|
995
|
+
}
|
|
996
|
+
async setContext(contextId) {
|
|
997
|
+
await this.request("POST", this.sessionPath("/context"), { name: contextId });
|
|
998
|
+
}
|
|
999
|
+
// ---------------------------------------------------------------------------
|
|
1000
|
+
// Scripting (execute in current context — works in WebView contexts)
|
|
1001
|
+
// ---------------------------------------------------------------------------
|
|
1002
|
+
async executeScript(script, args = []) {
|
|
1003
|
+
return this.request("POST", this.sessionPath("/execute/sync"), { script, args });
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
|
|
1007
|
+
// src/drivers/appium/android.ts
|
|
1008
|
+
import { Effect as Effect4 } from "effect";
|
|
1009
|
+
function createAppiumAndroidDriver(client) {
|
|
1010
|
+
const service = {
|
|
1011
|
+
// -----------------------------------------------------------------------
|
|
1012
|
+
// Hierarchy
|
|
1013
|
+
// -----------------------------------------------------------------------
|
|
1014
|
+
dumpHierarchy: () => Effect4.tryPromise({
|
|
1015
|
+
try: () => client.request("GET", client.sessionPath("/source")),
|
|
1016
|
+
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
1017
|
+
}),
|
|
1018
|
+
// -----------------------------------------------------------------------
|
|
1019
|
+
// Coordinate-level actions
|
|
1020
|
+
// -----------------------------------------------------------------------
|
|
1021
|
+
tapAtCoordinate: (x, y) => Effect4.tryPromise({
|
|
1022
|
+
try: () => client.request("POST", client.sessionPath("/appium/gestures/click"), {
|
|
1023
|
+
offset: { x, y }
|
|
1024
|
+
}),
|
|
1025
|
+
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
1026
|
+
}),
|
|
1027
|
+
doubleTapAtCoordinate: (x, y) => Effect4.tryPromise({
|
|
1028
|
+
try: () => client.request("POST", client.sessionPath("/appium/gestures/double_click"), {
|
|
1029
|
+
offset: { x, y }
|
|
1030
|
+
}),
|
|
1031
|
+
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
1032
|
+
}),
|
|
1033
|
+
longPressAtCoordinate: (x, y, duration) => Effect4.tryPromise({
|
|
1034
|
+
try: () => client.request("POST", client.sessionPath("/appium/gestures/long_click"), {
|
|
1035
|
+
offset: { x, y },
|
|
1036
|
+
duration
|
|
1037
|
+
}),
|
|
1038
|
+
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
1039
|
+
}),
|
|
1040
|
+
swipe: (sx, sy, ex, ey, dur) => Effect4.tryPromise({
|
|
1041
|
+
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1042
|
+
actions: [
|
|
1043
|
+
{
|
|
1044
|
+
type: "pointer",
|
|
1045
|
+
id: "finger1",
|
|
1046
|
+
parameters: { pointerType: "touch" },
|
|
1047
|
+
actions: [
|
|
1048
|
+
{ type: "pointerMove", duration: 0, x: sx, y: sy },
|
|
1049
|
+
{ type: "pointerDown", button: 0 },
|
|
1050
|
+
{ type: "pointerMove", duration: dur, x: ex, y: ey },
|
|
1051
|
+
{ type: "pointerUp", button: 0 }
|
|
1052
|
+
]
|
|
1053
|
+
}
|
|
1054
|
+
]
|
|
1055
|
+
}),
|
|
1056
|
+
catch: (e) => new DriverError({ message: `Swipe failed: ${e}` })
|
|
1057
|
+
}),
|
|
1058
|
+
// -----------------------------------------------------------------------
|
|
1059
|
+
// Text input
|
|
1060
|
+
// -----------------------------------------------------------------------
|
|
1061
|
+
inputText: (text) => Effect4.tryPromise({
|
|
1062
|
+
try: () => {
|
|
1063
|
+
const keyActions = [];
|
|
1064
|
+
for (const ch of text) {
|
|
1065
|
+
keyActions.push({ type: "keyDown", value: ch });
|
|
1066
|
+
keyActions.push({ type: "keyUp", value: ch });
|
|
1067
|
+
}
|
|
1068
|
+
return client.request("POST", client.sessionPath("/actions"), {
|
|
1069
|
+
actions: [
|
|
1070
|
+
{
|
|
1071
|
+
type: "key",
|
|
1072
|
+
id: "keyboard",
|
|
1073
|
+
actions: keyActions
|
|
1074
|
+
}
|
|
1075
|
+
]
|
|
1076
|
+
});
|
|
1077
|
+
},
|
|
1078
|
+
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
1079
|
+
}),
|
|
1080
|
+
pressKey: (key) => Effect4.tryPromise({
|
|
1081
|
+
try: () => client.request("POST", client.sessionPath("/appium/device/press_keycode"), {
|
|
1082
|
+
keycode: parseInt(key, 10) || 0
|
|
1083
|
+
}),
|
|
1084
|
+
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
1085
|
+
}),
|
|
1086
|
+
hideKeyboard: () => Effect4.tryPromise({
|
|
1087
|
+
try: () => client.request("POST", client.sessionPath("/appium/device/hide_keyboard")),
|
|
1088
|
+
catch: (e) => new DriverError({ message: `Hide keyboard failed: ${e}` })
|
|
1089
|
+
}),
|
|
1090
|
+
// -----------------------------------------------------------------------
|
|
1091
|
+
// Queries
|
|
1092
|
+
// -----------------------------------------------------------------------
|
|
1093
|
+
takeScreenshot: () => Effect4.tryPromise({
|
|
1094
|
+
try: async () => {
|
|
1095
|
+
const base64 = await client.request("GET", client.sessionPath("/screenshot"));
|
|
1096
|
+
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
1097
|
+
},
|
|
1098
|
+
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
1099
|
+
}),
|
|
1100
|
+
getDeviceInfo: () => Effect4.tryPromise({
|
|
1101
|
+
try: async () => {
|
|
1102
|
+
const size = await client.request(
|
|
1103
|
+
"GET",
|
|
1104
|
+
client.sessionPath("/window/size")
|
|
1105
|
+
);
|
|
1106
|
+
const caps = client.getSessionCaps();
|
|
1107
|
+
return {
|
|
1108
|
+
platform: "android",
|
|
1109
|
+
deviceId: client.getSessionId() ?? "appium",
|
|
1110
|
+
name: caps["deviceName"] ?? "Android Device (Appium)",
|
|
1111
|
+
isEmulator: false,
|
|
1112
|
+
screenWidth: size.width,
|
|
1113
|
+
screenHeight: size.height,
|
|
1114
|
+
driverType: "appium"
|
|
1115
|
+
};
|
|
1116
|
+
},
|
|
1117
|
+
catch: (e) => new DriverError({ message: `Get device info failed: ${e}` })
|
|
1118
|
+
}),
|
|
1119
|
+
// -----------------------------------------------------------------------
|
|
1120
|
+
// App lifecycle
|
|
1121
|
+
// -----------------------------------------------------------------------
|
|
1122
|
+
launchApp: (bundleId, opts) => Effect4.tryPromise({
|
|
1123
|
+
try: async () => {
|
|
1124
|
+
if (opts?.clearState) {
|
|
1125
|
+
try {
|
|
1126
|
+
await client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1127
|
+
appId: bundleId
|
|
1128
|
+
});
|
|
1129
|
+
} catch {
|
|
1130
|
+
}
|
|
1131
|
+
await client.request("POST", client.sessionPath("/appium/execute_mobile/clearApp"), {
|
|
1132
|
+
appId: bundleId
|
|
1133
|
+
});
|
|
1134
|
+
await client.request("POST", client.sessionPath("/appium/device/activate_app"), {
|
|
1135
|
+
appId: bundleId
|
|
1136
|
+
});
|
|
1137
|
+
} else {
|
|
1138
|
+
await client.request("POST", client.sessionPath("/appium/device/activate_app"), {
|
|
1139
|
+
appId: bundleId
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
if (opts?.clearKeychain) {
|
|
1143
|
+
console.warn("clearKeychain is not supported on Android, skipping.");
|
|
1144
|
+
}
|
|
1145
|
+
if (opts?.launchArguments && Object.keys(opts.launchArguments).length > 0) {
|
|
1146
|
+
throw new DriverError({
|
|
1147
|
+
message: "launchArguments are not supported in Appium Android mode. Remove launchArguments from your config or use local mode."
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
if (opts?.deepLink) {
|
|
1151
|
+
await client.request("POST", client.sessionPath("/url"), {
|
|
1152
|
+
url: opts.deepLink
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
},
|
|
1156
|
+
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
1157
|
+
}),
|
|
1158
|
+
stopApp: (bundleId) => Effect4.tryPromise({
|
|
1159
|
+
try: () => client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1160
|
+
appId: bundleId
|
|
1161
|
+
}),
|
|
1162
|
+
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
1163
|
+
}),
|
|
1164
|
+
killApp: (bundleId) => Effect4.tryPromise({
|
|
1165
|
+
try: () => client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1166
|
+
appId: bundleId
|
|
1167
|
+
}),
|
|
1168
|
+
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
1169
|
+
}),
|
|
1170
|
+
clearAppState: (bundleId) => Effect4.tryPromise({
|
|
1171
|
+
try: async () => {
|
|
1172
|
+
try {
|
|
1173
|
+
await client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1174
|
+
appId: bundleId
|
|
1175
|
+
});
|
|
1176
|
+
} catch {
|
|
1177
|
+
}
|
|
1178
|
+
await client.request("POST", client.sessionPath("/appium/execute_mobile/clearApp"), {
|
|
1179
|
+
appId: bundleId
|
|
1180
|
+
});
|
|
1181
|
+
},
|
|
1182
|
+
catch: (e) => new DriverError({ message: `Clear app state failed: ${e}` })
|
|
1183
|
+
}),
|
|
1184
|
+
// -----------------------------------------------------------------------
|
|
1185
|
+
// Navigation
|
|
1186
|
+
// -----------------------------------------------------------------------
|
|
1187
|
+
openLink: (url) => Effect4.tryPromise({
|
|
1188
|
+
try: () => client.request("POST", client.sessionPath("/url"), { url }),
|
|
1189
|
+
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
1190
|
+
}),
|
|
1191
|
+
back: () => Effect4.tryPromise({
|
|
1192
|
+
try: () => client.request("POST", client.sessionPath("/back")),
|
|
1193
|
+
catch: (e) => new DriverError({ message: `Back failed: ${e}` })
|
|
1194
|
+
}),
|
|
1195
|
+
// -----------------------------------------------------------------------
|
|
1196
|
+
// Scripting (works when switched to a WebView context)
|
|
1197
|
+
// -----------------------------------------------------------------------
|
|
1198
|
+
evaluate: (script, ...args) => Effect4.tryPromise({
|
|
1199
|
+
try: () => client.executeScript(
|
|
1200
|
+
typeof script === "function" ? `return (${script})(...arguments)` : script,
|
|
1201
|
+
args
|
|
1202
|
+
),
|
|
1203
|
+
catch: (e) => new DriverError({ message: `evaluate() failed: ${e}` })
|
|
1204
|
+
}),
|
|
1205
|
+
// -----------------------------------------------------------------------
|
|
1206
|
+
// WebView / hybrid context switching
|
|
1207
|
+
// -----------------------------------------------------------------------
|
|
1208
|
+
getContexts: () => Effect4.tryPromise({
|
|
1209
|
+
try: () => client.getContexts(),
|
|
1210
|
+
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
1211
|
+
}),
|
|
1212
|
+
getCurrentContext: () => Effect4.tryPromise({
|
|
1213
|
+
try: () => client.getCurrentContext(),
|
|
1214
|
+
catch: (e) => new DriverError({ message: `getCurrentContext failed: ${e}` })
|
|
1215
|
+
}),
|
|
1216
|
+
setContext: (contextId) => Effect4.tryPromise({
|
|
1217
|
+
try: () => client.setContext(contextId),
|
|
1218
|
+
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
1219
|
+
})
|
|
1220
|
+
};
|
|
1221
|
+
return Effect4.succeed(service);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
// src/drivers/appium/ios.ts
|
|
1225
|
+
import { Effect as Effect5 } from "effect";
|
|
1226
|
+
function createAppiumIOSDriver(client) {
|
|
1227
|
+
const service = {
|
|
1228
|
+
// -----------------------------------------------------------------------
|
|
1229
|
+
// Hierarchy
|
|
1230
|
+
// -----------------------------------------------------------------------
|
|
1231
|
+
dumpHierarchy: () => Effect5.tryPromise({
|
|
1232
|
+
try: () => client.request("GET", client.sessionPath("/source")),
|
|
1233
|
+
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
1234
|
+
}),
|
|
1235
|
+
// -----------------------------------------------------------------------
|
|
1236
|
+
// Coordinate-level actions (W3C touch pointer actions for iOS)
|
|
1237
|
+
// -----------------------------------------------------------------------
|
|
1238
|
+
tapAtCoordinate: (x, y) => Effect5.tryPromise({
|
|
1239
|
+
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1240
|
+
actions: [
|
|
1241
|
+
{
|
|
1242
|
+
type: "pointer",
|
|
1243
|
+
id: "finger1",
|
|
1244
|
+
parameters: { pointerType: "touch" },
|
|
1245
|
+
actions: [
|
|
1246
|
+
{ type: "pointerMove", duration: 0, x, y },
|
|
1247
|
+
{ type: "pointerDown", button: 0 },
|
|
1248
|
+
{ type: "pointerUp", button: 0 }
|
|
1249
|
+
]
|
|
1250
|
+
}
|
|
1251
|
+
]
|
|
1252
|
+
}),
|
|
1253
|
+
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
1254
|
+
}),
|
|
1255
|
+
doubleTapAtCoordinate: (x, y) => Effect5.tryPromise({
|
|
1256
|
+
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1257
|
+
actions: [
|
|
1258
|
+
{
|
|
1259
|
+
type: "pointer",
|
|
1260
|
+
id: "finger1",
|
|
1261
|
+
parameters: { pointerType: "touch" },
|
|
1262
|
+
actions: [
|
|
1263
|
+
{ type: "pointerMove", duration: 0, x, y },
|
|
1264
|
+
{ type: "pointerDown", button: 0 },
|
|
1265
|
+
{ type: "pointerUp", button: 0 },
|
|
1266
|
+
{ type: "pause", duration: 40 },
|
|
1267
|
+
{ type: "pointerDown", button: 0 },
|
|
1268
|
+
{ type: "pointerUp", button: 0 }
|
|
1269
|
+
]
|
|
1270
|
+
}
|
|
1271
|
+
]
|
|
1272
|
+
}),
|
|
1273
|
+
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
1274
|
+
}),
|
|
1275
|
+
longPressAtCoordinate: (x, y, duration) => Effect5.tryPromise({
|
|
1276
|
+
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1277
|
+
actions: [
|
|
1278
|
+
{
|
|
1279
|
+
type: "pointer",
|
|
1280
|
+
id: "finger1",
|
|
1281
|
+
parameters: { pointerType: "touch" },
|
|
1282
|
+
actions: [
|
|
1283
|
+
{ type: "pointerMove", duration: 0, x, y },
|
|
1284
|
+
{ type: "pointerDown", button: 0 },
|
|
1285
|
+
{ type: "pause", duration },
|
|
1286
|
+
{ type: "pointerUp", button: 0 }
|
|
1287
|
+
]
|
|
1288
|
+
}
|
|
1289
|
+
]
|
|
1290
|
+
}),
|
|
1291
|
+
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
1292
|
+
}),
|
|
1293
|
+
swipe: (sx, sy, ex, ey, dur) => Effect5.tryPromise({
|
|
1294
|
+
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1295
|
+
actions: [
|
|
1296
|
+
{
|
|
1297
|
+
type: "pointer",
|
|
1298
|
+
id: "finger1",
|
|
1299
|
+
parameters: { pointerType: "touch" },
|
|
1300
|
+
actions: [
|
|
1301
|
+
{ type: "pointerMove", duration: 0, x: sx, y: sy },
|
|
1302
|
+
{ type: "pointerDown", button: 0 },
|
|
1303
|
+
{ type: "pointerMove", duration: dur, x: ex, y: ey },
|
|
1304
|
+
{ type: "pointerUp", button: 0 }
|
|
1305
|
+
]
|
|
1306
|
+
}
|
|
1307
|
+
]
|
|
1308
|
+
}),
|
|
1309
|
+
catch: (e) => new DriverError({ message: `Swipe failed: ${e}` })
|
|
1310
|
+
}),
|
|
1311
|
+
// -----------------------------------------------------------------------
|
|
1312
|
+
// Text input
|
|
1313
|
+
// -----------------------------------------------------------------------
|
|
1314
|
+
inputText: (text) => Effect5.tryPromise({
|
|
1315
|
+
try: () => {
|
|
1316
|
+
const keyActions = [];
|
|
1317
|
+
for (const ch of text) {
|
|
1318
|
+
keyActions.push({ type: "keyDown", value: ch });
|
|
1319
|
+
keyActions.push({ type: "keyUp", value: ch });
|
|
1320
|
+
}
|
|
1321
|
+
return client.request("POST", client.sessionPath("/actions"), {
|
|
1322
|
+
actions: [
|
|
1323
|
+
{
|
|
1324
|
+
type: "key",
|
|
1325
|
+
id: "keyboard",
|
|
1326
|
+
actions: keyActions
|
|
1327
|
+
}
|
|
1328
|
+
]
|
|
1329
|
+
});
|
|
1330
|
+
},
|
|
1331
|
+
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
1332
|
+
}),
|
|
1333
|
+
pressKey: (key) => Effect5.tryPromise({
|
|
1334
|
+
try: () => client.request("POST", client.sessionPath("/actions"), {
|
|
1335
|
+
actions: [
|
|
1336
|
+
{
|
|
1337
|
+
type: "key",
|
|
1338
|
+
id: "keyboard",
|
|
1339
|
+
actions: [
|
|
1340
|
+
{ type: "keyDown", value: key },
|
|
1341
|
+
{ type: "keyUp", value: key }
|
|
1342
|
+
]
|
|
1343
|
+
}
|
|
1344
|
+
]
|
|
1345
|
+
}),
|
|
1346
|
+
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
1347
|
+
}),
|
|
1348
|
+
hideKeyboard: () => Effect5.tryPromise({
|
|
1349
|
+
try: () => client.request("POST", client.sessionPath("/appium/device/hide_keyboard")),
|
|
1350
|
+
catch: (e) => new DriverError({ message: `Hide keyboard failed: ${e}` })
|
|
1351
|
+
}),
|
|
1352
|
+
// -----------------------------------------------------------------------
|
|
1353
|
+
// Queries
|
|
1354
|
+
// -----------------------------------------------------------------------
|
|
1355
|
+
takeScreenshot: () => Effect5.tryPromise({
|
|
1356
|
+
try: async () => {
|
|
1357
|
+
const base64 = await client.request("GET", client.sessionPath("/screenshot"));
|
|
1358
|
+
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
1359
|
+
},
|
|
1360
|
+
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
1361
|
+
}),
|
|
1362
|
+
getDeviceInfo: () => Effect5.tryPromise({
|
|
1363
|
+
try: async () => {
|
|
1364
|
+
const size = await client.request(
|
|
1365
|
+
"GET",
|
|
1366
|
+
client.sessionPath("/window/size")
|
|
1367
|
+
);
|
|
1368
|
+
const caps = client.getSessionCaps();
|
|
1369
|
+
return {
|
|
1370
|
+
platform: "ios",
|
|
1371
|
+
deviceId: client.getSessionId() ?? "appium",
|
|
1372
|
+
name: caps["deviceName"] ?? "iOS Device (Appium)",
|
|
1373
|
+
isEmulator: false,
|
|
1374
|
+
screenWidth: size.width,
|
|
1375
|
+
screenHeight: size.height,
|
|
1376
|
+
driverType: "appium"
|
|
1377
|
+
};
|
|
1378
|
+
},
|
|
1379
|
+
catch: (e) => new DriverError({ message: `Get device info failed: ${e}` })
|
|
1380
|
+
}),
|
|
1381
|
+
// -----------------------------------------------------------------------
|
|
1382
|
+
// App lifecycle
|
|
1383
|
+
// -----------------------------------------------------------------------
|
|
1384
|
+
launchApp: (bundleId, opts) => Effect5.tryPromise({
|
|
1385
|
+
try: async () => {
|
|
1386
|
+
if (opts?.clearState) {
|
|
1387
|
+
try {
|
|
1388
|
+
await client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1389
|
+
appId: bundleId
|
|
1390
|
+
});
|
|
1391
|
+
} catch {
|
|
1392
|
+
}
|
|
1393
|
+
await client.request("POST", client.sessionPath("/appium/execute_mobile/clearApp"), {
|
|
1394
|
+
appId: bundleId
|
|
1395
|
+
});
|
|
1396
|
+
await client.request("POST", client.sessionPath("/appium/device/activate_app"), {
|
|
1397
|
+
appId: bundleId
|
|
1398
|
+
});
|
|
1399
|
+
} else {
|
|
1400
|
+
await client.request("POST", client.sessionPath("/appium/device/activate_app"), {
|
|
1401
|
+
appId: bundleId
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
if (opts?.clearKeychain) {
|
|
1405
|
+
console.warn(
|
|
1406
|
+
"clearKeychain is not available via Appium on iOS. Use local mode with xcrun simctl for keychain operations."
|
|
1407
|
+
);
|
|
1408
|
+
}
|
|
1409
|
+
if (opts?.launchArguments && Object.keys(opts.launchArguments).length > 0) {
|
|
1410
|
+
throw new DriverError({
|
|
1411
|
+
message: "launchArguments are not supported in Appium iOS mode. Remove launchArguments from your config or use local mode."
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
if (opts?.deepLink) {
|
|
1415
|
+
await client.request("POST", client.sessionPath("/url"), {
|
|
1416
|
+
url: opts.deepLink
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
},
|
|
1420
|
+
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
1421
|
+
}),
|
|
1422
|
+
stopApp: (bundleId) => Effect5.tryPromise({
|
|
1423
|
+
try: () => client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1424
|
+
appId: bundleId
|
|
1425
|
+
}),
|
|
1426
|
+
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
1427
|
+
}),
|
|
1428
|
+
killApp: (bundleId) => Effect5.tryPromise({
|
|
1429
|
+
try: () => client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1430
|
+
appId: bundleId
|
|
1431
|
+
}),
|
|
1432
|
+
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
1433
|
+
}),
|
|
1434
|
+
clearAppState: (bundleId) => Effect5.tryPromise({
|
|
1435
|
+
try: async () => {
|
|
1436
|
+
try {
|
|
1437
|
+
await client.request("POST", client.sessionPath("/appium/device/terminate_app"), {
|
|
1438
|
+
appId: bundleId
|
|
1439
|
+
});
|
|
1440
|
+
} catch {
|
|
1441
|
+
}
|
|
1442
|
+
await client.request("POST", client.sessionPath("/appium/execute_mobile/clearApp"), {
|
|
1443
|
+
appId: bundleId
|
|
1444
|
+
});
|
|
1445
|
+
},
|
|
1446
|
+
catch: (e) => new DriverError({
|
|
1447
|
+
message: `Clear app state failed: ${e}. Note: clearApp may not be available on all iOS Appium providers. If this persists, consider using terminate + uninstall + install instead.`
|
|
1448
|
+
})
|
|
1449
|
+
}),
|
|
1450
|
+
// -----------------------------------------------------------------------
|
|
1451
|
+
// Navigation
|
|
1452
|
+
// -----------------------------------------------------------------------
|
|
1453
|
+
openLink: (url) => Effect5.tryPromise({
|
|
1454
|
+
try: () => client.request("POST", client.sessionPath("/url"), { url }),
|
|
1455
|
+
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
1456
|
+
}),
|
|
1457
|
+
back: () => Effect5.fail(
|
|
1458
|
+
new DriverError({
|
|
1459
|
+
message: "back() is not supported on iOS. Use navigation within the app or swipe gestures."
|
|
1460
|
+
})
|
|
1461
|
+
),
|
|
1462
|
+
// -----------------------------------------------------------------------
|
|
1463
|
+
// Scripting (works when switched to a WebView context)
|
|
1464
|
+
// -----------------------------------------------------------------------
|
|
1465
|
+
evaluate: (script, ...args) => Effect5.tryPromise({
|
|
1466
|
+
try: () => client.executeScript(
|
|
1467
|
+
typeof script === "function" ? `return (${script})(...arguments)` : script,
|
|
1468
|
+
args
|
|
1469
|
+
),
|
|
1470
|
+
catch: (e) => new DriverError({ message: `evaluate() failed: ${e}` })
|
|
1471
|
+
}),
|
|
1472
|
+
// -----------------------------------------------------------------------
|
|
1473
|
+
// WebView / hybrid context switching
|
|
1474
|
+
// -----------------------------------------------------------------------
|
|
1475
|
+
getContexts: () => Effect5.tryPromise({
|
|
1476
|
+
try: () => client.getContexts(),
|
|
1477
|
+
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
1478
|
+
}),
|
|
1479
|
+
getCurrentContext: () => Effect5.tryPromise({
|
|
1480
|
+
try: () => client.getCurrentContext(),
|
|
1481
|
+
catch: (e) => new DriverError({ message: `getCurrentContext failed: ${e}` })
|
|
1482
|
+
}),
|
|
1483
|
+
setContext: (contextId) => Effect5.tryPromise({
|
|
1484
|
+
try: () => client.setContext(contextId),
|
|
1485
|
+
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
1486
|
+
})
|
|
1487
|
+
};
|
|
1488
|
+
return Effect5.succeed(service);
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
// src/runtime/appium.ts
|
|
1492
|
+
async function buildAppiumAndroidRuntime(config, appiumUrl, caps) {
|
|
1493
|
+
const client = new AppiumClient(appiumUrl);
|
|
1494
|
+
await client.createSession({
|
|
1495
|
+
platformName: "Android",
|
|
1496
|
+
...caps
|
|
1497
|
+
});
|
|
1498
|
+
const driver = await Effect6.runPromise(createAppiumAndroidDriver(client));
|
|
1499
|
+
const sessionId = client.getSessionId() ?? void 0;
|
|
1500
|
+
const sessionCaps = client.getSessionCaps();
|
|
1501
|
+
const detectedProvider = detectProvider(appiumUrl);
|
|
1502
|
+
const providerName = detectedProvider?.name();
|
|
1503
|
+
return {
|
|
1504
|
+
runtime: {
|
|
1505
|
+
driver,
|
|
1506
|
+
cleanup: async () => {
|
|
1507
|
+
try {
|
|
1508
|
+
await client.deleteSession();
|
|
1509
|
+
} catch {
|
|
1510
|
+
}
|
|
1511
|
+
},
|
|
1512
|
+
metadata: {
|
|
1513
|
+
platform: "android",
|
|
1514
|
+
mode: "appium",
|
|
1515
|
+
sessionId,
|
|
1516
|
+
sessionCaps,
|
|
1517
|
+
provider: providerName
|
|
1518
|
+
}
|
|
1519
|
+
},
|
|
1520
|
+
engineConfig: {
|
|
1521
|
+
appId: caps["appium:appPackage"] ?? "",
|
|
1522
|
+
platform: "android",
|
|
1523
|
+
coordinatorConfig: {
|
|
1524
|
+
parse: parseAndroidHierarchy,
|
|
1525
|
+
defaults: {
|
|
1526
|
+
timeout: config.defaults?.waitTimeout,
|
|
1527
|
+
pollInterval: config.defaults?.pollInterval
|
|
1528
|
+
},
|
|
1529
|
+
waitForIdleTimeout: config.defaults?.waitForIdleTimeout,
|
|
1530
|
+
typingDelay: config.defaults?.typingDelay
|
|
1531
|
+
},
|
|
1532
|
+
autoLaunch: false,
|
|
1533
|
+
// Appium manages app lifecycle
|
|
1534
|
+
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
1535
|
+
artifactConfig: config.artifacts,
|
|
1536
|
+
launchOptions: config.launchOptions,
|
|
1537
|
+
hooks: config.hooks
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
async function buildAppiumIOSRuntime(config, appiumUrl, caps) {
|
|
1542
|
+
const client = new AppiumClient(appiumUrl);
|
|
1543
|
+
await client.createSession({
|
|
1544
|
+
platformName: "iOS",
|
|
1545
|
+
"appium:automationName": "XCUITest",
|
|
1546
|
+
...caps
|
|
1547
|
+
});
|
|
1548
|
+
const driver = await Effect6.runPromise(createAppiumIOSDriver(client));
|
|
1549
|
+
const sessionId = client.getSessionId() ?? void 0;
|
|
1550
|
+
const sessionCaps = client.getSessionCaps();
|
|
1551
|
+
const detectedProvider = detectProvider(appiumUrl);
|
|
1552
|
+
const providerName = detectedProvider?.name();
|
|
1553
|
+
return {
|
|
1554
|
+
runtime: {
|
|
1555
|
+
driver,
|
|
1556
|
+
cleanup: async () => {
|
|
1557
|
+
try {
|
|
1558
|
+
await client.deleteSession();
|
|
1559
|
+
} catch {
|
|
1560
|
+
}
|
|
1561
|
+
},
|
|
1562
|
+
metadata: {
|
|
1563
|
+
platform: "ios",
|
|
1564
|
+
mode: "appium",
|
|
1565
|
+
sessionId,
|
|
1566
|
+
sessionCaps,
|
|
1567
|
+
provider: providerName
|
|
1568
|
+
}
|
|
1569
|
+
},
|
|
1570
|
+
engineConfig: {
|
|
1571
|
+
appId: caps["appium:bundleId"] ?? "",
|
|
1572
|
+
platform: "ios",
|
|
1573
|
+
coordinatorConfig: {
|
|
1574
|
+
parse: parseIOSHierarchy,
|
|
1575
|
+
defaults: {
|
|
1576
|
+
timeout: config.defaults?.waitTimeout,
|
|
1577
|
+
pollInterval: config.defaults?.pollInterval
|
|
1578
|
+
},
|
|
1579
|
+
waitForIdleTimeout: config.defaults?.waitForIdleTimeout,
|
|
1580
|
+
typingDelay: config.defaults?.typingDelay
|
|
1581
|
+
},
|
|
1582
|
+
autoLaunch: false,
|
|
1583
|
+
// Appium manages app lifecycle
|
|
1584
|
+
flowTimeout: config.defaults?.waitTimeout ? config.defaults.waitTimeout * 10 : 6e4,
|
|
1585
|
+
artifactConfig: config.artifacts,
|
|
1586
|
+
launchOptions: config.launchOptions,
|
|
1587
|
+
hooks: config.hooks
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
// src/cli/test-command.ts
|
|
1593
|
+
async function runTestCommand(opts) {
|
|
1594
|
+
if (opts.driver && opts.driver !== "local" && opts.driver !== "appium") {
|
|
1595
|
+
console.log(`Unknown --driver value "${opts.driver}". Use "local" or "appium".`);
|
|
1596
|
+
return false;
|
|
1597
|
+
}
|
|
1598
|
+
if (opts.shard) {
|
|
1599
|
+
const { current, total } = opts.shard;
|
|
1600
|
+
if (!Number.isInteger(current) || !Number.isInteger(total) || current < 1 || total < 1 || current > total) {
|
|
1601
|
+
console.log("Invalid shard config. Use { current, total } with 1 <= current <= total.");
|
|
1602
|
+
return false;
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
if (opts.bail !== void 0 && (!Number.isInteger(opts.bail) || opts.bail < 1)) {
|
|
1606
|
+
console.log("Invalid bail config. Use a positive integer.");
|
|
1607
|
+
return false;
|
|
1608
|
+
}
|
|
1609
|
+
let config = {};
|
|
1610
|
+
let loadedConfigPath;
|
|
1611
|
+
try {
|
|
1612
|
+
const loaded = await loadConfig({ configPath: opts.configPath, allowMissing: true });
|
|
1613
|
+
config = loaded.config;
|
|
1614
|
+
loadedConfigPath = loaded.configPath;
|
|
1615
|
+
} catch (error) {
|
|
1616
|
+
console.log(error instanceof Error ? error.message : String(error));
|
|
1617
|
+
return false;
|
|
1618
|
+
}
|
|
1619
|
+
const configDir = dirname(loadedConfigPath ?? resolve("spana.config.ts"));
|
|
1620
|
+
if (opts.validateConfigOnly) {
|
|
1621
|
+
if (!loadedConfigPath) {
|
|
1622
|
+
console.log("No config file found to validate.");
|
|
1623
|
+
return false;
|
|
1624
|
+
}
|
|
1625
|
+
console.log(`\u2713 Config valid (${loadedConfigPath})`);
|
|
1626
|
+
return true;
|
|
1627
|
+
}
|
|
1628
|
+
const resolveFromConfig = (p) => resolve(configDir, p);
|
|
1629
|
+
if (config.artifacts?.outputDir) {
|
|
1630
|
+
config.artifacts.outputDir = resolveFromConfig(config.artifacts.outputDir);
|
|
1631
|
+
}
|
|
1632
|
+
const executionMode = opts.driver ?? (opts.appiumUrl ? "appium" : void 0) ?? config.execution?.mode ?? "local";
|
|
1633
|
+
if (opts.capsJson) {
|
|
1634
|
+
try {
|
|
1635
|
+
JSON.parse(opts.capsJson);
|
|
1636
|
+
} catch {
|
|
1637
|
+
console.log("Invalid JSON in --caps-json flag.");
|
|
1638
|
+
return false;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
if (executionMode === "appium") {
|
|
1642
|
+
const appiumUrl = opts.appiumUrl ?? config.execution?.appium?.serverUrl;
|
|
1643
|
+
if (!appiumUrl) {
|
|
1644
|
+
console.log(
|
|
1645
|
+
"Appium mode requires a server URL. Set --appium-url or execution.appium.serverUrl in config."
|
|
1646
|
+
);
|
|
1647
|
+
return false;
|
|
1648
|
+
}
|
|
1649
|
+
if (opts.device) {
|
|
1650
|
+
console.log(
|
|
1651
|
+
"Cannot use --device with appium mode. Use --caps or --caps-json to set device capabilities."
|
|
1652
|
+
);
|
|
1653
|
+
return false;
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
const platforms = opts.platforms.length > 0 ? opts.platforms : config.platforms && config.platforms.length > 0 ? config.platforms : ["web"];
|
|
1657
|
+
let targetDevice = null;
|
|
1658
|
+
if (opts.device) {
|
|
1659
|
+
const { findDeviceById } = await import("./discover-RWBKI5IB.js");
|
|
1660
|
+
targetDevice = findDeviceById(opts.device);
|
|
1661
|
+
if (!targetDevice) {
|
|
1662
|
+
const { discoverDevices } = await import("./discover-RWBKI5IB.js");
|
|
1663
|
+
const available = discoverDevices(["web", "android", "ios"]);
|
|
1664
|
+
console.log(`Device "${opts.device}" not found. Available devices:`);
|
|
1665
|
+
for (const d of available) {
|
|
1666
|
+
console.log(` ${d.id.padEnd(30)} ${d.platform.padEnd(8)} ${d.type}`);
|
|
1667
|
+
}
|
|
1668
|
+
return false;
|
|
1669
|
+
}
|
|
1670
|
+
if (opts.platforms.length === 0) {
|
|
1671
|
+
platforms.length = 0;
|
|
1672
|
+
platforms.push(targetDevice.platform);
|
|
1673
|
+
}
|
|
1674
|
+
if (!platforms.includes(targetDevice.platform)) {
|
|
1675
|
+
console.log(
|
|
1676
|
+
`Device "${opts.device}" is ${targetDevice.platform}, but --platform ${platforms.join(",")} was specified.`
|
|
1677
|
+
);
|
|
1678
|
+
return false;
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
const reporterNames = opts.reporter?.trim() ? opts.reporter : config.reporters && config.reporters.length > 0 ? config.reporters.join(",") : "console";
|
|
1682
|
+
const reporterList = reporterNames.split(",").map((name) => name.trim());
|
|
1683
|
+
const validReporters = /* @__PURE__ */ new Set(["console", "json", "junit", "html", "allure"]);
|
|
1684
|
+
for (const reporterName of reporterList) {
|
|
1685
|
+
if (!validReporters.has(reporterName)) {
|
|
1686
|
+
console.log(
|
|
1687
|
+
`Unknown reporter "${reporterName}". Use one of: ${Array.from(validReporters).join(", ")}.`
|
|
1688
|
+
);
|
|
1689
|
+
return false;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
const flowDir = opts.flowPath ?? resolveFromConfig(config.flowDir ?? "./flows");
|
|
1693
|
+
const flowPaths = await discoverFlows(flowDir);
|
|
1694
|
+
if (flowPaths.length === 0) {
|
|
1695
|
+
console.log("No flow files found.");
|
|
1696
|
+
return true;
|
|
1697
|
+
}
|
|
1698
|
+
const hasFeatureFiles = flowPaths.some((p) => p.endsWith(".feature"));
|
|
1699
|
+
if (hasFeatureFiles) {
|
|
1700
|
+
const { stat: statPath } = await import("fs/promises");
|
|
1701
|
+
const { dirname: dirname2 } = await import("path");
|
|
1702
|
+
const flowDirStats = await statPath(flowDir).catch(() => null);
|
|
1703
|
+
const stepSearchDir = flowDirStats?.isDirectory() ? flowDir : dirname2(flowDir);
|
|
1704
|
+
const stepPaths = await discoverStepFiles(stepSearchDir);
|
|
1705
|
+
if (stepPaths.length > 0) {
|
|
1706
|
+
await loadStepFiles(stepPaths);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
const flows = [];
|
|
1710
|
+
for (const p of flowPaths) {
|
|
1711
|
+
const loaded = await loadTestSource(p);
|
|
1712
|
+
flows.push(...loaded);
|
|
1713
|
+
}
|
|
1714
|
+
const filtered = filterFlows(flows, {
|
|
1715
|
+
tags: opts.tags,
|
|
1716
|
+
grep: opts.grep,
|
|
1717
|
+
platforms
|
|
1718
|
+
});
|
|
1719
|
+
const selectedFlows = applyShard(filtered, opts.shard);
|
|
1720
|
+
if (filtered.length === 0) {
|
|
1721
|
+
console.log("No flows match the given filters.");
|
|
1722
|
+
return true;
|
|
1723
|
+
}
|
|
1724
|
+
if (selectedFlows.length === 0) {
|
|
1725
|
+
console.log(`No flows assigned to shard ${opts.shard.current}/${opts.shard.total}.`);
|
|
1726
|
+
return true;
|
|
1727
|
+
}
|
|
1728
|
+
if (opts.shard) {
|
|
1729
|
+
console.log(
|
|
1730
|
+
`Running shard ${opts.shard.current}/${opts.shard.total} (${selectedFlows.length}/${filtered.length} flow(s))...`
|
|
1731
|
+
);
|
|
1732
|
+
}
|
|
1733
|
+
console.log(`Running ${selectedFlows.length} flow(s) on ${platforms.join(", ")}...
|
|
1734
|
+
`);
|
|
1735
|
+
const runtimes = [];
|
|
1736
|
+
const platformConfigs = [];
|
|
1737
|
+
const runCleanups = [];
|
|
1738
|
+
const handleSignal = () => {
|
|
1739
|
+
for (const cleanup of runCleanups) {
|
|
1740
|
+
try {
|
|
1741
|
+
void cleanup();
|
|
1742
|
+
} catch {
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
for (const rt of runtimes) {
|
|
1746
|
+
try {
|
|
1747
|
+
void rt.cleanup();
|
|
1748
|
+
} catch {
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
process.exit(1);
|
|
1752
|
+
};
|
|
1753
|
+
process.on("SIGINT", handleSignal);
|
|
1754
|
+
process.on("SIGTERM", handleSignal);
|
|
1755
|
+
try {
|
|
1756
|
+
const appiumUrl = opts.appiumUrl ?? config.execution?.appium?.serverUrl;
|
|
1757
|
+
const appiumConfig = config.execution?.appium ?? {};
|
|
1758
|
+
const shouldReportToProvider = !opts.noProviderReporting && appiumConfig.reportToProvider !== false;
|
|
1759
|
+
const cloudHelper = executionMode === "appium" && appiumUrl ? createCloudProviderHelper(appiumUrl, appiumConfig) : void 0;
|
|
1760
|
+
const baseAppiumCaps = executionMode === "appium" && appiumUrl ? await resolveCapabilities(appiumConfig, {
|
|
1761
|
+
capsPath: opts.capsPath,
|
|
1762
|
+
capsJson: opts.capsJson
|
|
1763
|
+
}) : void 0;
|
|
1764
|
+
if (cloudHelper) {
|
|
1765
|
+
runCleanups.push(() => cloudHelper.cleanup());
|
|
1766
|
+
}
|
|
1767
|
+
for (const platform of platforms) {
|
|
1768
|
+
if (executionMode === "appium" && (platform === "android" || platform === "ios")) {
|
|
1769
|
+
const builder = platform === "android" ? buildAppiumAndroidRuntime : buildAppiumIOSRuntime;
|
|
1770
|
+
const preparedCaps = await cloudHelper.prepareCapabilities(
|
|
1771
|
+
platform,
|
|
1772
|
+
{ ...baseAppiumCaps },
|
|
1773
|
+
platform === "android" ? config.apps?.android : config.apps?.ios
|
|
1774
|
+
);
|
|
1775
|
+
const result2 = await builder(config, appiumUrl, preparedCaps);
|
|
1776
|
+
runtimes.push(result2.runtime);
|
|
1777
|
+
platformConfigs.push({
|
|
1778
|
+
platform,
|
|
1779
|
+
driver: result2.runtime.driver,
|
|
1780
|
+
engineConfig: { ...result2.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
1781
|
+
});
|
|
1782
|
+
} else if (platform === "web") {
|
|
1783
|
+
const result2 = await buildWebRuntime(config);
|
|
1784
|
+
runtimes.push(result2.runtime);
|
|
1785
|
+
platformConfigs.push({
|
|
1786
|
+
platform,
|
|
1787
|
+
driver: result2.runtime.driver,
|
|
1788
|
+
engineConfig: { ...result2.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
1789
|
+
});
|
|
1790
|
+
} else if (platform === "android") {
|
|
1791
|
+
const result2 = await buildLocalAndroidRuntime(config, targetDevice, resolveFromConfig);
|
|
1792
|
+
if (!result2) continue;
|
|
1793
|
+
runtimes.push(result2.runtime);
|
|
1794
|
+
platformConfigs.push({
|
|
1795
|
+
platform,
|
|
1796
|
+
driver: result2.runtime.driver,
|
|
1797
|
+
engineConfig: { ...result2.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
1798
|
+
});
|
|
1799
|
+
} else if (platform === "ios") {
|
|
1800
|
+
const result2 = await buildLocalIOSRuntime(config, targetDevice, resolveFromConfig);
|
|
1801
|
+
if (!result2) continue;
|
|
1802
|
+
runtimes.push(result2.runtime);
|
|
1803
|
+
platformConfigs.push({
|
|
1804
|
+
platform,
|
|
1805
|
+
driver: result2.runtime.driver,
|
|
1806
|
+
engineConfig: { ...result2.engineConfig, debugOnFailure: opts.debugOnFailure }
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
const { createRedactor, registerUrlSecrets } = await import("./redact-IDA3C4UH.js");
|
|
1811
|
+
const redactor = createRedactor();
|
|
1812
|
+
if (appiumUrl) registerUrlSecrets(redactor, appiumUrl);
|
|
1813
|
+
const { createConsoleReporter } = await import("./console-FV4RJPO4.js");
|
|
1814
|
+
const { createJsonReporter } = await import("./json-JMRPUVY2.js");
|
|
1815
|
+
const { createJUnitReporter } = await import("./junit-UDY5JG22.js");
|
|
1816
|
+
const { createHtmlReporter } = await import("./html-JP2HBIJQ.js");
|
|
1817
|
+
const { createAllureReporter } = await import("./allure-PTTVORQ6.js");
|
|
1818
|
+
const resolvedOutputDir = config.artifacts?.outputDir ?? resolveFromConfig("./spana-output");
|
|
1819
|
+
const reporters = reporterNames.split(",").map((r) => {
|
|
1820
|
+
switch (r.trim()) {
|
|
1821
|
+
case "json":
|
|
1822
|
+
return createJsonReporter();
|
|
1823
|
+
case "junit":
|
|
1824
|
+
return createJUnitReporter(resolvedOutputDir);
|
|
1825
|
+
case "html":
|
|
1826
|
+
return createHtmlReporter(resolvedOutputDir);
|
|
1827
|
+
case "allure":
|
|
1828
|
+
return createAllureReporter();
|
|
1829
|
+
default:
|
|
1830
|
+
return createConsoleReporter({ quiet: opts.quiet });
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1833
|
+
const totalFlowCount = selectedFlows.length * platforms.length;
|
|
1834
|
+
for (const reporter of reporters) {
|
|
1835
|
+
if (reporter.flowCount !== void 0 || "flowCount" in reporter) {
|
|
1836
|
+
reporter.flowCount = totalFlowCount;
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
const redactResult = (r) => {
|
|
1840
|
+
if (!r.error) return r;
|
|
1841
|
+
return {
|
|
1842
|
+
...r,
|
|
1843
|
+
error: {
|
|
1844
|
+
...r.error,
|
|
1845
|
+
message: redactor.redact(r.error.message),
|
|
1846
|
+
stack: r.error.stack ? redactor.redact(r.error.stack) : void 0,
|
|
1847
|
+
suggestion: r.error.suggestion ? redactor.redact(r.error.suggestion) : void 0
|
|
1848
|
+
}
|
|
1849
|
+
};
|
|
1850
|
+
};
|
|
1851
|
+
const retries = opts.retries ?? config.defaults?.retries ?? 0;
|
|
1852
|
+
const result = await orchestrate(selectedFlows, platformConfigs, {
|
|
1853
|
+
retries,
|
|
1854
|
+
bail: opts.bail,
|
|
1855
|
+
onFlowStart(name, platform) {
|
|
1856
|
+
for (const reporter of reporters) {
|
|
1857
|
+
reporter.onFlowStart?.(name, platform);
|
|
1858
|
+
}
|
|
1859
|
+
},
|
|
1860
|
+
onResult(r) {
|
|
1861
|
+
const redacted = redactResult(r);
|
|
1862
|
+
for (const reporter of reporters) {
|
|
1863
|
+
if (redacted.status === "passed") {
|
|
1864
|
+
reporter.onFlowPass?.(redacted);
|
|
1865
|
+
} else if (redacted.status === "failed") {
|
|
1866
|
+
reporter.onFlowFail?.(redacted);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
});
|
|
1871
|
+
const redactedResults = result.results.map(redactResult);
|
|
1872
|
+
for (const reporter of reporters) {
|
|
1873
|
+
reporter.onRunComplete({
|
|
1874
|
+
total: result.results.length,
|
|
1875
|
+
passed: result.passed,
|
|
1876
|
+
failed: result.failed,
|
|
1877
|
+
skipped: result.skipped,
|
|
1878
|
+
flaky: result.flaky,
|
|
1879
|
+
durationMs: result.totalDurationMs,
|
|
1880
|
+
results: redactedResults,
|
|
1881
|
+
platforms,
|
|
1882
|
+
bailedOut: result.bailedOut,
|
|
1883
|
+
bailLimit: result.bailLimit
|
|
1884
|
+
});
|
|
1885
|
+
}
|
|
1886
|
+
if (shouldReportToProvider && appiumUrl) {
|
|
1887
|
+
const { detectProvider: detectProvider2 } = await import("./provider-CUWPULGC.js");
|
|
1888
|
+
for (const rt of runtimes) {
|
|
1889
|
+
if (rt.metadata.mode === "appium" && rt.metadata.provider) {
|
|
1890
|
+
const provider = detectProvider2(appiumUrl);
|
|
1891
|
+
if (provider) {
|
|
1892
|
+
try {
|
|
1893
|
+
const meta = {};
|
|
1894
|
+
provider.extractMeta(rt.metadata.sessionId, rt.metadata.sessionCaps ?? {}, meta);
|
|
1895
|
+
await provider.reportResult(appiumUrl, meta, {
|
|
1896
|
+
passed: result.failed === 0,
|
|
1897
|
+
name: `spana ${platforms.join(",")}`
|
|
1898
|
+
});
|
|
1899
|
+
} catch (e) {
|
|
1900
|
+
console.log(
|
|
1901
|
+
`Warning: Failed to report to ${rt.metadata.provider}: ${e instanceof Error ? e.message : e}`
|
|
1902
|
+
);
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
return result.failed === 0;
|
|
1909
|
+
} finally {
|
|
1910
|
+
for (const rt of runtimes) {
|
|
1911
|
+
try {
|
|
1912
|
+
await rt.cleanup();
|
|
1913
|
+
} catch {
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
for (const cleanup of runCleanups) {
|
|
1917
|
+
try {
|
|
1918
|
+
await cleanup();
|
|
1919
|
+
} catch {
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
process.removeListener("SIGINT", handleSignal);
|
|
1923
|
+
process.removeListener("SIGTERM", handleSignal);
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
export {
|
|
1927
|
+
runTestCommand
|
|
1928
|
+
};
|
|
1929
|
+
//# sourceMappingURL=test-command-SB5KYPQI.js.map
|