spana-test 0.9.0 → 0.10.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/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +6 -6
- package/dist/{allure-RAEK4SIH.js → allure-FGVR5LND.js} +5 -1
- package/dist/allure-FGVR5LND.js.map +1 -0
- package/dist/{app-DSh1ejLh.d.ts → app-xIYd2jde.d.ts} +44 -1
- package/dist/{chunk-ALPQES3J.js → chunk-66D3C7NB.js} +142 -28
- package/dist/chunk-66D3C7NB.js.map +1 -0
- package/dist/{chunk-IGTK5MHB.js → chunk-6GBAPW6K.js} +12 -8
- package/dist/chunk-6GBAPW6K.js.map +1 -0
- package/dist/{chunk-JZZ2W2XH.js → chunk-7QFJ7MDH.js} +2 -1
- package/dist/chunk-7QFJ7MDH.js.map +1 -0
- package/dist/{chunk-3UVSUVHW.js → chunk-B35G77DN.js} +694 -404
- package/dist/chunk-B35G77DN.js.map +1 -0
- package/dist/{chunk-UEWZ2EXL.js → chunk-B473XZOM.js} +90 -13
- package/dist/chunk-B473XZOM.js.map +1 -0
- package/dist/{chunk-Y2RZNOKU.js → chunk-C2HBFEMQ.js} +2 -2
- package/dist/{chunk-PLE7RFQE.js → chunk-DP7MGXHN.js} +26 -1
- package/dist/chunk-DP7MGXHN.js.map +1 -0
- package/dist/{chunk-FP6PVHHR.js → chunk-IXON7DMB.js} +2 -2
- package/dist/{chunk-2KRVN4WN.js → chunk-Y6KMJJ2T.js} +3 -3
- package/dist/cli.js +16 -11
- package/dist/cli.js.map +1 -1
- package/dist/config-loader-WLPQ5WVH.js +9 -0
- package/dist/{console-BGAK7Z2L.js → console-DIYEJSSP.js} +9 -2
- package/dist/console-DIYEJSSP.js.map +1 -0
- package/dist/{doctor-command-YTCQ2SC7.js → doctor-command-QIYBI7ZF.js} +3 -3
- package/dist/{flow-CSMwD9Fh.d.ts → flow-CI5parw2.d.ts} +24 -3
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/{html-JO2YNRWX.js → html-FLMWPFQD.js} +2 -1
- package/dist/html-FLMWPFQD.js.map +1 -0
- package/dist/index.d.ts +17 -5
- package/dist/index.js +23 -9
- package/dist/index.js.map +1 -1
- package/dist/{junit-HLC62MK6.js → junit-CGB3LKHD.js} +3 -2
- package/dist/junit-CGB3LKHD.js.map +1 -0
- package/dist/{runner-TF4OKPYP.js → runner-JID2YWRE.js} +6 -2
- package/dist/{server-4YLBAZEM.js → server-6KQSTQIG.js} +12 -12
- package/dist/{server-IS4K5FCT.js → server-UIRGHUYM.js} +2 -2
- package/dist/{session-K7FCRKOC.js → session-BE6U34DA.js} +5 -5
- package/dist/{session-CgvT-Oso.d.ts → session-Bt_mbUWg.d.ts} +1 -1
- package/dist/{studio-command-RFPV2DS7.js → studio-command-TXQTIWRS.js} +2 -2
- package/dist/{test-command-UEJG5AI6.js → test-command-CCSQPKWU.js} +106 -27
- package/dist/test-command-CCSQPKWU.js.map +1 -0
- package/dist/{validator-BLOLIHUY.js → validator-YWNHCU2S.js} +3 -3
- package/package.json +1 -1
- package/dist/allure-RAEK4SIH.js.map +0 -1
- package/dist/chunk-3UVSUVHW.js.map +0 -1
- package/dist/chunk-ALPQES3J.js.map +0 -1
- package/dist/chunk-IGTK5MHB.js.map +0 -1
- package/dist/chunk-JZZ2W2XH.js.map +0 -1
- package/dist/chunk-PLE7RFQE.js.map +0 -1
- package/dist/chunk-UEWZ2EXL.js.map +0 -1
- package/dist/config-loader-F5YAY7RP.js +0 -9
- package/dist/console-BGAK7Z2L.js.map +0 -1
- package/dist/html-JO2YNRWX.js.map +0 -1
- package/dist/junit-HLC62MK6.js.map +0 -1
- package/dist/test-command-UEJG5AI6.js.map +0 -1
- /package/dist/{chunk-Y2RZNOKU.js.map → chunk-C2HBFEMQ.js.map} +0 -0
- /package/dist/{chunk-FP6PVHHR.js.map → chunk-IXON7DMB.js.map} +0 -0
- /package/dist/{chunk-2KRVN4WN.js.map → chunk-Y6KMJJ2T.js.map} +0 -0
- /package/dist/{config-loader-F5YAY7RP.js.map → config-loader-WLPQ5WVH.js.map} +0 -0
- /package/dist/{doctor-command-YTCQ2SC7.js.map → doctor-command-QIYBI7ZF.js.map} +0 -0
- /package/dist/{runner-TF4OKPYP.js.map → runner-JID2YWRE.js.map} +0 -0
- /package/dist/{server-4YLBAZEM.js.map → server-6KQSTQIG.js.map} +0 -0
- /package/dist/{server-IS4K5FCT.js.map → server-UIRGHUYM.js.map} +0 -0
- /package/dist/{session-K7FCRKOC.js.map → session-BE6U34DA.js.map} +0 -0
- /package/dist/{studio-command-RFPV2DS7.js.map → studio-command-TXQTIWRS.js.map} +0 -0
- /package/dist/{validator-BLOLIHUY.js.map → validator-YWNHCU2S.js.map} +0 -0
|
@@ -15,11 +15,7 @@ import {
|
|
|
15
15
|
createCompositeDomChannel,
|
|
16
16
|
createWebKitInspectorChannel,
|
|
17
17
|
domMatchToElement
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import {
|
|
20
|
-
getHealthyWarmDaemon,
|
|
21
|
-
registerWarmDaemon
|
|
22
|
-
} from "./chunk-Z6K4QQAR.js";
|
|
18
|
+
} from "./chunk-B473XZOM.js";
|
|
23
19
|
import {
|
|
24
20
|
installedUrlSchemesOnSimulator,
|
|
25
21
|
launchOnSimulator,
|
|
@@ -30,6 +26,10 @@ import {
|
|
|
30
26
|
resetSimulatorKeychain,
|
|
31
27
|
terminateOnSimulator
|
|
32
28
|
} from "./chunk-WV3ALL3H.js";
|
|
29
|
+
import {
|
|
30
|
+
getHealthyWarmDaemon,
|
|
31
|
+
registerWarmDaemon
|
|
32
|
+
} from "./chunk-Z6K4QQAR.js";
|
|
33
33
|
import {
|
|
34
34
|
allocateFreePort,
|
|
35
35
|
allocatePort,
|
|
@@ -2026,6 +2026,9 @@ function buildStorybookUrl(storyId, options, runtime) {
|
|
|
2026
2026
|
}
|
|
2027
2027
|
|
|
2028
2028
|
// src/api/expect.ts
|
|
2029
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
2030
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
2031
|
+
import { dirname, resolve as resolvePath } from "path";
|
|
2029
2032
|
import { Effect as Effect5 } from "effect";
|
|
2030
2033
|
function selectorToCss(sel) {
|
|
2031
2034
|
if (typeof sel === "string") return sel;
|
|
@@ -2059,26 +2062,60 @@ function deepEqual(a, b) {
|
|
|
2059
2062
|
}
|
|
2060
2063
|
return true;
|
|
2061
2064
|
}
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
const
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2065
|
+
var retryScope = new AsyncLocalStorage();
|
|
2066
|
+
var defaultRetryIntervals = [50, 100, 250, 500];
|
|
2067
|
+
function normalizeAriaSnapshot(snapshot) {
|
|
2068
|
+
const lines = snapshot.replaceAll("\r\n", "\n").trimEnd().split("\n");
|
|
2069
|
+
while (lines[0]?.trim() === "" && lines.length > 1) lines.shift();
|
|
2070
|
+
const indentation = lines.reduce(
|
|
2071
|
+
(minimum, line) => line.trim() ? Math.min(minimum, /^ */.exec(line)[0].length) : minimum,
|
|
2072
|
+
Infinity
|
|
2073
|
+
);
|
|
2074
|
+
return lines.map((line) => line.slice(indentation)).join("\n");
|
|
2075
|
+
}
|
|
2076
|
+
async function retryAssertion(check, timeout, intervals = defaultRetryIntervals) {
|
|
2077
|
+
if (!Number.isFinite(timeout) || timeout < 0 || intervals.some((ms) => !Number.isFinite(ms) || ms < 0)) {
|
|
2078
|
+
throw new RangeError("Assertion timeout and intervals must be finite, non-negative numbers");
|
|
2079
|
+
}
|
|
2080
|
+
if (intervals.length === 0) intervals = defaultRetryIntervals;
|
|
2081
|
+
let lastFailure;
|
|
2082
|
+
let expired = false;
|
|
2083
|
+
let delayTimer;
|
|
2084
|
+
let timeoutTimer;
|
|
2085
|
+
const deadline = new Promise((_, reject) => {
|
|
2086
|
+
timeoutTimer = setTimeout(() => {
|
|
2087
|
+
expired = true;
|
|
2088
|
+
const detail = lastFailure instanceof Error ? lastFailure.message : String(lastFailure);
|
|
2089
|
+
reject(
|
|
2090
|
+
new Error(
|
|
2091
|
+
`Assertion timed out after ${timeout}ms${lastFailure === void 0 ? "" : `: ${detail}`}`,
|
|
2092
|
+
{ cause: lastFailure }
|
|
2093
|
+
)
|
|
2094
|
+
);
|
|
2095
|
+
}, timeout);
|
|
2096
|
+
});
|
|
2097
|
+
const attempts = async () => {
|
|
2098
|
+
for (let attempt = 0; ; attempt++) {
|
|
2099
|
+
if (expired) return;
|
|
2100
|
+
try {
|
|
2101
|
+
await retryScope.run(true, check);
|
|
2102
|
+
return;
|
|
2103
|
+
} catch (error) {
|
|
2104
|
+
if (expired) return;
|
|
2105
|
+
lastFailure = error;
|
|
2106
|
+
const interval = intervals[Math.min(attempt, intervals.length - 1)];
|
|
2107
|
+
await new Promise((resolve2) => {
|
|
2108
|
+
delayTimer = setTimeout(resolve2, interval);
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2079
2111
|
}
|
|
2112
|
+
};
|
|
2113
|
+
try {
|
|
2114
|
+
await Promise.race([deadline, attempts()]);
|
|
2115
|
+
} finally {
|
|
2116
|
+
clearTimeout(timeoutTimer);
|
|
2117
|
+
clearTimeout(delayTimer);
|
|
2080
2118
|
}
|
|
2081
|
-
throw lastError instanceof Error ? lastError : new Error(`expect(fn).toPass() timed out after ${timeout}ms: ${String(lastError)}`);
|
|
2082
2119
|
}
|
|
2083
2120
|
function createPromiseExpect(driver, config, recorder, flowContext, visualRegression) {
|
|
2084
2121
|
const ctx = flowContext ?? {
|
|
@@ -2088,69 +2125,78 @@ function createPromiseExpect(driver, config, recorder, flowContext, visualRegres
|
|
|
2088
2125
|
};
|
|
2089
2126
|
const coord = createCoordinator(driver, config);
|
|
2090
2127
|
const defaultTimeout = config.defaults?.timeout ?? 5e3;
|
|
2091
|
-
const
|
|
2092
|
-
const
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2128
|
+
const run2 = (effect) => Effect5.runPromise(effect);
|
|
2129
|
+
const recordSoft = async (action) => {
|
|
2130
|
+
if (!ctx.recordSoftFailure || retryScope.getStore()) return action();
|
|
2131
|
+
try {
|
|
2132
|
+
await action();
|
|
2133
|
+
} catch (error) {
|
|
2134
|
+
ctx.recordSoftFailure(error);
|
|
2135
|
+
}
|
|
2136
|
+
};
|
|
2137
|
+
const recordStep = (command, action, selector) => recorder && !retryScope.getStore() ? recorder.runStep(command, action, { selector, captureScreenshot: false }) : action();
|
|
2138
|
+
const runSelectorStep = (command, selector, action) => recordStep(command, action, selector);
|
|
2139
|
+
const runSoftSelectorStep = (command, selector, action) => recordSoft(() => runSelectorStep(command, selector, action));
|
|
2140
|
+
const buildNegatedExpectation = (selector, runStep) => ({
|
|
2141
|
+
toBeVisible: (opts) => runStep("expect.not.toBeVisible", selector, () => run2(coord.assertHidden(selector, opts))),
|
|
2096
2142
|
toBeHidden: (opts) => runStep(
|
|
2097
2143
|
"expect.not.toBeHidden",
|
|
2098
2144
|
selector,
|
|
2099
|
-
() =>
|
|
2145
|
+
() => run2(coord.assertVisible(selector, opts)).then(() => {
|
|
2100
2146
|
})
|
|
2101
2147
|
),
|
|
2102
2148
|
toHaveText: (expected, opts) => runStep(
|
|
2103
2149
|
`expect.not.toHaveText(${JSON.stringify(expected)})`,
|
|
2104
2150
|
selector,
|
|
2105
|
-
() =>
|
|
2151
|
+
() => run2(coord.assertText(selector, expected, opts, true))
|
|
2106
2152
|
),
|
|
2107
2153
|
toMatchText: (pattern, opts) => runStep(
|
|
2108
2154
|
`expect.not.toMatchText(${pattern})`,
|
|
2109
2155
|
selector,
|
|
2110
|
-
() =>
|
|
2156
|
+
() => run2(coord.assertMatchesText(selector, pattern, opts, true))
|
|
2111
2157
|
),
|
|
2112
2158
|
toHaveValue: (expected, opts) => runStep(
|
|
2113
2159
|
`expect.not.toHaveValue(${JSON.stringify(expected)})`,
|
|
2114
2160
|
selector,
|
|
2115
|
-
() =>
|
|
2161
|
+
() => run2(coord.assertValue(selector, expected, opts, true))
|
|
2116
2162
|
),
|
|
2117
2163
|
toHaveAttribute: (name, value, opts) => runStep(
|
|
2118
2164
|
`expect.not.toHaveAttribute(${JSON.stringify(name)})`,
|
|
2119
2165
|
selector,
|
|
2120
|
-
() =>
|
|
2166
|
+
() => run2(coord.assertAttribute(selector, name, value, opts, true))
|
|
2121
2167
|
),
|
|
2122
|
-
toBeEnabled: (opts) => runStep("expect.not.toBeEnabled", selector, () =>
|
|
2123
|
-
toBeDisabled: (opts) => runStep("expect.not.toBeDisabled", selector, () =>
|
|
2168
|
+
toBeEnabled: (opts) => runStep("expect.not.toBeEnabled", selector, () => run2(coord.assertDisabled(selector, opts))),
|
|
2169
|
+
toBeDisabled: (opts) => runStep("expect.not.toBeDisabled", selector, () => run2(coord.assertEnabled(selector, opts))),
|
|
2124
2170
|
toContainText: (expected, opts) => runStep(
|
|
2125
2171
|
`expect.not.toContainText(${JSON.stringify(expected)})`,
|
|
2126
2172
|
selector,
|
|
2127
|
-
() =>
|
|
2173
|
+
() => run2(coord.assertContainsText(selector, expected, opts, true))
|
|
2128
2174
|
),
|
|
2129
2175
|
toHaveCount: (expected, opts) => runStep(
|
|
2130
2176
|
`expect.not.toHaveCount(${expected})`,
|
|
2131
2177
|
selector,
|
|
2132
|
-
() =>
|
|
2178
|
+
() => run2(coord.assertCount(selector, expected, opts, true))
|
|
2133
2179
|
),
|
|
2134
2180
|
toBeFocused: (opts) => runStep(
|
|
2135
2181
|
"expect.not.toBeFocused",
|
|
2136
2182
|
selector,
|
|
2137
|
-
() =>
|
|
2183
|
+
() => run2(coord.assertFocused(selector, opts, true))
|
|
2138
2184
|
),
|
|
2139
2185
|
toHaveAccessibleName: (expected, opts) => runStep(
|
|
2140
2186
|
`expect.not.toHaveAccessibleName(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2141
2187
|
selector,
|
|
2142
|
-
() =>
|
|
2188
|
+
() => run2(coord.assertAccessibleName(selector, expected, opts, true))
|
|
2143
2189
|
),
|
|
2144
2190
|
toHaveAccessibleDescription: (expected, opts) => runStep(
|
|
2145
2191
|
`expect.not.toHaveAccessibleDescription(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2146
2192
|
selector,
|
|
2147
|
-
() =>
|
|
2193
|
+
() => run2(coord.assertAccessibleDescription(selector, expected, opts, true))
|
|
2148
2194
|
)
|
|
2149
2195
|
});
|
|
2150
2196
|
const buildPollMatchers = (fn, opts, negate) => {
|
|
2151
|
-
const check = (label, predicate, describeFail) =>
|
|
2197
|
+
const check = (label, predicate, describeFail) => recordStep(
|
|
2152
2198
|
`expect.poll.${negate ? "not." : ""}${label}`,
|
|
2153
|
-
() =>
|
|
2199
|
+
() => retryAssertion(
|
|
2154
2200
|
async () => {
|
|
2155
2201
|
const val = await fn();
|
|
2156
2202
|
const ok = predicate(val);
|
|
@@ -2158,8 +2204,8 @@ function createPromiseExpect(driver, config, recorder, flowContext, visualRegres
|
|
|
2158
2204
|
throw new Error(describeFail(val));
|
|
2159
2205
|
}
|
|
2160
2206
|
},
|
|
2161
|
-
opts,
|
|
2162
|
-
|
|
2207
|
+
opts?.timeout ?? defaultTimeout,
|
|
2208
|
+
opts?.intervals
|
|
2163
2209
|
)
|
|
2164
2210
|
);
|
|
2165
2211
|
return {
|
|
@@ -2237,126 +2283,174 @@ function createPromiseExpect(driver, config, recorder, flowContext, visualRegres
|
|
|
2237
2283
|
)
|
|
2238
2284
|
};
|
|
2239
2285
|
};
|
|
2240
|
-
const
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2286
|
+
const buildSelectorExpectation = (selector, runStep) => ({
|
|
2287
|
+
toBeVisible: (opts) => runStep(
|
|
2288
|
+
"expect.toBeVisible",
|
|
2289
|
+
selector,
|
|
2290
|
+
() => run2(coord.assertVisible(selector, opts)).then(() => {
|
|
2291
|
+
})
|
|
2292
|
+
),
|
|
2293
|
+
toBeHidden: (opts) => runStep("expect.toBeHidden", selector, () => run2(coord.assertHidden(selector, opts))),
|
|
2294
|
+
toHaveText: (expected, opts) => runStep(
|
|
2295
|
+
`expect.toHaveText(${JSON.stringify(expected)})`,
|
|
2296
|
+
selector,
|
|
2297
|
+
() => run2(coord.assertText(selector, expected, opts))
|
|
2298
|
+
),
|
|
2299
|
+
toMatchText: (pattern, opts) => runStep(
|
|
2300
|
+
`expect.toMatchText(${pattern})`,
|
|
2301
|
+
selector,
|
|
2302
|
+
() => run2(coord.assertMatchesText(selector, pattern, opts))
|
|
2303
|
+
),
|
|
2304
|
+
toHaveValue: (expected, opts) => runStep(
|
|
2305
|
+
`expect.toHaveValue(${JSON.stringify(expected)})`,
|
|
2306
|
+
selector,
|
|
2307
|
+
() => run2(coord.assertValue(selector, expected, opts))
|
|
2308
|
+
),
|
|
2309
|
+
toHaveAttribute: (name, value, opts) => runStep(
|
|
2310
|
+
`expect.toHaveAttribute(${JSON.stringify(name)})`,
|
|
2311
|
+
selector,
|
|
2312
|
+
() => run2(coord.assertAttribute(selector, name, value, opts))
|
|
2313
|
+
),
|
|
2314
|
+
toBeEnabled: (opts) => runStep("expect.toBeEnabled", selector, () => run2(coord.assertEnabled(selector, opts))),
|
|
2315
|
+
toBeDisabled: (opts) => runStep("expect.toBeDisabled", selector, () => run2(coord.assertDisabled(selector, opts))),
|
|
2316
|
+
toContainText: (expected, opts) => runStep(
|
|
2317
|
+
`expect.toContainText(${JSON.stringify(expected)})`,
|
|
2318
|
+
selector,
|
|
2319
|
+
() => run2(coord.assertContainsText(selector, expected, opts))
|
|
2320
|
+
),
|
|
2321
|
+
toHaveCount: (expected, opts) => runStep(
|
|
2322
|
+
`expect.toHaveCount(${expected})`,
|
|
2323
|
+
selector,
|
|
2324
|
+
() => run2(coord.assertCount(selector, expected, opts))
|
|
2325
|
+
),
|
|
2326
|
+
toBeFocused: (opts) => runStep("expect.toBeFocused", selector, () => run2(coord.assertFocused(selector, opts))),
|
|
2327
|
+
toHaveAccessibleName: (expected, opts) => runStep(
|
|
2328
|
+
`expect.toHaveAccessibleName(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2329
|
+
selector,
|
|
2330
|
+
() => run2(coord.assertAccessibleName(selector, expected, opts))
|
|
2331
|
+
),
|
|
2332
|
+
toHaveAccessibleDescription: (expected, opts) => runStep(
|
|
2333
|
+
`expect.toHaveAccessibleDescription(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2334
|
+
selector,
|
|
2335
|
+
() => run2(coord.assertAccessibleDescription(selector, expected, opts))
|
|
2336
|
+
),
|
|
2337
|
+
not: buildNegatedExpectation(selector, runStep),
|
|
2338
|
+
toMatchAriaSnapshot: (expected, opts) => runStep("expect.toMatchAriaSnapshot", selector, async () => {
|
|
2339
|
+
if (!driver.getAriaSnapshot) {
|
|
2340
|
+
throw new Error(
|
|
2341
|
+
`toMatchAriaSnapshot() is not supported on ${ctx.platform} with the current driver`
|
|
2342
|
+
);
|
|
2343
|
+
}
|
|
2344
|
+
if (isRelativeSelector(selector))
|
|
2345
|
+
throw new Error("ARIA snapshots require a locator, not a relative selector");
|
|
2346
|
+
const timeout = opts?.timeout ?? defaultTimeout;
|
|
2347
|
+
const path = typeof expected === "string" ? void 0 : resolvePath(dirname(ctx.flowFilePath), expected.path);
|
|
2348
|
+
if (path && ctx.updateBaselines) {
|
|
2349
|
+
const actual = await run2(driver.getAriaSnapshot(selector, timeout));
|
|
2350
|
+
await mkdir(dirname(path), { recursive: true });
|
|
2351
|
+
await writeFile(path, `${normalizeAriaSnapshot(actual)}
|
|
2352
|
+
`, "utf8");
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2355
|
+
const baseline = normalizeAriaSnapshot(
|
|
2356
|
+
typeof expected === "string" ? expected : await readFile(path, "utf8")
|
|
2357
|
+
);
|
|
2358
|
+
await retryAssertion(
|
|
2359
|
+
async () => {
|
|
2360
|
+
const actual = normalizeAriaSnapshot(
|
|
2361
|
+
await run2(driver.getAriaSnapshot(selector, timeout))
|
|
2362
|
+
);
|
|
2363
|
+
if (actual !== baseline)
|
|
2364
|
+
throw new Error(
|
|
2365
|
+
`ARIA snapshot did not match.
|
|
2366
|
+
Expected:
|
|
2367
|
+
${baseline}
|
|
2368
|
+
Received:
|
|
2369
|
+
${actual}`
|
|
2370
|
+
);
|
|
2371
|
+
},
|
|
2372
|
+
timeout,
|
|
2373
|
+
opts?.intervals
|
|
2374
|
+
);
|
|
2375
|
+
}),
|
|
2376
|
+
toMatchScreenshot: (name, options) => runStep(
|
|
2377
|
+
`expect.toMatchScreenshot(${JSON.stringify(name)})`,
|
|
2378
|
+
selector,
|
|
2379
|
+
() => run2(
|
|
2380
|
+
coord.assertScreenshot(selector, name, ctx.flowFilePath, ctx.flowName, ctx.platform, {
|
|
2381
|
+
threshold: options?.threshold ?? visualRegression?.threshold,
|
|
2382
|
+
maxDiffPixelRatio: options?.maxDiffPixelRatio ?? visualRegression?.maxDiffPixelRatio,
|
|
2383
|
+
mask: [],
|
|
2384
|
+
updateBaselines: ctx.updateBaselines,
|
|
2385
|
+
baselinesDir: visualRegression?.baselinesDir
|
|
2252
2386
|
})
|
|
2253
|
-
)
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
toMatchText: (pattern, opts) => runStep(
|
|
2261
|
-
`expect.toMatchText(${pattern})`,
|
|
2262
|
-
selector,
|
|
2263
|
-
() => run(coord.assertMatchesText(selector, pattern, opts))
|
|
2264
|
-
),
|
|
2265
|
-
toHaveValue: (expected, opts) => runStep(
|
|
2266
|
-
`expect.toHaveValue(${JSON.stringify(expected)})`,
|
|
2267
|
-
selector,
|
|
2268
|
-
() => run(coord.assertValue(selector, expected, opts))
|
|
2269
|
-
),
|
|
2270
|
-
toHaveAttribute: (name, value, opts) => runStep(
|
|
2271
|
-
`expect.toHaveAttribute(${JSON.stringify(name)})`,
|
|
2272
|
-
selector,
|
|
2273
|
-
() => run(coord.assertAttribute(selector, name, value, opts))
|
|
2274
|
-
),
|
|
2275
|
-
toBeEnabled: (opts) => runStep("expect.toBeEnabled", selector, () => run(coord.assertEnabled(selector, opts))),
|
|
2276
|
-
toBeDisabled: (opts) => runStep("expect.toBeDisabled", selector, () => run(coord.assertDisabled(selector, opts))),
|
|
2277
|
-
toContainText: (expected, opts) => runStep(
|
|
2278
|
-
`expect.toContainText(${JSON.stringify(expected)})`,
|
|
2279
|
-
selector,
|
|
2280
|
-
() => run(coord.assertContainsText(selector, expected, opts))
|
|
2281
|
-
),
|
|
2282
|
-
toHaveCount: (expected, opts) => runStep(
|
|
2283
|
-
`expect.toHaveCount(${expected})`,
|
|
2284
|
-
selector,
|
|
2285
|
-
() => run(coord.assertCount(selector, expected, opts))
|
|
2286
|
-
),
|
|
2287
|
-
toBeFocused: (opts) => runStep("expect.toBeFocused", selector, () => run(coord.assertFocused(selector, opts))),
|
|
2288
|
-
toHaveAccessibleName: (expected, opts) => runStep(
|
|
2289
|
-
`expect.toHaveAccessibleName(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2290
|
-
selector,
|
|
2291
|
-
() => run(coord.assertAccessibleName(selector, expected, opts))
|
|
2292
|
-
),
|
|
2293
|
-
toHaveAccessibleDescription: (expected, opts) => runStep(
|
|
2294
|
-
`expect.toHaveAccessibleDescription(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2295
|
-
selector,
|
|
2296
|
-
() => run(coord.assertAccessibleDescription(selector, expected, opts))
|
|
2297
|
-
),
|
|
2298
|
-
not: buildNegatedExpectation(selector),
|
|
2299
|
-
toMatchScreenshot: (name, options) => runStep(
|
|
2300
|
-
`expect.toMatchScreenshot(${JSON.stringify(name)})`,
|
|
2387
|
+
)
|
|
2388
|
+
),
|
|
2389
|
+
toPassAccessibilityAudit: (options) => {
|
|
2390
|
+
const excludeCss = options?.exclude?.map(selectorToCss).filter(Boolean) ?? [];
|
|
2391
|
+
const targetCss = selectorToCss(selector);
|
|
2392
|
+
return runStep(
|
|
2393
|
+
"expect.toPassAccessibilityAudit",
|
|
2301
2394
|
selector,
|
|
2302
|
-
() =>
|
|
2303
|
-
coord.
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
baselinesDir: visualRegression?.baselinesDir
|
|
2395
|
+
() => run2(
|
|
2396
|
+
coord.assertAccessibilityAudit(ctx.platform, {
|
|
2397
|
+
severity: options?.severity,
|
|
2398
|
+
rules: options?.rules,
|
|
2399
|
+
targetSelector: targetCss || void 0,
|
|
2400
|
+
excludeSelectors: excludeCss
|
|
2309
2401
|
})
|
|
2310
2402
|
)
|
|
2311
|
-
)
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
() =>
|
|
2342
|
-
),
|
|
2343
|
-
toHaveMinTouchTarget: (size = 44) => runStep(
|
|
2344
|
-
`expect.toHaveMinTouchTarget(${size})`,
|
|
2345
|
-
selector,
|
|
2346
|
-
() => run(coord.assertMinTouchTarget(selector, size))
|
|
2403
|
+
);
|
|
2404
|
+
},
|
|
2405
|
+
toHaveAccessibilityLabel: (expected) => runStep(
|
|
2406
|
+
`expect.toHaveAccessibilityLabel(${expected !== void 0 ? JSON.stringify(expected) : ""})`,
|
|
2407
|
+
selector,
|
|
2408
|
+
() => run2(coord.assertAccessibilityLabel(selector, expected))
|
|
2409
|
+
),
|
|
2410
|
+
toBeFocusable: () => runStep(
|
|
2411
|
+
"expect.toBeFocusable",
|
|
2412
|
+
selector,
|
|
2413
|
+
() => run2(coord.assertFocusable(selector, ctx.platform))
|
|
2414
|
+
),
|
|
2415
|
+
toHaveRole: (expected) => runStep(
|
|
2416
|
+
`expect.toHaveRole(${JSON.stringify(expected)})`,
|
|
2417
|
+
selector,
|
|
2418
|
+
() => run2(coord.assertRole(selector, expected, ctx.platform))
|
|
2419
|
+
),
|
|
2420
|
+
toHaveMinTouchTarget: (size = 44) => runStep(
|
|
2421
|
+
`expect.toHaveMinTouchTarget(${size})`,
|
|
2422
|
+
selector,
|
|
2423
|
+
() => run2(coord.assertMinTouchTarget(selector, size))
|
|
2424
|
+
)
|
|
2425
|
+
});
|
|
2426
|
+
const expectFn = ((selectorOrFn) => {
|
|
2427
|
+
if (typeof selectorOrFn !== "function") {
|
|
2428
|
+
return buildSelectorExpectation(selectorOrFn, runSelectorStep);
|
|
2429
|
+
}
|
|
2430
|
+
return {
|
|
2431
|
+
toPass: (opts) => recordStep(
|
|
2432
|
+
"expect.toPass",
|
|
2433
|
+
() => retryAssertion(selectorOrFn, opts?.timeout ?? defaultTimeout, opts?.intervals)
|
|
2347
2434
|
)
|
|
2348
2435
|
};
|
|
2349
2436
|
});
|
|
2350
|
-
|
|
2437
|
+
const toHaveURL = (expected, opts) => {
|
|
2351
2438
|
const label = `expect.toHaveURL(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`;
|
|
2352
|
-
return
|
|
2439
|
+
return recordStep(label, () => run2(coord.waitForURL(expected, opts)));
|
|
2353
2440
|
};
|
|
2441
|
+
expectFn.toHaveURL = toHaveURL;
|
|
2442
|
+
expectFn.soft = Object.assign(
|
|
2443
|
+
(selector) => buildSelectorExpectation(selector, runSoftSelectorStep),
|
|
2444
|
+
{
|
|
2445
|
+
toHaveURL: (expected, opts) => recordSoft(() => toHaveURL(expected, opts))
|
|
2446
|
+
}
|
|
2447
|
+
);
|
|
2354
2448
|
Object.defineProperty(expectFn, "not", {
|
|
2355
2449
|
enumerable: true,
|
|
2356
2450
|
value: {
|
|
2357
2451
|
toHaveURL: (expected, opts) => {
|
|
2358
2452
|
const label = `expect.not.toHaveURL(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`;
|
|
2359
|
-
return
|
|
2453
|
+
return recordStep(label, () => run2(coord.waitForURL(expected, opts, true)));
|
|
2360
2454
|
}
|
|
2361
2455
|
}
|
|
2362
2456
|
});
|
|
@@ -2566,16 +2660,29 @@ function wrapRawPageWithStepRecording(rawPage, recorder) {
|
|
|
2566
2660
|
function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
2567
2661
|
const coord = createCoordinator(driver, config);
|
|
2568
2662
|
const platform = options.platform ?? (appId.startsWith("http://") || appId.startsWith("https://") ? "web" : void 0);
|
|
2569
|
-
const
|
|
2663
|
+
const run2 = (effect) => Effect6.runPromise(effect);
|
|
2570
2664
|
const unsupportedWebFeature = (feature) => Effect6.fail(new DriverError({ message: `${feature}() is only supported on the web platform` }));
|
|
2571
2665
|
const optionalMethod = (name, method) => method ?? ((..._args) => unsupportedWebFeature(name));
|
|
2666
|
+
const unsupportedNetworkFeature = async (name) => {
|
|
2667
|
+
const target = platform ?? (await run2(driver.getDeviceInfo())).platform;
|
|
2668
|
+
throw new DriverError({
|
|
2669
|
+
message: `${name}() is not supported on ${target} with the current driver`
|
|
2670
|
+
});
|
|
2671
|
+
};
|
|
2572
2672
|
const runStep = (command, action, opts) => recorder ? recorder.runStep(command, action, opts) : action();
|
|
2673
|
+
const runDeviceStep = (name, method, ...args) => runStep(name, async () => {
|
|
2674
|
+
if (!method) {
|
|
2675
|
+
const target = platform ?? (await run2(driver.getDeviceInfo())).platform;
|
|
2676
|
+
throw new DriverError({ message: `${name}() is not supported on ${target}` });
|
|
2677
|
+
}
|
|
2678
|
+
await run2(method(...args));
|
|
2679
|
+
});
|
|
2573
2680
|
const runScreenshotStep = (command, action, opts) => recorder ? recorder.runScreenshotStep(command, action, opts) : action();
|
|
2574
2681
|
const getCurrentUrl = async () => {
|
|
2575
2682
|
if (driver.getUrl) {
|
|
2576
|
-
return
|
|
2683
|
+
return run2(driver.getUrl());
|
|
2577
2684
|
}
|
|
2578
|
-
return
|
|
2685
|
+
return run2(
|
|
2579
2686
|
driver.evaluate(
|
|
2580
2687
|
"typeof window !== 'undefined' && window.location ? String(window.location.href || '') : ''"
|
|
2581
2688
|
).pipe(Effect6.catchAll(() => Effect6.succeed("")))
|
|
@@ -2599,7 +2706,7 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
2599
2706
|
const headers = { ...init?.headers };
|
|
2600
2707
|
const hasCookieHeader = Object.keys(headers).some((k) => k.toLowerCase() === "cookie");
|
|
2601
2708
|
if (!hasCookieHeader && driver.getCookies) {
|
|
2602
|
-
const cookies = await
|
|
2709
|
+
const cookies = await run2(driver.getCookies([targetUrl.toString()])).catch(() => []);
|
|
2603
2710
|
if (cookies.length > 0) {
|
|
2604
2711
|
headers["cookie"] = cookies.map((c) => `${c.name}=${c.value}`).join("; ");
|
|
2605
2712
|
}
|
|
@@ -2625,7 +2732,7 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
2625
2732
|
const rawSetCookies = typeof res.headers.getSetCookie === "function" ? res.headers.getSetCookie() : res.headers.get("set-cookie") ? [res.headers.get("set-cookie")] : [];
|
|
2626
2733
|
const parsedCookies = rawSetCookies.map((line) => parseSetCookieHeader(line, targetUrl)).filter((c) => c !== null);
|
|
2627
2734
|
if (parsedCookies.length > 0) {
|
|
2628
|
-
await
|
|
2735
|
+
await run2(driver.setCookies(parsedCookies)).catch(() => {
|
|
2629
2736
|
});
|
|
2630
2737
|
}
|
|
2631
2738
|
}
|
|
@@ -2687,51 +2794,59 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
2687
2794
|
options.visualRegression
|
|
2688
2795
|
);
|
|
2689
2796
|
const appObj = {
|
|
2690
|
-
|
|
2691
|
-
|
|
2797
|
+
setGeolocation: (point) => runDeviceStep("setGeolocation", driver.setGeolocation, point),
|
|
2798
|
+
setSystemTime: (time) => runDeviceStep("setSystemTime", driver.setSystemTime, time),
|
|
2799
|
+
grantPermission: (permission, opts) => runDeviceStep("grantPermission", driver.setPermission, appId, permission, "grant", opts),
|
|
2800
|
+
denyPermission: (permission, opts) => runDeviceStep("denyPermission", driver.setPermission, appId, permission, "deny", opts),
|
|
2801
|
+
setOrientation: (orientation) => runDeviceStep("setOrientation", driver.setOrientation, orientation),
|
|
2802
|
+
setBiometricEnrollment: (enabled) => runDeviceStep("setBiometricEnrollment", driver.setBiometricEnrollment, enabled),
|
|
2803
|
+
simulateBiometric: (opts) => runDeviceStep("simulateBiometric", driver.simulateBiometric, opts),
|
|
2804
|
+
sendPushNotification: (payload) => runDeviceStep("sendPushNotification", driver.sendPushNotification, appId, payload),
|
|
2805
|
+
tap: (selector, opts) => runStep("tap", () => run2(coord.tap(selector, opts)), { selector, captureScreenshot: true }),
|
|
2806
|
+
tapXY: (x, y) => runStep("tapXY", () => run2(coord.tapXY(x, y)), {
|
|
2692
2807
|
selector: { point: { x, y } },
|
|
2693
2808
|
captureScreenshot: true
|
|
2694
2809
|
}),
|
|
2695
|
-
doubleTap: (selector, opts) => runStep("doubleTap", () =>
|
|
2810
|
+
doubleTap: (selector, opts) => runStep("doubleTap", () => run2(coord.doubleTap(selector, opts)), {
|
|
2696
2811
|
selector,
|
|
2697
2812
|
captureScreenshot: true
|
|
2698
2813
|
}),
|
|
2699
|
-
longPress: (selector, opts) => runStep("longPress", () =>
|
|
2814
|
+
longPress: (selector, opts) => runStep("longPress", () => run2(coord.longPress(selector, opts?.duration, opts)), {
|
|
2700
2815
|
selector,
|
|
2701
2816
|
captureScreenshot: true
|
|
2702
2817
|
}),
|
|
2703
|
-
longPressXY: (x, y, opts) => runStep("longPressXY", () =>
|
|
2818
|
+
longPressXY: (x, y, opts) => runStep("longPressXY", () => run2(coord.longPressXY(x, y, opts?.duration)), {
|
|
2704
2819
|
selector: { point: { x, y } },
|
|
2705
2820
|
captureScreenshot: true
|
|
2706
2821
|
}),
|
|
2707
|
-
hover: (selector, opts) => runStep("hover", () =>
|
|
2822
|
+
hover: (selector, opts) => runStep("hover", () => run2(coord.hover(selector, opts)), {
|
|
2708
2823
|
selector,
|
|
2709
2824
|
captureScreenshot: true
|
|
2710
2825
|
}),
|
|
2711
|
-
inputText: (text) => runStep("inputText", () =>
|
|
2712
|
-
fill: (selector, value, opts) => runStep("fill", () =>
|
|
2826
|
+
inputText: (text) => runStep("inputText", () => run2(coord.inputText(text)), { captureScreenshot: true }),
|
|
2827
|
+
fill: (selector, value, opts) => runStep("fill", () => run2(coord.fill(selector, value, opts)), {
|
|
2713
2828
|
selector,
|
|
2714
2829
|
captureScreenshot: true
|
|
2715
2830
|
}),
|
|
2716
|
-
pressKey: (key) => runStep(`pressKey(${key})`, () =>
|
|
2717
|
-
hideKeyboard: () => runStep("hideKeyboard", () =>
|
|
2831
|
+
pressKey: (key) => runStep(`pressKey(${key})`, () => run2(coord.pressKey(key)), { captureScreenshot: true }),
|
|
2832
|
+
hideKeyboard: () => runStep("hideKeyboard", () => run2(coord.hideKeyboard()), { captureScreenshot: true }),
|
|
2718
2833
|
dismissKeyboard: (opts) => runStep(
|
|
2719
2834
|
`dismissKeyboard(${opts?.strategy ?? "auto"})`,
|
|
2720
|
-
() =>
|
|
2835
|
+
() => run2(coord.dismissKeyboard(opts)),
|
|
2721
2836
|
{
|
|
2722
2837
|
selector: { strategy: opts?.strategy ?? "auto" },
|
|
2723
2838
|
captureScreenshot: true
|
|
2724
2839
|
}
|
|
2725
2840
|
),
|
|
2726
|
-
swipe: (direction, opts) => runStep(`swipe(${direction})`, () =>
|
|
2841
|
+
swipe: (direction, opts) => runStep(`swipe(${direction})`, () => run2(coord.swipe(direction, opts)), {
|
|
2727
2842
|
captureScreenshot: true
|
|
2728
2843
|
}),
|
|
2729
|
-
scroll: (direction) => runStep(`scroll(${direction})`, () =>
|
|
2844
|
+
scroll: (direction) => runStep(`scroll(${direction})`, () => run2(coord.scroll(direction)), {
|
|
2730
2845
|
captureScreenshot: true
|
|
2731
2846
|
}),
|
|
2732
2847
|
scrollUntilVisible: (selector, opts) => runStep(
|
|
2733
2848
|
`scrollUntilVisible(${opts?.direction ?? "down"})`,
|
|
2734
|
-
() =>
|
|
2849
|
+
() => run2(coord.scrollUntilVisible(selector, opts)),
|
|
2735
2850
|
{
|
|
2736
2851
|
selector: {
|
|
2737
2852
|
target: selector,
|
|
@@ -2744,7 +2859,7 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
2744
2859
|
),
|
|
2745
2860
|
backUntilVisible: (selector, opts) => runStep(
|
|
2746
2861
|
`backUntilVisible(${opts?.maxBacks ?? 3})`,
|
|
2747
|
-
() =>
|
|
2862
|
+
() => run2(coord.backUntilVisible(selector, opts)),
|
|
2748
2863
|
{
|
|
2749
2864
|
selector: {
|
|
2750
2865
|
target: selector,
|
|
@@ -2756,15 +2871,15 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
2756
2871
|
),
|
|
2757
2872
|
launch: (opts) => {
|
|
2758
2873
|
const mergedLaunchOptions = mergeLaunchOptions(options.launchOptions, opts);
|
|
2759
|
-
return runStep("launch", () =>
|
|
2874
|
+
return runStep("launch", () => run2(driver.launchApp(appId, mergedLaunchOptions)), {
|
|
2760
2875
|
selector: mergedLaunchOptions,
|
|
2761
2876
|
captureScreenshot: true
|
|
2762
2877
|
});
|
|
2763
2878
|
},
|
|
2764
|
-
stop: () => runStep("stop", () =>
|
|
2765
|
-
kill: () => runStep("kill", () =>
|
|
2766
|
-
clearState: () => runStep("clearState", () =>
|
|
2767
|
-
openLink: (url) => runStep("openLink", () =>
|
|
2879
|
+
stop: () => runStep("stop", () => run2(driver.stopApp(appId)), { captureScreenshot: true }),
|
|
2880
|
+
kill: () => runStep("kill", () => run2(driver.killApp(appId)), { captureScreenshot: true }),
|
|
2881
|
+
clearState: () => runStep("clearState", () => run2(driver.clearAppState(appId)), { captureScreenshot: true }),
|
|
2882
|
+
openLink: (url) => runStep("openLink", () => run2(driver.openLink(url)), {
|
|
2768
2883
|
selector: { url },
|
|
2769
2884
|
captureScreenshot: true
|
|
2770
2885
|
}),
|
|
@@ -2772,14 +2887,14 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
2772
2887
|
`openStory(${storyId})`,
|
|
2773
2888
|
async () => {
|
|
2774
2889
|
if (platform !== "web") {
|
|
2775
|
-
await
|
|
2890
|
+
await run2(unsupportedWebFeature("openStory"));
|
|
2776
2891
|
return;
|
|
2777
2892
|
}
|
|
2778
2893
|
const url = buildStorybookUrl(storyId, opts, {
|
|
2779
2894
|
appBaseUrl: appId,
|
|
2780
2895
|
storybook: options.storybook
|
|
2781
2896
|
});
|
|
2782
|
-
await
|
|
2897
|
+
await run2(driver.openLink(url));
|
|
2783
2898
|
},
|
|
2784
2899
|
{
|
|
2785
2900
|
selector: {
|
|
@@ -2792,129 +2907,129 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
2792
2907
|
captureScreenshot: true
|
|
2793
2908
|
}
|
|
2794
2909
|
),
|
|
2795
|
-
back: () => runStep("back", () =>
|
|
2910
|
+
back: () => runStep("back", () => run2(driver.back()), { captureScreenshot: true }),
|
|
2796
2911
|
reload: (opts) => runStep(
|
|
2797
2912
|
"reload",
|
|
2798
2913
|
async () => {
|
|
2799
2914
|
if (driver.reload) {
|
|
2800
|
-
await
|
|
2915
|
+
await run2(driver.reload(opts));
|
|
2801
2916
|
return;
|
|
2802
2917
|
}
|
|
2803
2918
|
if (driver.domChannel?.reload) {
|
|
2804
2919
|
await driver.domChannel.reload();
|
|
2805
2920
|
return;
|
|
2806
2921
|
}
|
|
2807
|
-
await
|
|
2922
|
+
await run2(driver.evaluate("window.location.reload()"));
|
|
2808
2923
|
},
|
|
2809
2924
|
{ captureScreenshot: true }
|
|
2810
2925
|
),
|
|
2811
2926
|
url: () => runStep("url", () => getCurrentUrl()),
|
|
2812
2927
|
waitForURL: (expected, opts) => runStep(
|
|
2813
2928
|
`waitForURL(${expected instanceof RegExp ? String(expected) : JSON.stringify(expected)})`,
|
|
2814
|
-
() =>
|
|
2929
|
+
() => run2(coord.waitForURL(expected, opts))
|
|
2815
2930
|
),
|
|
2816
2931
|
waitForResponse: (matcher, opts) => runStep(
|
|
2817
2932
|
`waitForResponse(${typeof matcher === "function" ? "<predicate>" : describeMatcher(matcher)})`,
|
|
2818
|
-
() =>
|
|
2933
|
+
() => run2(optionalMethod("waitForResponse", driver.waitForResponse)(matcher, opts))
|
|
2819
2934
|
),
|
|
2820
2935
|
takeScreenshot: (name) => runScreenshotStep(
|
|
2821
2936
|
name ? `takeScreenshot(${name})` : "takeScreenshot",
|
|
2822
|
-
() =>
|
|
2937
|
+
() => run2(driver.takeScreenshot()),
|
|
2823
2938
|
{ name }
|
|
2824
2939
|
),
|
|
2825
2940
|
evaluate: (fn, ...args) => runStep(
|
|
2826
2941
|
formatEvaluateCommand(fn),
|
|
2827
|
-
() =>
|
|
2942
|
+
() => run2(driver.evaluate(fn, ...args))
|
|
2828
2943
|
),
|
|
2829
2944
|
mockNetwork: (matcher, response) => runStep(
|
|
2830
2945
|
"mockNetwork",
|
|
2831
|
-
() =>
|
|
2946
|
+
() => driver.mockNetwork ? run2(driver.mockNetwork(matcher, response)) : unsupportedNetworkFeature("mockNetwork"),
|
|
2832
2947
|
{
|
|
2833
2948
|
selector: { matcher: describeMatcher(matcher), response }
|
|
2834
2949
|
}
|
|
2835
2950
|
),
|
|
2836
2951
|
blockNetwork: (matcher) => runStep(
|
|
2837
2952
|
"blockNetwork",
|
|
2838
|
-
() =>
|
|
2953
|
+
() => driver.blockNetwork ? run2(driver.blockNetwork(matcher)) : unsupportedNetworkFeature("blockNetwork"),
|
|
2839
2954
|
{
|
|
2840
2955
|
selector: { matcher: describeMatcher(matcher) }
|
|
2841
2956
|
}
|
|
2842
2957
|
),
|
|
2843
2958
|
clearNetworkMocks: () => runStep(
|
|
2844
2959
|
"clearNetworkMocks",
|
|
2845
|
-
() =>
|
|
2960
|
+
() => driver.clearNetworkMocks ? run2(driver.clearNetworkMocks()) : unsupportedNetworkFeature("clearNetworkMocks")
|
|
2846
2961
|
),
|
|
2847
2962
|
setNetworkConditions: (conditions) => runStep(
|
|
2848
2963
|
"setNetworkConditions",
|
|
2849
|
-
() =>
|
|
2964
|
+
() => run2(optionalMethod("setNetworkConditions", driver.setNetworkConditions)(conditions)),
|
|
2850
2965
|
{ selector: conditions }
|
|
2851
2966
|
),
|
|
2852
2967
|
setOffline: (offline) => runStep(
|
|
2853
2968
|
`setOffline(${offline})`,
|
|
2854
|
-
() =>
|
|
2969
|
+
() => run2(optionalMethod("setOffline", driver.setNetworkConditions)({ offline })),
|
|
2855
2970
|
{ selector: { offline } }
|
|
2856
2971
|
),
|
|
2857
|
-
saveCookies: (path) => runStep("saveCookies", () =>
|
|
2972
|
+
saveCookies: (path) => runStep("saveCookies", () => run2(optionalMethod("saveCookies", driver.saveCookies)(path)), {
|
|
2858
2973
|
selector: { path }
|
|
2859
2974
|
}),
|
|
2860
|
-
loadCookies: (path) => runStep("loadCookies", () =>
|
|
2975
|
+
loadCookies: (path) => runStep("loadCookies", () => run2(optionalMethod("loadCookies", driver.loadCookies)(path)), {
|
|
2861
2976
|
selector: { path }
|
|
2862
2977
|
}),
|
|
2863
|
-
getCookies: (urls) => runStep("getCookies", () =>
|
|
2864
|
-
setCookies: (cookies) => runStep("setCookies", () =>
|
|
2978
|
+
getCookies: (urls) => runStep("getCookies", () => run2(optionalMethod("getCookies", driver.getCookies)(urls))),
|
|
2979
|
+
setCookies: (cookies) => runStep("setCookies", () => run2(optionalMethod("setCookies", driver.setCookies)(cookies)), {
|
|
2865
2980
|
selector: { count: cookies.length }
|
|
2866
2981
|
}),
|
|
2867
|
-
clearCookies: () => runStep("clearCookies", () =>
|
|
2982
|
+
clearCookies: () => runStep("clearCookies", () => run2(optionalMethod("clearCookies", driver.clearCookies)())),
|
|
2868
2983
|
saveAuthState: (path) => runStep(
|
|
2869
2984
|
"saveAuthState",
|
|
2870
|
-
() =>
|
|
2985
|
+
() => run2(optionalMethod("saveAuthState", driver.saveAuthState)(path)),
|
|
2871
2986
|
{ selector: { path } }
|
|
2872
2987
|
),
|
|
2873
2988
|
loadAuthState: (path) => runStep(
|
|
2874
2989
|
"loadAuthState",
|
|
2875
|
-
() =>
|
|
2990
|
+
() => run2(optionalMethod("loadAuthState", driver.loadAuthState)(path)),
|
|
2876
2991
|
{ selector: { path } }
|
|
2877
2992
|
),
|
|
2878
2993
|
downloadFile: (path) => runStep(
|
|
2879
2994
|
"downloadFile",
|
|
2880
|
-
() =>
|
|
2995
|
+
() => run2(optionalMethod("downloadFile", driver.downloadFile)(path)),
|
|
2881
2996
|
{ selector: { path } }
|
|
2882
2997
|
),
|
|
2883
2998
|
uploadFile: (selector, path) => runStep(
|
|
2884
2999
|
"uploadFile",
|
|
2885
|
-
() =>
|
|
3000
|
+
() => run2(optionalMethod("uploadFile", driver.uploadFile)(selector, path)),
|
|
2886
3001
|
{
|
|
2887
3002
|
selector: { target: selector, path },
|
|
2888
3003
|
captureScreenshot: true
|
|
2889
3004
|
}
|
|
2890
3005
|
),
|
|
2891
|
-
newTab: (url) => runStep("newTab", () =>
|
|
3006
|
+
newTab: (url) => runStep("newTab", () => run2(optionalMethod("newTab", driver.newTab)(url)), {
|
|
2892
3007
|
selector: url ? { url } : void 0,
|
|
2893
3008
|
captureScreenshot: true
|
|
2894
3009
|
}),
|
|
2895
3010
|
switchToTab: (index) => runStep(
|
|
2896
3011
|
`switchToTab(${index})`,
|
|
2897
|
-
() =>
|
|
3012
|
+
() => run2(optionalMethod("switchToTab", driver.switchToTab)(index)),
|
|
2898
3013
|
{
|
|
2899
3014
|
selector: { index },
|
|
2900
3015
|
captureScreenshot: true
|
|
2901
3016
|
}
|
|
2902
3017
|
),
|
|
2903
|
-
closeTab: () => runStep("closeTab", () =>
|
|
3018
|
+
closeTab: () => runStep("closeTab", () => run2(optionalMethod("closeTab", driver.closeTab)()), {
|
|
2904
3019
|
captureScreenshot: true
|
|
2905
3020
|
}),
|
|
2906
|
-
getTabIds: () => runStep("getTabIds", () =>
|
|
3021
|
+
getTabIds: () => runStep("getTabIds", () => run2(optionalMethod("getTabIds", driver.getTabIds)())),
|
|
2907
3022
|
getConsoleLogs: () => runStep(
|
|
2908
3023
|
"getConsoleLogs",
|
|
2909
|
-
() =>
|
|
3024
|
+
() => run2(optionalMethod("getConsoleLogs", driver.getConsoleLogs)())
|
|
2910
3025
|
),
|
|
2911
|
-
getJSErrors: () => runStep("getJSErrors", () =>
|
|
2912
|
-
getHAR: () => runStep("getHAR", () =>
|
|
3026
|
+
getJSErrors: () => runStep("getJSErrors", () => run2(optionalMethod("getJSErrors", driver.getJSErrors)())),
|
|
3027
|
+
getHAR: () => runStep("getHAR", () => run2(optionalMethod("getHAR", driver.getHAR)())),
|
|
2913
3028
|
request: requestClient,
|
|
2914
3029
|
newContext: (ctxOpts) => runStep(
|
|
2915
3030
|
"newContext",
|
|
2916
3031
|
async () => {
|
|
2917
|
-
const created = await
|
|
3032
|
+
const created = await run2(
|
|
2918
3033
|
optionalMethod("newContext", driver.createIsolatedContext)(ctxOpts)
|
|
2919
3034
|
);
|
|
2920
3035
|
let closed = false;
|
|
@@ -2984,14 +3099,14 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
2984
3099
|
},
|
|
2985
3100
|
enableVirtualAuthenticator: (opts) => runStep(
|
|
2986
3101
|
"enableVirtualAuthenticator",
|
|
2987
|
-
() =>
|
|
3102
|
+
() => run2(
|
|
2988
3103
|
optionalMethod("enableVirtualAuthenticator", driver.enableVirtualAuthenticator)(opts)
|
|
2989
3104
|
),
|
|
2990
3105
|
{ selector: opts }
|
|
2991
3106
|
),
|
|
2992
3107
|
removeVirtualAuthenticator: (authenticatorId) => runStep(
|
|
2993
3108
|
"removeVirtualAuthenticator",
|
|
2994
|
-
() =>
|
|
3109
|
+
() => run2(
|
|
2995
3110
|
optionalMethod(
|
|
2996
3111
|
"removeVirtualAuthenticator",
|
|
2997
3112
|
driver.removeVirtualAuthenticator
|
|
@@ -3000,11 +3115,11 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
3000
3115
|
),
|
|
3001
3116
|
getVirtualCredentials: (authenticatorId) => runStep(
|
|
3002
3117
|
"getVirtualCredentials",
|
|
3003
|
-
() =>
|
|
3118
|
+
() => run2(optionalMethod("getVirtualCredentials", driver.getVirtualCredentials)(authenticatorId))
|
|
3004
3119
|
),
|
|
3005
3120
|
addVirtualCredential: (credential, authenticatorId) => runStep(
|
|
3006
3121
|
"addVirtualCredential",
|
|
3007
|
-
() =>
|
|
3122
|
+
() => run2(
|
|
3008
3123
|
optionalMethod("addVirtualCredential", driver.addVirtualCredential)(
|
|
3009
3124
|
credential,
|
|
3010
3125
|
authenticatorId
|
|
@@ -3014,29 +3129,29 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
3014
3129
|
),
|
|
3015
3130
|
clearVirtualCredentials: (authenticatorId) => runStep(
|
|
3016
3131
|
"clearVirtualCredentials",
|
|
3017
|
-
() =>
|
|
3132
|
+
() => run2(
|
|
3018
3133
|
optionalMethod(
|
|
3019
3134
|
"clearVirtualCredentials",
|
|
3020
3135
|
driver.clearVirtualCredentials
|
|
3021
3136
|
)(authenticatorId)
|
|
3022
3137
|
)
|
|
3023
3138
|
),
|
|
3024
|
-
pinch: (selector, opts) => runStep("pinch", () =>
|
|
3139
|
+
pinch: (selector, opts) => runStep("pinch", () => run2(coord.pinch(selector, opts)), {
|
|
3025
3140
|
selector,
|
|
3026
3141
|
captureScreenshot: true
|
|
3027
3142
|
}),
|
|
3028
|
-
zoom: (selector, opts) => runStep("zoom", () =>
|
|
3143
|
+
zoom: (selector, opts) => runStep("zoom", () => run2(coord.zoom(selector, opts)), {
|
|
3029
3144
|
selector,
|
|
3030
3145
|
captureScreenshot: true
|
|
3031
3146
|
}),
|
|
3032
|
-
multiTouch: (sequences) => runStep("multiTouch", () =>
|
|
3033
|
-
getText: (selector, opts) => runStep("getText", () =>
|
|
3034
|
-
getAttribute: (selector, name, opts) => runStep(`getAttribute(${name})`, () =>
|
|
3147
|
+
multiTouch: (sequences) => runStep("multiTouch", () => run2(coord.multiTouch(sequences)), { captureScreenshot: true }),
|
|
3148
|
+
getText: (selector, opts) => runStep("getText", () => run2(coord.getText(selector, opts)), { selector }),
|
|
3149
|
+
getAttribute: (selector, name, opts) => runStep(`getAttribute(${name})`, () => run2(coord.getAttribute(selector, name, opts)), {
|
|
3035
3150
|
selector
|
|
3036
3151
|
}),
|
|
3037
3152
|
isVisible: (selector, opts) => {
|
|
3038
3153
|
const timeout = opts?.timeout ?? 1e3;
|
|
3039
|
-
return
|
|
3154
|
+
return run2(
|
|
3040
3155
|
Effect6.gen(function* () {
|
|
3041
3156
|
const result = yield* Effect6.either(
|
|
3042
3157
|
waitForElement(
|
|
@@ -3051,8 +3166,8 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
3051
3166
|
})
|
|
3052
3167
|
);
|
|
3053
3168
|
},
|
|
3054
|
-
isEnabled: (selector, opts) => runStep("isEnabled", () =>
|
|
3055
|
-
count: (selector, opts) => runStep("count", () =>
|
|
3169
|
+
isEnabled: (selector, opts) => runStep("isEnabled", () => run2(coord.isElementEnabled(selector, opts)), { selector }),
|
|
3170
|
+
count: (selector, opts) => runStep("count", () => run2(coord.count(selector, opts)), { selector }),
|
|
3056
3171
|
// Web-first bridge & fast state helpers
|
|
3057
3172
|
waitForIdle: (opts) => runStep("waitForIdle", async () => {
|
|
3058
3173
|
if (driver.domChannel?.waitForIdle) {
|
|
@@ -3065,7 +3180,7 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
3065
3180
|
return;
|
|
3066
3181
|
}
|
|
3067
3182
|
const serialized = JSON.stringify(entries);
|
|
3068
|
-
await
|
|
3183
|
+
await run2(
|
|
3069
3184
|
driver.evaluate(
|
|
3070
3185
|
`((payload) => {
|
|
3071
3186
|
if (payload.localStorage) {
|
|
@@ -3095,7 +3210,7 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
3095
3210
|
return;
|
|
3096
3211
|
}
|
|
3097
3212
|
const serialized = JSON.stringify(opts ?? {});
|
|
3098
|
-
await
|
|
3213
|
+
await run2(
|
|
3099
3214
|
driver.evaluate(
|
|
3100
3215
|
`((clearOpts) => {
|
|
3101
3216
|
if (clearOpts.localStorage !== false) {
|
|
@@ -3110,7 +3225,7 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
3110
3225
|
}),
|
|
3111
3226
|
resetFast: () => runStep("resetFast", async () => {
|
|
3112
3227
|
if (driver.resetFast) {
|
|
3113
|
-
await
|
|
3228
|
+
await run2(driver.resetFast());
|
|
3114
3229
|
return;
|
|
3115
3230
|
}
|
|
3116
3231
|
if (driver.domChannel?.clearStorage) {
|
|
@@ -3126,23 +3241,23 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
3126
3241
|
}
|
|
3127
3242
|
return;
|
|
3128
3243
|
}
|
|
3129
|
-
await
|
|
3244
|
+
await run2(driver.clearAppState(appId));
|
|
3130
3245
|
}),
|
|
3131
3246
|
// WebView / hybrid context switching (low-level escape hatches)
|
|
3132
3247
|
getContexts: () => runStep(
|
|
3133
3248
|
"getContexts",
|
|
3134
|
-
() =>
|
|
3249
|
+
() => run2((driver.getContexts ?? (() => Effect6.succeed(["NATIVE_APP"])))())
|
|
3135
3250
|
),
|
|
3136
3251
|
getCurrentContext: () => runStep(
|
|
3137
3252
|
"getCurrentContext",
|
|
3138
|
-
() =>
|
|
3253
|
+
() => run2((driver.getCurrentContext ?? (() => Effect6.succeed("NATIVE_APP")))())
|
|
3139
3254
|
),
|
|
3140
3255
|
switchToContext: (contextId) => runStep(
|
|
3141
3256
|
`switchToContext(${contextId})`,
|
|
3142
|
-
() =>
|
|
3257
|
+
() => run2((driver.setContext ?? ((_id) => Effect6.void))(contextId))
|
|
3143
3258
|
),
|
|
3144
3259
|
switchToWebView: () => runStep("switchToWebView", async () => {
|
|
3145
|
-
const contexts = await
|
|
3260
|
+
const contexts = await run2(
|
|
3146
3261
|
(driver.getContexts ?? (() => Effect6.succeed(["NATIVE_APP"])))()
|
|
3147
3262
|
);
|
|
3148
3263
|
const webview = contexts.find((c) => c.startsWith("WEBVIEW_"));
|
|
@@ -3151,11 +3266,11 @@ function createPromiseApp(driver, appId, config, recorder, options = {}) {
|
|
|
3151
3266
|
message: `No WebView context found. Available contexts: ${contexts.join(", ")}`
|
|
3152
3267
|
});
|
|
3153
3268
|
}
|
|
3154
|
-
await
|
|
3269
|
+
await run2((driver.setContext ?? ((_id) => Effect6.void))(webview));
|
|
3155
3270
|
}),
|
|
3156
3271
|
switchToNativeApp: () => runStep(
|
|
3157
3272
|
"switchToNativeApp",
|
|
3158
|
-
() =>
|
|
3273
|
+
() => run2((driver.setContext ?? ((_id) => Effect6.void))("NATIVE_APP"))
|
|
3159
3274
|
)
|
|
3160
3275
|
};
|
|
3161
3276
|
return appObj;
|
|
@@ -3198,16 +3313,108 @@ var RawDriver = class extends Context.Tag("RawDriver")() {
|
|
|
3198
3313
|
import { spawn } from "child_process";
|
|
3199
3314
|
import { createHash } from "crypto";
|
|
3200
3315
|
import { mkdtempSync, rmSync } from "fs";
|
|
3201
|
-
import { readFile, writeFile } from "fs/promises";
|
|
3316
|
+
import { readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
3202
3317
|
import { tmpdir } from "os";
|
|
3203
3318
|
import { join } from "path";
|
|
3204
|
-
import { Effect as
|
|
3319
|
+
import { Effect as Effect9, Layer } from "effect";
|
|
3205
3320
|
import {
|
|
3206
3321
|
chromium,
|
|
3207
3322
|
firefox,
|
|
3208
3323
|
webkit
|
|
3209
3324
|
} from "playwright-core";
|
|
3210
3325
|
|
|
3326
|
+
// src/drivers/device-controls.ts
|
|
3327
|
+
import { execFileSync } from "child_process";
|
|
3328
|
+
import { Effect as Effect8 } from "effect";
|
|
3329
|
+
function deviceEffect(operation, action) {
|
|
3330
|
+
return Effect8.tryPromise({
|
|
3331
|
+
try: async () => action(),
|
|
3332
|
+
catch: (error) => new DriverError({
|
|
3333
|
+
message: `${operation} failed: ${error instanceof Error ? error.message : String(error)}`
|
|
3334
|
+
})
|
|
3335
|
+
});
|
|
3336
|
+
}
|
|
3337
|
+
var run = (file, args, input) => execFileSync(file, args, { encoding: "utf8", input, timeout: 15e3 });
|
|
3338
|
+
function androidIdentifier(name) {
|
|
3339
|
+
if (!/^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*)+$/.test(name)) {
|
|
3340
|
+
throw new Error(`Invalid Android package or permission: ${name}`);
|
|
3341
|
+
}
|
|
3342
|
+
return name;
|
|
3343
|
+
}
|
|
3344
|
+
function androidDeviceControls(serial, command = run, adbPath = findADB) {
|
|
3345
|
+
const adb = (...args) => {
|
|
3346
|
+
const file = adbPath();
|
|
3347
|
+
if (!file) throw new Error("adb not found");
|
|
3348
|
+
return command(file, ["-s", serial, ...args]);
|
|
3349
|
+
};
|
|
3350
|
+
const emulator = (operation, ...args) => {
|
|
3351
|
+
if (!serial.startsWith("emulator-")) {
|
|
3352
|
+
throw new Error(`${operation} is not supported on physical Android devices`);
|
|
3353
|
+
}
|
|
3354
|
+
const result = adb("emu", ...args);
|
|
3355
|
+
if (/^KO:/m.test(result)) throw new Error(result.trim());
|
|
3356
|
+
};
|
|
3357
|
+
return {
|
|
3358
|
+
setGeolocation: (point) => deviceEffect(
|
|
3359
|
+
"setGeolocation",
|
|
3360
|
+
() => emulator(
|
|
3361
|
+
"Geolocation emulation",
|
|
3362
|
+
"geo",
|
|
3363
|
+
"fix",
|
|
3364
|
+
String(point.longitude),
|
|
3365
|
+
String(point.latitude)
|
|
3366
|
+
)
|
|
3367
|
+
),
|
|
3368
|
+
setPermission: (appId, permission, state) => deviceEffect("setPermission", () => {
|
|
3369
|
+
adb(
|
|
3370
|
+
"shell",
|
|
3371
|
+
"pm",
|
|
3372
|
+
state === "grant" ? "grant" : "revoke",
|
|
3373
|
+
androidIdentifier(appId),
|
|
3374
|
+
androidIdentifier(permission)
|
|
3375
|
+
);
|
|
3376
|
+
}),
|
|
3377
|
+
simulateBiometric: (opts) => deviceEffect("simulateBiometric", () => {
|
|
3378
|
+
if (opts.type !== "fingerprint")
|
|
3379
|
+
throw new Error("Only fingerprint simulation is supported on Android");
|
|
3380
|
+
if (!Number.isInteger(opts.fingerId) || opts.fingerId < 1)
|
|
3381
|
+
throw new Error("fingerId must be a positive integer");
|
|
3382
|
+
emulator("Fingerprint simulation", "finger", "touch", String(opts.fingerId));
|
|
3383
|
+
})
|
|
3384
|
+
};
|
|
3385
|
+
}
|
|
3386
|
+
function iosSimulatorControls(udid, command = run) {
|
|
3387
|
+
const simctl = (subcommand, args, input) => {
|
|
3388
|
+
if (!udid) throw new Error(`${subcommand} is not supported on physical iOS devices`);
|
|
3389
|
+
return command("xcrun", ["simctl", subcommand, udid, ...args], input);
|
|
3390
|
+
};
|
|
3391
|
+
const notify = (args) => simctl("spawn", ["notifyutil", ...args]);
|
|
3392
|
+
return {
|
|
3393
|
+
setGeolocation: (point) => deviceEffect("setGeolocation", () => {
|
|
3394
|
+
simctl("location", ["set", `${point.latitude.toFixed(7)},${point.longitude.toFixed(7)}`]);
|
|
3395
|
+
}),
|
|
3396
|
+
setPermission: (appId, permission, state) => deviceEffect("setPermission", () => {
|
|
3397
|
+
simctl("privacy", [state === "grant" ? "grant" : "revoke", permission, appId]);
|
|
3398
|
+
}),
|
|
3399
|
+
setBiometricEnrollment: (enabled) => deviceEffect("setBiometricEnrollment", () => {
|
|
3400
|
+
const event = "com.apple.BiometricKit.enrollmentChanged";
|
|
3401
|
+
notify(["-s", event, enabled ? "1" : "0"]);
|
|
3402
|
+
notify(["-p", event]);
|
|
3403
|
+
}),
|
|
3404
|
+
simulateBiometric: (opts) => deviceEffect("simulateBiometric", () => {
|
|
3405
|
+
if (opts.type === "fingerprint") throw new Error("Use touchId or faceId on iOS");
|
|
3406
|
+
const sensor = opts.type === "faceId" ? "pearl" : "fingerTouch";
|
|
3407
|
+
notify([
|
|
3408
|
+
"-p",
|
|
3409
|
+
`com.apple.BiometricKit_Sim.${sensor}.${opts.match === false ? "nomatch" : "match"}`
|
|
3410
|
+
]);
|
|
3411
|
+
}),
|
|
3412
|
+
sendPushNotification: (appId, payload) => deviceEffect("sendPushNotification", () => {
|
|
3413
|
+
simctl("push", [appId, "-"], JSON.stringify(payload));
|
|
3414
|
+
})
|
|
3415
|
+
};
|
|
3416
|
+
}
|
|
3417
|
+
|
|
3211
3418
|
// src/drivers/network-profiles.ts
|
|
3212
3419
|
var PROFILES = {
|
|
3213
3420
|
wifi: {
|
|
@@ -3511,23 +3718,23 @@ function resolvePlaywrightLocator(root, selector) {
|
|
|
3511
3718
|
return locator;
|
|
3512
3719
|
}
|
|
3513
3720
|
function makePlaywrightDriver(config) {
|
|
3514
|
-
return
|
|
3721
|
+
return Effect9.gen(function* () {
|
|
3515
3722
|
const browserName = config.browser ?? "chromium";
|
|
3516
3723
|
const ownsBrowser = !config.sharedBrowser && !config.cdpEndpoint && !config.wsEndpoint && !config.warmBrowser;
|
|
3517
|
-
const browser = config.sharedBrowser ? config.sharedBrowser : config.wsEndpoint ? yield*
|
|
3724
|
+
const browser = config.sharedBrowser ? config.sharedBrowser : config.wsEndpoint ? yield* Effect9.tryPromise({
|
|
3518
3725
|
try: () => browserLaunchers[browserName].connect(config.wsEndpoint),
|
|
3519
3726
|
catch: (e) => new DriverError({
|
|
3520
3727
|
message: `Failed to connect to remote Playwright server (${config.wsEndpoint}): ${e}`
|
|
3521
3728
|
})
|
|
3522
|
-
}) : config.cdpEndpoint ? yield*
|
|
3729
|
+
}) : config.cdpEndpoint ? yield* Effect9.tryPromise({
|
|
3523
3730
|
try: () => chromium.connectOverCDP(config.cdpEndpoint),
|
|
3524
3731
|
catch: (e) => new DriverError({
|
|
3525
3732
|
message: `Failed to connect to browser over CDP (${config.cdpEndpoint}): ${e}`
|
|
3526
3733
|
})
|
|
3527
|
-
}) : config.warmBrowser && browserName === "chromium" ? yield*
|
|
3734
|
+
}) : config.warmBrowser && browserName === "chromium" ? yield* Effect9.tryPromise({
|
|
3528
3735
|
try: async () => (await ensureWarmBrowserDaemon(config)).browser,
|
|
3529
3736
|
catch: (e) => new DriverError({ message: `Failed to connect to warm Chromium daemon: ${e}` })
|
|
3530
|
-
}) : yield*
|
|
3737
|
+
}) : yield* Effect9.tryPromise({
|
|
3531
3738
|
try: () => browserLaunchers[browserName].launch({
|
|
3532
3739
|
headless: config.headless ?? true,
|
|
3533
3740
|
...config.channel ? { channel: config.channel } : {},
|
|
@@ -4004,7 +4211,7 @@ function makePlaywrightDriver(config) {
|
|
|
4004
4211
|
updateHarPage(page);
|
|
4005
4212
|
debugLog("beginFlow", flowName);
|
|
4006
4213
|
};
|
|
4007
|
-
yield*
|
|
4214
|
+
yield* Effect9.tryPromise({
|
|
4008
4215
|
try: () => createContextAndPage(config.storageState),
|
|
4009
4216
|
catch: (e) => new DriverError({ message: `Failed to create page: ${e}` })
|
|
4010
4217
|
});
|
|
@@ -4045,13 +4252,14 @@ function makePlaywrightDriver(config) {
|
|
|
4045
4252
|
return Boolean(res);
|
|
4046
4253
|
}
|
|
4047
4254
|
};
|
|
4255
|
+
let coveragePage;
|
|
4048
4256
|
const service = {
|
|
4049
4257
|
...domChannel ? { domChannel } : {},
|
|
4050
|
-
beginFlow: (flowName) =>
|
|
4258
|
+
beginFlow: (flowName) => Effect9.tryPromise({
|
|
4051
4259
|
try: () => beginFlow(flowName),
|
|
4052
4260
|
catch: (e) => new DriverError({ message: `Failed to prepare flow ${flowName}: ${e}` })
|
|
4053
4261
|
}),
|
|
4054
|
-
dumpHierarchy: () =>
|
|
4262
|
+
dumpHierarchy: () => Effect9.tryPromise({
|
|
4055
4263
|
try: async () => {
|
|
4056
4264
|
const tree = await page.evaluate(`
|
|
4057
4265
|
(function() {
|
|
@@ -4086,17 +4294,17 @@ function makePlaywrightDriver(config) {
|
|
|
4086
4294
|
},
|
|
4087
4295
|
catch: (e) => new DriverError({ message: `Failed to dump hierarchy: ${e}` })
|
|
4088
4296
|
}),
|
|
4089
|
-
tapAtCoordinate: (x, y) =>
|
|
4297
|
+
tapAtCoordinate: (x, y) => Effect9.tryPromise({
|
|
4090
4298
|
try: async () => {
|
|
4091
4299
|
await page.mouse.click(x, y);
|
|
4092
4300
|
},
|
|
4093
4301
|
catch: (e) => new DriverError({ message: `Failed to tap at (${x}, ${y}): ${e}` })
|
|
4094
4302
|
}),
|
|
4095
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
4303
|
+
doubleTapAtCoordinate: (x, y) => Effect9.tryPromise({
|
|
4096
4304
|
try: () => page.mouse.dblclick(x, y),
|
|
4097
4305
|
catch: (e) => new DriverError({ message: `Failed to double tap at (${x}, ${y}): ${e}` })
|
|
4098
4306
|
}),
|
|
4099
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
4307
|
+
longPressAtCoordinate: (x, y, duration) => Effect9.tryPromise({
|
|
4100
4308
|
try: async () => {
|
|
4101
4309
|
await page.mouse.move(x, y);
|
|
4102
4310
|
await page.mouse.down();
|
|
@@ -4105,7 +4313,7 @@ function makePlaywrightDriver(config) {
|
|
|
4105
4313
|
},
|
|
4106
4314
|
catch: (e) => new DriverError({ message: `Failed to long press at (${x}, ${y}): ${e}` })
|
|
4107
4315
|
}),
|
|
4108
|
-
swipe: (startX, startY, endX, endY, duration) =>
|
|
4316
|
+
swipe: (startX, startY, endX, endY, duration) => Effect9.tryPromise({
|
|
4109
4317
|
try: async () => {
|
|
4110
4318
|
await page.evaluate(`
|
|
4111
4319
|
(function() {
|
|
@@ -4142,23 +4350,23 @@ function makePlaywrightDriver(config) {
|
|
|
4142
4350
|
},
|
|
4143
4351
|
catch: (e) => new DriverError({ message: `Failed to swipe: ${e}` })
|
|
4144
4352
|
}),
|
|
4145
|
-
inputText: (text) =>
|
|
4353
|
+
inputText: (text) => Effect9.tryPromise({
|
|
4146
4354
|
try: () => page.keyboard.insertText(text),
|
|
4147
4355
|
catch: (e) => new DriverError({ message: `Failed to input text: ${e}` })
|
|
4148
4356
|
}),
|
|
4149
|
-
pressKey: (key) =>
|
|
4357
|
+
pressKey: (key) => Effect9.tryPromise({
|
|
4150
4358
|
try: () => page.keyboard.press(key),
|
|
4151
4359
|
catch: (e) => new DriverError({ message: `Failed to press key ${key}: ${e}` })
|
|
4152
4360
|
}),
|
|
4153
|
-
hideKeyboard: () =>
|
|
4154
|
-
takeScreenshot: () =>
|
|
4361
|
+
hideKeyboard: () => Effect9.void,
|
|
4362
|
+
takeScreenshot: () => Effect9.tryPromise({
|
|
4155
4363
|
try: async () => {
|
|
4156
4364
|
const buffer = await page.screenshot();
|
|
4157
4365
|
return new Uint8Array(buffer);
|
|
4158
4366
|
},
|
|
4159
4367
|
catch: (e) => new DriverError({ message: `Failed to take screenshot: ${e}` })
|
|
4160
4368
|
}),
|
|
4161
|
-
getDeviceInfo: () =>
|
|
4369
|
+
getDeviceInfo: () => Effect9.tryPromise({
|
|
4162
4370
|
try: async () => {
|
|
4163
4371
|
const viewport = page.viewportSize() ?? { width: 1280, height: 720 };
|
|
4164
4372
|
return {
|
|
@@ -4173,7 +4381,7 @@ function makePlaywrightDriver(config) {
|
|
|
4173
4381
|
},
|
|
4174
4382
|
catch: (e) => new DriverError({ message: `Failed to get device info: ${e}` })
|
|
4175
4383
|
}),
|
|
4176
|
-
launchApp: (url, opts) =>
|
|
4384
|
+
launchApp: (url, opts) => Effect9.tryPromise({
|
|
4177
4385
|
try: async () => {
|
|
4178
4386
|
const targetUrl = opts?.deepLink || url || config.baseUrl || "about:blank";
|
|
4179
4387
|
if (opts?.clearState) {
|
|
@@ -4194,7 +4402,7 @@ function makePlaywrightDriver(config) {
|
|
|
4194
4402
|
},
|
|
4195
4403
|
catch: (e) => new DriverError({ message: `Failed to navigate to ${url}: ${e}` })
|
|
4196
4404
|
}),
|
|
4197
|
-
stopApp: (_id) =>
|
|
4405
|
+
stopApp: (_id) => Effect9.tryPromise({
|
|
4198
4406
|
try: async () => {
|
|
4199
4407
|
await page.goto("about:blank");
|
|
4200
4408
|
updateHarPage(page);
|
|
@@ -4202,7 +4410,7 @@ function makePlaywrightDriver(config) {
|
|
|
4202
4410
|
},
|
|
4203
4411
|
catch: (e) => new DriverError({ message: `Failed to stop app: ${e}` })
|
|
4204
4412
|
}),
|
|
4205
|
-
killApp: (_id) =>
|
|
4413
|
+
killApp: (_id) => Effect9.tryPromise({
|
|
4206
4414
|
try: async () => {
|
|
4207
4415
|
const prefetched = prefetchedSlotPromise;
|
|
4208
4416
|
prefetchedSlotPromise = void 0;
|
|
@@ -4225,14 +4433,14 @@ function makePlaywrightDriver(config) {
|
|
|
4225
4433
|
},
|
|
4226
4434
|
catch: (e) => new DriverError({ message: `Failed to kill app: ${e}` })
|
|
4227
4435
|
}),
|
|
4228
|
-
clearAppState: (_id) =>
|
|
4436
|
+
clearAppState: (_id) => Effect9.tryPromise({
|
|
4229
4437
|
try: async () => {
|
|
4230
4438
|
await clearStorage();
|
|
4231
4439
|
debugLog("clearAppState");
|
|
4232
4440
|
},
|
|
4233
4441
|
catch: (e) => new DriverError({ message: `Failed to clear app state: ${e}` })
|
|
4234
4442
|
}),
|
|
4235
|
-
openLink: (url) =>
|
|
4443
|
+
openLink: (url) => Effect9.tryPromise({
|
|
4236
4444
|
try: async () => {
|
|
4237
4445
|
await page.goto(url, config.waitUntil ? { waitUntil: config.waitUntil } : void 0);
|
|
4238
4446
|
updateHarPage(page);
|
|
@@ -4241,7 +4449,7 @@ function makePlaywrightDriver(config) {
|
|
|
4241
4449
|
},
|
|
4242
4450
|
catch: (e) => new DriverError({ message: `Failed to open link ${url}: ${e}` })
|
|
4243
4451
|
}),
|
|
4244
|
-
back: () =>
|
|
4452
|
+
back: () => Effect9.tryPromise({
|
|
4245
4453
|
try: async () => {
|
|
4246
4454
|
await page.goBack();
|
|
4247
4455
|
updateHarPage(page);
|
|
@@ -4249,7 +4457,7 @@ function makePlaywrightDriver(config) {
|
|
|
4249
4457
|
},
|
|
4250
4458
|
catch: (e) => new DriverError({ message: `Failed to go back: ${e}` })
|
|
4251
4459
|
}),
|
|
4252
|
-
reload: (reloadOpts) =>
|
|
4460
|
+
reload: (reloadOpts) => Effect9.tryPromise({
|
|
4253
4461
|
try: async () => {
|
|
4254
4462
|
const waitUntil = reloadOpts?.waitUntil ?? config.waitUntil;
|
|
4255
4463
|
await page.reload(waitUntil ? { waitUntil } : void 0);
|
|
@@ -4258,18 +4466,73 @@ function makePlaywrightDriver(config) {
|
|
|
4258
4466
|
},
|
|
4259
4467
|
catch: (e) => new DriverError({ message: `Failed to reload page: ${e}` })
|
|
4260
4468
|
}),
|
|
4261
|
-
hoverAtCoordinate: (x, y) =>
|
|
4469
|
+
hoverAtCoordinate: (x, y) => Effect9.tryPromise({
|
|
4262
4470
|
try: async () => {
|
|
4263
4471
|
await page.mouse.move(x, y);
|
|
4264
4472
|
},
|
|
4265
4473
|
catch: (e) => new DriverError({ message: `Failed to hover at (${x}, ${y}): ${e}` })
|
|
4266
4474
|
}),
|
|
4267
|
-
getUrl: () =>
|
|
4268
|
-
evaluate: (script, ...args) =>
|
|
4475
|
+
getUrl: () => Effect9.sync(() => currentPageUrl(page)),
|
|
4476
|
+
evaluate: (script, ...args) => Effect9.tryPromise({
|
|
4269
4477
|
try: () => evaluateOnPage(page, script, args),
|
|
4270
4478
|
catch: (e) => new DriverError({ message: `Evaluate failed: ${e}` })
|
|
4271
4479
|
}),
|
|
4272
4480
|
getRawPage: () => page,
|
|
4481
|
+
getAriaSnapshot: (selector, timeout) => deviceEffect("getAriaSnapshot", () => {
|
|
4482
|
+
if (typeof selector === "string") {
|
|
4483
|
+
return page.getByLabel(selector, { exact: true }).or(page.getByText(selector, { exact: true })).ariaSnapshot({ timeout });
|
|
4484
|
+
}
|
|
4485
|
+
if ("point" in selector) throw new Error("ARIA snapshots require a locator, not a point");
|
|
4486
|
+
return resolvePlaywrightLocator(
|
|
4487
|
+
page,
|
|
4488
|
+
"text" in selector ? { ...selector, css: `text=${JSON.stringify(selector.text)}` } : selector
|
|
4489
|
+
).ariaSnapshot({ timeout });
|
|
4490
|
+
}),
|
|
4491
|
+
...browserName === "chromium" ? {
|
|
4492
|
+
startJSCoverage: () => deviceEffect("startJSCoverage", async () => {
|
|
4493
|
+
const target = page;
|
|
4494
|
+
await target.coverage.startJSCoverage({ resetOnNavigation: false });
|
|
4495
|
+
coveragePage = target;
|
|
4496
|
+
}),
|
|
4497
|
+
stopJSCoverage: () => deviceEffect("stopJSCoverage", async () => {
|
|
4498
|
+
const target = coveragePage;
|
|
4499
|
+
coveragePage = void 0;
|
|
4500
|
+
if (!target) throw new Error("JavaScript coverage was not started");
|
|
4501
|
+
return target.coverage.stopJSCoverage();
|
|
4502
|
+
})
|
|
4503
|
+
} : {},
|
|
4504
|
+
setGeolocation: (point) => deviceEffect("setGeolocation", () => context.setGeolocation(point)),
|
|
4505
|
+
setSystemTime: (time) => deviceEffect("setSystemTime", () => page.clock.setSystemTime(time)),
|
|
4506
|
+
setPermission: (_appId, permission, state, options) => deviceEffect("setPermission", async () => {
|
|
4507
|
+
if (state === "grant") {
|
|
4508
|
+
await context.grantPermissions([permission], options);
|
|
4509
|
+
return;
|
|
4510
|
+
}
|
|
4511
|
+
if (browserName !== "chromium")
|
|
4512
|
+
throw new Error(`Permission denial is not supported on ${browserName} (web)`);
|
|
4513
|
+
const session = await ensureCdpSession();
|
|
4514
|
+
const {
|
|
4515
|
+
targetInfo: { browserContextId }
|
|
4516
|
+
} = await session.send("Target.getTargetInfo");
|
|
4517
|
+
if (!browserContextId)
|
|
4518
|
+
throw new Error("Could not resolve Chromium's browser context for permission denial");
|
|
4519
|
+
const name = permission === "midi-sysex" ? "midi" : permission;
|
|
4520
|
+
await session.send("Browser.setPermission", {
|
|
4521
|
+
permission: { name, ...permission === "midi-sysex" ? { sysex: true } : {} },
|
|
4522
|
+
setting: "denied",
|
|
4523
|
+
...options?.origin ? { origin: options.origin } : {},
|
|
4524
|
+
browserContextId
|
|
4525
|
+
});
|
|
4526
|
+
}),
|
|
4527
|
+
setOrientation: (orientation) => deviceEffect("setOrientation", async () => {
|
|
4528
|
+
const viewport = page.viewportSize() ?? await page.evaluate(
|
|
4529
|
+
"({ width: window.innerWidth, height: window.innerHeight })"
|
|
4530
|
+
);
|
|
4531
|
+
const { width, height } = viewport;
|
|
4532
|
+
if (orientation === "portrait" && width > height || orientation === "landscape" && height > width) {
|
|
4533
|
+
await page.setViewportSize({ width: height, height: width });
|
|
4534
|
+
}
|
|
4535
|
+
}),
|
|
4273
4536
|
getCdpSession: () => {
|
|
4274
4537
|
if (browserName !== "chromium") return void 0;
|
|
4275
4538
|
return {
|
|
@@ -4298,7 +4561,7 @@ function makePlaywrightDriver(config) {
|
|
|
4298
4561
|
}
|
|
4299
4562
|
};
|
|
4300
4563
|
},
|
|
4301
|
-
enableVirtualAuthenticator: (opts) =>
|
|
4564
|
+
enableVirtualAuthenticator: (opts) => Effect9.tryPromise({
|
|
4302
4565
|
try: async () => {
|
|
4303
4566
|
const attached = await attachVirtualAuthenticatorOn(context, page, opts);
|
|
4304
4567
|
activeAuthenticatorId = attached.authenticatorId;
|
|
@@ -4307,7 +4570,7 @@ function makePlaywrightDriver(config) {
|
|
|
4307
4570
|
},
|
|
4308
4571
|
catch: (e) => e instanceof DriverError ? e : new DriverError({ message: `Failed to enable virtual authenticator: ${e}` })
|
|
4309
4572
|
}),
|
|
4310
|
-
removeVirtualAuthenticator: (authenticatorId) =>
|
|
4573
|
+
removeVirtualAuthenticator: (authenticatorId) => Effect9.tryPromise({
|
|
4311
4574
|
try: async () => {
|
|
4312
4575
|
const id = authenticatorId ?? activeAuthenticatorId;
|
|
4313
4576
|
if (!id) return;
|
|
@@ -4318,7 +4581,7 @@ function makePlaywrightDriver(config) {
|
|
|
4318
4581
|
},
|
|
4319
4582
|
catch: (e) => new DriverError({ message: `Failed to remove virtual authenticator: ${e}` })
|
|
4320
4583
|
}),
|
|
4321
|
-
getVirtualCredentials: (authenticatorId) =>
|
|
4584
|
+
getVirtualCredentials: (authenticatorId) => Effect9.tryPromise({
|
|
4322
4585
|
try: async () => {
|
|
4323
4586
|
const id = authenticatorId ?? activeAuthenticatorId;
|
|
4324
4587
|
if (!id) return [];
|
|
@@ -4330,7 +4593,7 @@ function makePlaywrightDriver(config) {
|
|
|
4330
4593
|
},
|
|
4331
4594
|
catch: (e) => new DriverError({ message: `Failed to read virtual credentials: ${e}` })
|
|
4332
4595
|
}),
|
|
4333
|
-
addVirtualCredential: (credential, authenticatorId) =>
|
|
4596
|
+
addVirtualCredential: (credential, authenticatorId) => Effect9.tryPromise({
|
|
4334
4597
|
try: async () => {
|
|
4335
4598
|
if (browserName !== "chromium") {
|
|
4336
4599
|
throw new DriverError({
|
|
@@ -4360,7 +4623,7 @@ function makePlaywrightDriver(config) {
|
|
|
4360
4623
|
},
|
|
4361
4624
|
catch: (e) => e instanceof DriverError ? e : new DriverError({ message: `Failed to import virtual credential: ${e}` })
|
|
4362
4625
|
}),
|
|
4363
|
-
clearVirtualCredentials: (authenticatorId) =>
|
|
4626
|
+
clearVirtualCredentials: (authenticatorId) => Effect9.tryPromise({
|
|
4364
4627
|
try: async () => {
|
|
4365
4628
|
const id = authenticatorId ?? activeAuthenticatorId;
|
|
4366
4629
|
if (!id) return;
|
|
@@ -4370,7 +4633,7 @@ function makePlaywrightDriver(config) {
|
|
|
4370
4633
|
},
|
|
4371
4634
|
catch: (e) => new DriverError({ message: `Failed to clear virtual credentials: ${e}` })
|
|
4372
4635
|
}),
|
|
4373
|
-
mockNetwork: (matcher, response) =>
|
|
4636
|
+
mockNetwork: (matcher, response) => Effect9.tryPromise({
|
|
4374
4637
|
try: async () => {
|
|
4375
4638
|
buildMockResponse(response);
|
|
4376
4639
|
const definition = { kind: "mock", matcher, response };
|
|
@@ -4380,7 +4643,7 @@ function makePlaywrightDriver(config) {
|
|
|
4380
4643
|
},
|
|
4381
4644
|
catch: (e) => new DriverError({ message: `Failed to mock network route: ${e}` })
|
|
4382
4645
|
}),
|
|
4383
|
-
blockNetwork: (matcher) =>
|
|
4646
|
+
blockNetwork: (matcher) => Effect9.tryPromise({
|
|
4384
4647
|
try: async () => {
|
|
4385
4648
|
const definition = { kind: "block", matcher };
|
|
4386
4649
|
routeDefinitions.push(definition);
|
|
@@ -4389,7 +4652,7 @@ function makePlaywrightDriver(config) {
|
|
|
4389
4652
|
},
|
|
4390
4653
|
catch: (e) => new DriverError({ message: `Failed to block network route: ${e}` })
|
|
4391
4654
|
}),
|
|
4392
|
-
clearNetworkMocks: () =>
|
|
4655
|
+
clearNetworkMocks: () => Effect9.tryPromise({
|
|
4393
4656
|
try: async () => {
|
|
4394
4657
|
for (const appliedRoute of appliedRoutes) {
|
|
4395
4658
|
await context.unroute(appliedRoute.matcher, appliedRoute.handler);
|
|
@@ -4400,7 +4663,7 @@ function makePlaywrightDriver(config) {
|
|
|
4400
4663
|
},
|
|
4401
4664
|
catch: (e) => new DriverError({ message: `Failed to clear network mocks: ${e}` })
|
|
4402
4665
|
}),
|
|
4403
|
-
setNetworkConditions: (conditions) =>
|
|
4666
|
+
setNetworkConditions: (conditions) => Effect9.tryPromise({
|
|
4404
4667
|
try: async () => {
|
|
4405
4668
|
currentNetworkConditions = { ...conditions };
|
|
4406
4669
|
await applyNetworkConditions();
|
|
@@ -4408,17 +4671,17 @@ function makePlaywrightDriver(config) {
|
|
|
4408
4671
|
},
|
|
4409
4672
|
catch: (e) => new DriverError({ message: `Failed to set network conditions: ${e}` })
|
|
4410
4673
|
}),
|
|
4411
|
-
saveCookies: (path) =>
|
|
4674
|
+
saveCookies: (path) => Effect9.tryPromise({
|
|
4412
4675
|
try: async () => {
|
|
4413
4676
|
const cookies = await context.cookies();
|
|
4414
|
-
await
|
|
4677
|
+
await writeFile2(path, JSON.stringify(cookies, null, 2), "utf8");
|
|
4415
4678
|
debugLog("saveCookies", path);
|
|
4416
4679
|
},
|
|
4417
4680
|
catch: (e) => new DriverError({ message: `Failed to save cookies to ${path}: ${e}` })
|
|
4418
4681
|
}),
|
|
4419
|
-
loadCookies: (path) =>
|
|
4682
|
+
loadCookies: (path) => Effect9.tryPromise({
|
|
4420
4683
|
try: async () => {
|
|
4421
|
-
const contents = await
|
|
4684
|
+
const contents = await readFile2(path, "utf8");
|
|
4422
4685
|
const cookies = JSON.parse(contents);
|
|
4423
4686
|
if (!Array.isArray(cookies)) {
|
|
4424
4687
|
throw new Error("Cookie file must contain an array of cookies.");
|
|
@@ -4428,27 +4691,27 @@ function makePlaywrightDriver(config) {
|
|
|
4428
4691
|
},
|
|
4429
4692
|
catch: (e) => new DriverError({ message: `Failed to load cookies from ${path}: ${e}` })
|
|
4430
4693
|
}),
|
|
4431
|
-
getCookies: (urls) =>
|
|
4694
|
+
getCookies: (urls) => Effect9.tryPromise({
|
|
4432
4695
|
try: async () => {
|
|
4433
4696
|
const cookies = await (urls && urls.length > 0 ? context.cookies(urls) : context.cookies());
|
|
4434
4697
|
return cookies;
|
|
4435
4698
|
},
|
|
4436
4699
|
catch: (e) => new DriverError({ message: `Failed to read cookies: ${e}` })
|
|
4437
4700
|
}),
|
|
4438
|
-
setCookies: (cookies) =>
|
|
4701
|
+
setCookies: (cookies) => Effect9.tryPromise({
|
|
4439
4702
|
try: async () => {
|
|
4440
4703
|
if (cookies.length === 0) return;
|
|
4441
4704
|
await context.addCookies(cookies);
|
|
4442
4705
|
},
|
|
4443
4706
|
catch: (e) => new DriverError({ message: `Failed to set cookies: ${e}` })
|
|
4444
4707
|
}),
|
|
4445
|
-
clearCookies: () =>
|
|
4708
|
+
clearCookies: () => Effect9.tryPromise({
|
|
4446
4709
|
try: async () => {
|
|
4447
4710
|
await context.clearCookies();
|
|
4448
4711
|
},
|
|
4449
4712
|
catch: (e) => new DriverError({ message: `Failed to clear cookies: ${e}` })
|
|
4450
4713
|
}),
|
|
4451
|
-
waitForResponse: (matcher, waitOpts) =>
|
|
4714
|
+
waitForResponse: (matcher, waitOpts) => Effect9.tryPromise({
|
|
4452
4715
|
try: async () => {
|
|
4453
4716
|
const timeout = waitOpts?.timeout ?? 15e3;
|
|
4454
4717
|
const matches = (res) => {
|
|
@@ -4506,9 +4769,9 @@ function makePlaywrightDriver(config) {
|
|
|
4506
4769
|
},
|
|
4507
4770
|
catch: (e) => new DriverError({ message: `waitForResponse() failed: ${e}` })
|
|
4508
4771
|
}),
|
|
4509
|
-
createIsolatedContext: (ctxOpts) =>
|
|
4772
|
+
createIsolatedContext: (ctxOpts) => Effect9.tryPromise({
|
|
4510
4773
|
try: async () => {
|
|
4511
|
-
const childDriver = await
|
|
4774
|
+
const childDriver = await Effect9.runPromise(
|
|
4512
4775
|
makePlaywrightDriver({
|
|
4513
4776
|
...config,
|
|
4514
4777
|
sharedBrowser: browser,
|
|
@@ -4519,26 +4782,26 @@ function makePlaywrightDriver(config) {
|
|
|
4519
4782
|
})
|
|
4520
4783
|
);
|
|
4521
4784
|
if (ctxOpts?.url) {
|
|
4522
|
-
await
|
|
4785
|
+
await Effect9.runPromise(childDriver.openLink(ctxOpts.url));
|
|
4523
4786
|
}
|
|
4524
4787
|
return {
|
|
4525
4788
|
driver: childDriver,
|
|
4526
4789
|
close: async () => {
|
|
4527
|
-
await
|
|
4790
|
+
await Effect9.runPromise(childDriver.killApp("isolated-context")).catch(() => {
|
|
4528
4791
|
});
|
|
4529
4792
|
}
|
|
4530
4793
|
};
|
|
4531
4794
|
},
|
|
4532
4795
|
catch: (e) => new DriverError({ message: `createIsolatedContext() failed: ${e}` })
|
|
4533
4796
|
}),
|
|
4534
|
-
saveAuthState: (path) =>
|
|
4797
|
+
saveAuthState: (path) => Effect9.tryPromise({
|
|
4535
4798
|
try: async () => {
|
|
4536
4799
|
await context.storageState({ path });
|
|
4537
4800
|
debugLog("saveAuthState", path);
|
|
4538
4801
|
},
|
|
4539
4802
|
catch: (e) => new DriverError({ message: `Failed to save auth state to ${path}: ${e}` })
|
|
4540
4803
|
}),
|
|
4541
|
-
loadAuthState: (path) =>
|
|
4804
|
+
loadAuthState: (path) => Effect9.tryPromise({
|
|
4542
4805
|
try: async () => {
|
|
4543
4806
|
await replaceContext(path);
|
|
4544
4807
|
updateHarPage(page);
|
|
@@ -4546,7 +4809,7 @@ function makePlaywrightDriver(config) {
|
|
|
4546
4809
|
},
|
|
4547
4810
|
catch: (e) => new DriverError({ message: `Failed to load auth state from ${path}: ${e}` })
|
|
4548
4811
|
}),
|
|
4549
|
-
downloadFile: (path) =>
|
|
4812
|
+
downloadFile: (path) => Effect9.tryPromise({
|
|
4550
4813
|
try: async () => {
|
|
4551
4814
|
const download = await nextDownload();
|
|
4552
4815
|
await download.saveAs(path);
|
|
@@ -4554,7 +4817,7 @@ function makePlaywrightDriver(config) {
|
|
|
4554
4817
|
},
|
|
4555
4818
|
catch: (e) => new DriverError({ message: `Failed to download file to ${path}: ${e}` })
|
|
4556
4819
|
}),
|
|
4557
|
-
uploadFile: (selector, path) =>
|
|
4820
|
+
uploadFile: (selector, path) => Effect9.tryPromise({
|
|
4558
4821
|
try: async () => {
|
|
4559
4822
|
await setInputFiles(selector, path);
|
|
4560
4823
|
debugLog("uploadFile", Array.isArray(path) ? path.join(", ") : path);
|
|
@@ -4563,7 +4826,7 @@ function makePlaywrightDriver(config) {
|
|
|
4563
4826
|
message: `Failed to upload file ${Array.isArray(path) ? path.join(", ") : path}: ${e}`
|
|
4564
4827
|
})
|
|
4565
4828
|
}),
|
|
4566
|
-
newTab: (url) =>
|
|
4829
|
+
newTab: (url) => Effect9.tryPromise({
|
|
4567
4830
|
try: async () => {
|
|
4568
4831
|
const nextPage = await context.newPage();
|
|
4569
4832
|
attachPageDiagnostics(nextPage);
|
|
@@ -4578,7 +4841,7 @@ function makePlaywrightDriver(config) {
|
|
|
4578
4841
|
},
|
|
4579
4842
|
catch: (e) => new DriverError({ message: `Failed to open a new tab: ${e}` })
|
|
4580
4843
|
}),
|
|
4581
|
-
switchToTab: (index) =>
|
|
4844
|
+
switchToTab: (index) => Effect9.tryPromise({
|
|
4582
4845
|
try: async () => {
|
|
4583
4846
|
const openPages = context.pages();
|
|
4584
4847
|
const nextPage = openPages[index];
|
|
@@ -4594,7 +4857,7 @@ function makePlaywrightDriver(config) {
|
|
|
4594
4857
|
},
|
|
4595
4858
|
catch: (e) => new DriverError({ message: `Failed to switch tabs: ${e}` })
|
|
4596
4859
|
}),
|
|
4597
|
-
closeTab: () =>
|
|
4860
|
+
closeTab: () => Effect9.tryPromise({
|
|
4598
4861
|
try: async () => {
|
|
4599
4862
|
const openPages = context.pages();
|
|
4600
4863
|
if (openPages.length <= 1) {
|
|
@@ -4614,14 +4877,14 @@ function makePlaywrightDriver(config) {
|
|
|
4614
4877
|
},
|
|
4615
4878
|
catch: (e) => new DriverError({ message: `Failed to close the current tab: ${e}` })
|
|
4616
4879
|
}),
|
|
4617
|
-
getTabIds: () =>
|
|
4880
|
+
getTabIds: () => Effect9.sync(() => {
|
|
4618
4881
|
const ids = context.pages().map((openPage) => getTabId(openPage));
|
|
4619
4882
|
debugLog("getTabIds", ids.join(", "));
|
|
4620
4883
|
return ids;
|
|
4621
4884
|
}),
|
|
4622
|
-
getConsoleLogs: () =>
|
|
4623
|
-
getJSErrors: () =>
|
|
4624
|
-
getHAR: () =>
|
|
4885
|
+
getConsoleLogs: () => Effect9.succeed([...consoleLogs]),
|
|
4886
|
+
getJSErrors: () => Effect9.succeed([...jsErrors]),
|
|
4887
|
+
getHAR: () => Effect9.sync(() => ({
|
|
4625
4888
|
log: {
|
|
4626
4889
|
version: "1.2",
|
|
4627
4890
|
creator: {
|
|
@@ -4641,7 +4904,7 @@ function makePlaywrightDriver(config) {
|
|
|
4641
4904
|
}
|
|
4642
4905
|
|
|
4643
4906
|
// src/drivers/uiautomator2/driver.ts
|
|
4644
|
-
import { Effect as
|
|
4907
|
+
import { Effect as Effect10 } from "effect";
|
|
4645
4908
|
|
|
4646
4909
|
// src/drivers/uiautomator2/client.ts
|
|
4647
4910
|
var UiAutomator2Client = class {
|
|
@@ -4755,6 +5018,9 @@ var UiAutomator2Client = class {
|
|
|
4755
5018
|
}
|
|
4756
5019
|
}
|
|
4757
5020
|
}
|
|
5021
|
+
async setOrientation(orientation) {
|
|
5022
|
+
await this.request("POST", this.sessionPath("/orientation"), { orientation });
|
|
5023
|
+
}
|
|
4758
5024
|
// ---------------------------------------------------------------------------
|
|
4759
5025
|
// Gestures — Appium gesture extensions
|
|
4760
5026
|
// These match the endpoints used by maestro-runner's uiautomator2 client.
|
|
@@ -4985,7 +5251,7 @@ var UiAutomator2Client = class {
|
|
|
4985
5251
|
|
|
4986
5252
|
// src/drivers/uiautomator2/driver.ts
|
|
4987
5253
|
function createUiAutomator2Driver(host, port, serial, packageName, driverOptions) {
|
|
4988
|
-
return
|
|
5254
|
+
return Effect10.gen(function* () {
|
|
4989
5255
|
const client = new UiAutomator2Client(host, port);
|
|
4990
5256
|
let currentContext = "NATIVE_APP";
|
|
4991
5257
|
let hasLaunchedOnce = false;
|
|
@@ -5009,7 +5275,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5009
5275
|
if (driverOptions?.domChannel) channels.push(driverOptions.domChannel);
|
|
5010
5276
|
if (cdpChannel) channels.push(cdpChannel);
|
|
5011
5277
|
const domChannel = channels.length === 0 ? void 0 : channels.length === 1 ? channels[0] : createCompositeDomChannel(channels);
|
|
5012
|
-
yield*
|
|
5278
|
+
yield* Effect10.tryPromise({
|
|
5013
5279
|
try: () => client.createSession(packageName),
|
|
5014
5280
|
catch: (e) => new DriverError({
|
|
5015
5281
|
message: `Failed to create UiAutomator2 session: ${e}`
|
|
@@ -5017,73 +5283,78 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5017
5283
|
});
|
|
5018
5284
|
const service = {
|
|
5019
5285
|
domChannel,
|
|
5286
|
+
...androidDeviceControls(serial),
|
|
5287
|
+
setOrientation: (orientation) => deviceEffect(
|
|
5288
|
+
"setOrientation",
|
|
5289
|
+
() => client.setOrientation(orientation === "portrait" ? "PORTRAIT" : "LANDSCAPE")
|
|
5290
|
+
),
|
|
5020
5291
|
// -----------------------------------------------------------------------
|
|
5021
5292
|
// Hierarchy
|
|
5022
5293
|
// -----------------------------------------------------------------------
|
|
5023
|
-
dumpHierarchy: () =>
|
|
5294
|
+
dumpHierarchy: () => Effect10.tryPromise({
|
|
5024
5295
|
try: () => client.getSource(),
|
|
5025
5296
|
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
5026
5297
|
}),
|
|
5027
5298
|
// -----------------------------------------------------------------------
|
|
5028
5299
|
// Coordinate-level actions
|
|
5029
5300
|
// -----------------------------------------------------------------------
|
|
5030
|
-
tapAtCoordinate: (x, y) =>
|
|
5301
|
+
tapAtCoordinate: (x, y) => Effect10.tryPromise({
|
|
5031
5302
|
try: () => client.performTap(x, y),
|
|
5032
5303
|
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
5033
5304
|
}),
|
|
5034
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
5305
|
+
doubleTapAtCoordinate: (x, y) => Effect10.tryPromise({
|
|
5035
5306
|
try: async () => {
|
|
5036
5307
|
await client.performTap(x, y);
|
|
5037
5308
|
await client.performTap(x, y);
|
|
5038
5309
|
},
|
|
5039
5310
|
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
5040
5311
|
}),
|
|
5041
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
5312
|
+
longPressAtCoordinate: (x, y, duration) => Effect10.tryPromise({
|
|
5042
5313
|
try: () => client.performLongPress(x, y, duration),
|
|
5043
5314
|
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
5044
5315
|
}),
|
|
5045
|
-
swipe: (sx, sy, ex, ey, dur) =>
|
|
5316
|
+
swipe: (sx, sy, ex, ey, dur) => Effect10.tryPromise({
|
|
5046
5317
|
try: () => client.performSwipe(sx, sy, ex, ey, dur),
|
|
5047
5318
|
catch: (e) => new DriverError({ message: `Swipe failed: ${e}` })
|
|
5048
5319
|
}),
|
|
5049
|
-
pinch: (cx, cy, scale, duration) =>
|
|
5320
|
+
pinch: (cx, cy, scale, duration) => Effect10.tryPromise({
|
|
5050
5321
|
try: () => client.performPinch(cx, cy, scale, duration),
|
|
5051
5322
|
catch: (e) => new DriverError({ message: `Pinch failed: ${e}` })
|
|
5052
5323
|
}),
|
|
5053
|
-
zoom: (cx, cy, scale, duration) =>
|
|
5324
|
+
zoom: (cx, cy, scale, duration) => Effect10.tryPromise({
|
|
5054
5325
|
try: () => client.performZoom(cx, cy, scale, duration),
|
|
5055
5326
|
catch: (e) => new DriverError({ message: `Zoom failed: ${e}` })
|
|
5056
5327
|
}),
|
|
5057
|
-
multiTouch: (sequences) =>
|
|
5328
|
+
multiTouch: (sequences) => Effect10.tryPromise({
|
|
5058
5329
|
try: () => client.performMultiTouch(sequences),
|
|
5059
5330
|
catch: (e) => new DriverError({ message: `Multi-touch failed: ${e}` })
|
|
5060
5331
|
}),
|
|
5061
5332
|
// -----------------------------------------------------------------------
|
|
5062
5333
|
// Text input
|
|
5063
5334
|
// -----------------------------------------------------------------------
|
|
5064
|
-
inputText: (text) =>
|
|
5335
|
+
inputText: (text) => Effect10.tryPromise({
|
|
5065
5336
|
try: () => client.sendKeys(text),
|
|
5066
5337
|
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
5067
5338
|
}),
|
|
5068
|
-
pressKey: (key) =>
|
|
5339
|
+
pressKey: (key) => Effect10.tryPromise({
|
|
5069
5340
|
try: () => client.pressKeyCode(parseInt(key, 10) || 0),
|
|
5070
5341
|
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
5071
5342
|
}),
|
|
5072
|
-
hideKeyboard: () =>
|
|
5343
|
+
hideKeyboard: () => Effect10.tryPromise({
|
|
5073
5344
|
try: () => client.hideKeyboard(),
|
|
5074
5345
|
catch: (e) => new DriverError({ message: `Hide keyboard failed: ${e}` })
|
|
5075
5346
|
}),
|
|
5076
5347
|
// -----------------------------------------------------------------------
|
|
5077
5348
|
// Queries
|
|
5078
5349
|
// -----------------------------------------------------------------------
|
|
5079
|
-
takeScreenshot: () =>
|
|
5350
|
+
takeScreenshot: () => Effect10.tryPromise({
|
|
5080
5351
|
try: async () => {
|
|
5081
5352
|
const base64 = await client.getScreenshot();
|
|
5082
5353
|
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
5083
5354
|
},
|
|
5084
5355
|
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
5085
5356
|
}),
|
|
5086
|
-
getDeviceInfo: () =>
|
|
5357
|
+
getDeviceInfo: () => Effect10.tryPromise({
|
|
5087
5358
|
try: async () => {
|
|
5088
5359
|
const size = await client.getWindowSize();
|
|
5089
5360
|
return {
|
|
@@ -5101,7 +5372,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5101
5372
|
// -----------------------------------------------------------------------
|
|
5102
5373
|
// App lifecycle
|
|
5103
5374
|
// -----------------------------------------------------------------------
|
|
5104
|
-
launchApp: (bundleId, opts) =>
|
|
5375
|
+
launchApp: (bundleId, opts) => Effect10.tryPromise({
|
|
5105
5376
|
try: async () => {
|
|
5106
5377
|
const canFastReset = hasLaunchedOnce && driverOptions?.fastWebViewReset !== false && domChannel?.isConnected() && !opts?.deepLink && !opts?.clearKeychain && !hasLaunchDeviceState(opts?.deviceState) && !(opts?.launchArguments && Object.keys(opts.launchArguments).length > 0);
|
|
5107
5378
|
if (canFastReset) {
|
|
@@ -5141,7 +5412,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5141
5412
|
} else {
|
|
5142
5413
|
adbForceStop(serial, bundleId);
|
|
5143
5414
|
if (opts?.launchArguments && Object.keys(opts.launchArguments).length > 0) {
|
|
5144
|
-
const { execFileSync:
|
|
5415
|
+
const { execFileSync: execFileSync3 } = await import("child_process");
|
|
5145
5416
|
const { findADB: findADB2 } = await import("./android-6BOQTMM3.js");
|
|
5146
5417
|
const adb = findADB2();
|
|
5147
5418
|
if (!adb) throw new Error("adb not found");
|
|
@@ -5160,7 +5431,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5160
5431
|
for (const [k, v] of Object.entries(opts.launchArguments)) {
|
|
5161
5432
|
startArgs.push("--es", k, String(v));
|
|
5162
5433
|
}
|
|
5163
|
-
|
|
5434
|
+
execFileSync3(adb, startArgs, { stdio: "ignore" });
|
|
5164
5435
|
} else {
|
|
5165
5436
|
adbLaunchApp(serial, bundleId);
|
|
5166
5437
|
}
|
|
@@ -5170,13 +5441,13 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5170
5441
|
},
|
|
5171
5442
|
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
5172
5443
|
}),
|
|
5173
|
-
stopApp: (bundleId) =>
|
|
5444
|
+
stopApp: (bundleId) => Effect10.tryPromise({
|
|
5174
5445
|
try: async () => {
|
|
5175
5446
|
adbForceStop(serial, bundleId);
|
|
5176
5447
|
},
|
|
5177
5448
|
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
5178
5449
|
}),
|
|
5179
|
-
killApp: (bundleId) =>
|
|
5450
|
+
killApp: (bundleId) => Effect10.tryPromise({
|
|
5180
5451
|
try: async () => {
|
|
5181
5452
|
await domChannel?.disconnect().catch(() => {
|
|
5182
5453
|
});
|
|
@@ -5185,7 +5456,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5185
5456
|
},
|
|
5186
5457
|
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
5187
5458
|
}),
|
|
5188
|
-
clearAppState: (bundleId) =>
|
|
5459
|
+
clearAppState: (bundleId) => Effect10.tryPromise({
|
|
5189
5460
|
try: async () => {
|
|
5190
5461
|
if (domChannel?.isConnected() && domChannel.clearStorage) {
|
|
5191
5462
|
await domChannel.clearStorage({
|
|
@@ -5205,7 +5476,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5205
5476
|
},
|
|
5206
5477
|
catch: (e) => new DriverError({ message: `Clear app state failed: ${e}` })
|
|
5207
5478
|
}),
|
|
5208
|
-
resetFast: () =>
|
|
5479
|
+
resetFast: () => Effect10.tryPromise({
|
|
5209
5480
|
try: async () => {
|
|
5210
5481
|
if (!domChannel) {
|
|
5211
5482
|
throw new Error("resetFast() requires a connected DOM channel (spana-bridge or CDP)");
|
|
@@ -5235,14 +5506,14 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5235
5506
|
// -----------------------------------------------------------------------
|
|
5236
5507
|
// Navigation
|
|
5237
5508
|
// -----------------------------------------------------------------------
|
|
5238
|
-
openLink: (url) =>
|
|
5509
|
+
openLink: (url) => Effect10.tryPromise({
|
|
5239
5510
|
try: async () => {
|
|
5240
5511
|
adbOpenLink(serial, url, packageName);
|
|
5241
5512
|
await new Promise((resolve2) => setTimeout(resolve2, 1e3));
|
|
5242
5513
|
},
|
|
5243
5514
|
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
5244
5515
|
}),
|
|
5245
|
-
back: () =>
|
|
5516
|
+
back: () => Effect10.tryPromise({
|
|
5246
5517
|
// KEYCODE_BACK = 4
|
|
5247
5518
|
try: () => client.pressKeyCode(4),
|
|
5248
5519
|
catch: (e) => new DriverError({ message: `Back failed: ${e}` })
|
|
@@ -5251,7 +5522,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5251
5522
|
// Direct DOM evaluation via spana-bridge or Android WebView CDP,
|
|
5252
5523
|
// falling back to UiAutomator2 /execute/sync when no DOM channel attaches.
|
|
5253
5524
|
// -----------------------------------------------------------------------
|
|
5254
|
-
evaluate: (script, ...args) =>
|
|
5525
|
+
evaluate: (script, ...args) => Effect10.tryPromise({
|
|
5255
5526
|
try: async () => {
|
|
5256
5527
|
if (domChannel) {
|
|
5257
5528
|
try {
|
|
@@ -5277,7 +5548,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5277
5548
|
},
|
|
5278
5549
|
catch: (e) => new DriverError({ message: `evaluate() failed: ${e}` })
|
|
5279
5550
|
}),
|
|
5280
|
-
getContexts: () =>
|
|
5551
|
+
getContexts: () => Effect10.tryPromise({
|
|
5281
5552
|
try: async () => {
|
|
5282
5553
|
const contexts = /* @__PURE__ */ new Set(["NATIVE_APP"]);
|
|
5283
5554
|
if (domChannel?.listTargets) {
|
|
@@ -5300,7 +5571,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5300
5571
|
},
|
|
5301
5572
|
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
5302
5573
|
}),
|
|
5303
|
-
getCurrentContext: () =>
|
|
5574
|
+
getCurrentContext: () => Effect10.tryPromise({
|
|
5304
5575
|
try: async () => {
|
|
5305
5576
|
if (currentContext !== "NATIVE_APP") return currentContext;
|
|
5306
5577
|
if (typeof client.getCurrentContext === "function") {
|
|
@@ -5314,7 +5585,7 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5314
5585
|
},
|
|
5315
5586
|
catch: (e) => new DriverError({ message: `getCurrentContext failed: ${e}` })
|
|
5316
5587
|
}),
|
|
5317
|
-
setContext: (contextId) =>
|
|
5588
|
+
setContext: (contextId) => Effect10.tryPromise({
|
|
5318
5589
|
try: async () => {
|
|
5319
5590
|
if (contextId === "NATIVE_APP") {
|
|
5320
5591
|
currentContext = "NATIVE_APP";
|
|
@@ -5340,25 +5611,29 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5340
5611
|
},
|
|
5341
5612
|
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
5342
5613
|
}),
|
|
5343
|
-
mockNetwork: (matcher, response) =>
|
|
5614
|
+
mockNetwork: (matcher, response) => Effect10.tryPromise({
|
|
5344
5615
|
try: async () => {
|
|
5345
5616
|
if (!domChannel?.mockNetwork) {
|
|
5346
|
-
throw new Error(
|
|
5617
|
+
throw new Error(
|
|
5618
|
+
"mockNetwork() is not supported on native Android traffic; enable WebView debugging or install spana-bridge for WebView requests"
|
|
5619
|
+
);
|
|
5347
5620
|
}
|
|
5348
5621
|
await domChannel.mockNetwork(matcher, response);
|
|
5349
5622
|
},
|
|
5350
5623
|
catch: (e) => new DriverError({ message: `mockNetwork failed: ${e}` })
|
|
5351
5624
|
}),
|
|
5352
|
-
blockNetwork: (matcher) =>
|
|
5625
|
+
blockNetwork: (matcher) => Effect10.tryPromise({
|
|
5353
5626
|
try: async () => {
|
|
5354
5627
|
if (!domChannel?.blockNetwork) {
|
|
5355
|
-
throw new Error(
|
|
5628
|
+
throw new Error(
|
|
5629
|
+
"blockNetwork() is not supported on native Android traffic; enable WebView debugging or install spana-bridge for WebView requests"
|
|
5630
|
+
);
|
|
5356
5631
|
}
|
|
5357
5632
|
await domChannel.blockNetwork(matcher);
|
|
5358
5633
|
},
|
|
5359
5634
|
catch: (e) => new DriverError({ message: `blockNetwork failed: ${e}` })
|
|
5360
5635
|
}),
|
|
5361
|
-
clearNetworkMocks: () =>
|
|
5636
|
+
clearNetworkMocks: () => Effect10.tryPromise({
|
|
5362
5637
|
try: async () => {
|
|
5363
5638
|
if (domChannel?.clearNetworkMocks) {
|
|
5364
5639
|
await domChannel.clearNetworkMocks();
|
|
@@ -5366,18 +5641,18 @@ function createUiAutomator2Driver(host, port, serial, packageName, driverOptions
|
|
|
5366
5641
|
},
|
|
5367
5642
|
catch: (e) => new DriverError({ message: `clearNetworkMocks failed: ${e}` })
|
|
5368
5643
|
}),
|
|
5369
|
-
getConsoleLogs: () =>
|
|
5644
|
+
getConsoleLogs: () => Effect10.tryPromise({
|
|
5370
5645
|
try: async () => domChannel?.getConsoleLogs ? domChannel.getConsoleLogs() : [],
|
|
5371
5646
|
catch: (e) => new DriverError({ message: `getConsoleLogs failed: ${e}` })
|
|
5372
5647
|
}),
|
|
5373
|
-
getJSErrors: () =>
|
|
5648
|
+
getJSErrors: () => Effect10.tryPromise({
|
|
5374
5649
|
try: async () => domChannel?.getJSErrors ? domChannel.getJSErrors() : [],
|
|
5375
5650
|
catch: (e) => new DriverError({ message: `getJSErrors failed: ${e}` })
|
|
5376
5651
|
}),
|
|
5377
5652
|
// -----------------------------------------------------------------------
|
|
5378
5653
|
// Network conditions
|
|
5379
5654
|
// -----------------------------------------------------------------------
|
|
5380
|
-
setNetworkConditions: (conditions) =>
|
|
5655
|
+
setNetworkConditions: (conditions) => Effect10.tryPromise({
|
|
5381
5656
|
try: async () => {
|
|
5382
5657
|
const isEmulator = serial.startsWith("emulator-");
|
|
5383
5658
|
const resolved = resolveNetworkConditions(conditions);
|
|
@@ -5624,7 +5899,7 @@ function parseAndroidHierarchy(xml) {
|
|
|
5624
5899
|
}
|
|
5625
5900
|
|
|
5626
5901
|
// src/drivers/wda/driver.ts
|
|
5627
|
-
import { Effect as
|
|
5902
|
+
import { Effect as Effect11 } from "effect";
|
|
5628
5903
|
|
|
5629
5904
|
// src/drivers/wda/client.ts
|
|
5630
5905
|
var WDAClient = class {
|
|
@@ -5793,6 +6068,9 @@ var WDAClient = class {
|
|
|
5793
6068
|
);
|
|
5794
6069
|
return value;
|
|
5795
6070
|
}
|
|
6071
|
+
async setOrientation(orientation) {
|
|
6072
|
+
await this.request("POST", this.sessionPath("/orientation"), { orientation });
|
|
6073
|
+
}
|
|
5796
6074
|
// ---------------------------------------------------------------------------
|
|
5797
6075
|
// Touch actions — WDA-specific endpoints
|
|
5798
6076
|
// ---------------------------------------------------------------------------
|
|
@@ -6059,7 +6337,7 @@ function isSessionError(error) {
|
|
|
6059
6337
|
return msg.includes("session does not exist") || msg.includes("unable to connect") || msg.includes("no active session") || msg.includes("invalid session") || /status[:\s]*404/.test(msg);
|
|
6060
6338
|
}
|
|
6061
6339
|
function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth = 100, driverOptions) {
|
|
6062
|
-
return
|
|
6340
|
+
return Effect11.gen(function* () {
|
|
6063
6341
|
const client = new WDAClient(host, port);
|
|
6064
6342
|
let currentContext = "NATIVE_APP";
|
|
6065
6343
|
let hasLaunchedOnce = false;
|
|
@@ -6180,53 +6458,60 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6180
6458
|
let reusedWarmSession = false;
|
|
6181
6459
|
if (driverOptions?.warmSessionId && typeof client.attachSession === "function") {
|
|
6182
6460
|
client.attachSession(driverOptions.warmSessionId);
|
|
6183
|
-
const alive = yield*
|
|
6461
|
+
const alive = yield* Effect11.tryPromise({
|
|
6184
6462
|
try: () => client.isSessionAlive(),
|
|
6185
6463
|
catch: () => false
|
|
6186
|
-
}).pipe(
|
|
6464
|
+
}).pipe(Effect11.catchAll(() => Effect11.succeed(false)));
|
|
6187
6465
|
reusedWarmSession = alive;
|
|
6188
6466
|
}
|
|
6189
6467
|
if (!reusedWarmSession) {
|
|
6190
|
-
const createdId = yield*
|
|
6468
|
+
const createdId = yield* Effect11.tryPromise({
|
|
6191
6469
|
try: () => createSessionWithRetry(bundleId || void 0),
|
|
6192
6470
|
catch: (e) => new DriverError({ message: `Failed to create WDA session: ${e}` })
|
|
6193
6471
|
});
|
|
6194
6472
|
driverOptions?.onSessionCreated?.(createdId);
|
|
6195
|
-
yield*
|
|
6473
|
+
yield* Effect11.tryPromise({
|
|
6196
6474
|
try: () => client.disableQuiescence(),
|
|
6197
6475
|
catch: (e) => new DriverError({ message: `Failed to disable quiescence: ${e}` })
|
|
6198
6476
|
});
|
|
6199
|
-
yield*
|
|
6477
|
+
yield* Effect11.tryPromise({
|
|
6200
6478
|
try: () => client.setSnapshotMaxDepth(snapshotMaxDepth),
|
|
6201
6479
|
catch: (e) => new DriverError({ message: `Failed to set snapshot depth: ${e}` })
|
|
6202
6480
|
});
|
|
6203
6481
|
}
|
|
6204
6482
|
const service = {
|
|
6483
|
+
...iosSimulatorControls(simulatorUdid),
|
|
6484
|
+
setOrientation: (orientation) => deviceEffect(
|
|
6485
|
+
"setOrientation",
|
|
6486
|
+
() => withSessionRecovery(
|
|
6487
|
+
() => client.setOrientation(orientation === "portrait" ? "PORTRAIT" : "LANDSCAPE")
|
|
6488
|
+
)
|
|
6489
|
+
),
|
|
6205
6490
|
domChannel,
|
|
6206
6491
|
// -----------------------------------------------------------------------
|
|
6207
6492
|
// Hierarchy
|
|
6208
6493
|
// -----------------------------------------------------------------------
|
|
6209
|
-
dumpHierarchy: () =>
|
|
6494
|
+
dumpHierarchy: () => Effect11.tryPromise({
|
|
6210
6495
|
try: () => withSessionRecovery(() => client.getSource()),
|
|
6211
6496
|
catch: (e) => new DriverError({ message: `Failed to get page source: ${e}` })
|
|
6212
6497
|
}),
|
|
6213
6498
|
// -----------------------------------------------------------------------
|
|
6214
6499
|
// Coordinate-level actions
|
|
6215
6500
|
// -----------------------------------------------------------------------
|
|
6216
|
-
tapAtCoordinate: (x, y) =>
|
|
6501
|
+
tapAtCoordinate: (x, y) => Effect11.tryPromise({
|
|
6217
6502
|
try: () => withSessionRecovery(() => client.tap(x, y)),
|
|
6218
6503
|
catch: (e) => new DriverError({ message: `Tap failed: ${e}` })
|
|
6219
6504
|
}),
|
|
6220
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
6505
|
+
doubleTapAtCoordinate: (x, y) => Effect11.tryPromise({
|
|
6221
6506
|
try: () => withSessionRecovery(() => client.doubleTap(x, y)),
|
|
6222
6507
|
catch: (e) => new DriverError({ message: `Double tap failed: ${e}` })
|
|
6223
6508
|
}),
|
|
6224
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
6509
|
+
longPressAtCoordinate: (x, y, duration) => Effect11.tryPromise({
|
|
6225
6510
|
// duration arrives in ms (spana convention) → convert to seconds for WDA
|
|
6226
6511
|
try: () => withSessionRecovery(() => client.longPress(x, y, msToSec(duration))),
|
|
6227
6512
|
catch: (e) => new DriverError({ message: `Long press failed: ${e}` })
|
|
6228
6513
|
}),
|
|
6229
|
-
swipe: (sx, sy, ex, ey, dur) =>
|
|
6514
|
+
swipe: (sx, sy, ex, ey, dur) => Effect11.tryPromise({
|
|
6230
6515
|
// dur arrives in ms → convert to seconds for WDA.
|
|
6231
6516
|
// Clamp Y to avoid iOS system gesture zones (home indicator / App Switcher).
|
|
6232
6517
|
try: async () => {
|
|
@@ -6244,26 +6529,26 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6244
6529
|
},
|
|
6245
6530
|
catch: (e) => new DriverError({ message: `Swipe failed: ${e}` })
|
|
6246
6531
|
}),
|
|
6247
|
-
pinch: (cx, cy, scale, duration) =>
|
|
6532
|
+
pinch: (cx, cy, scale, duration) => Effect11.tryPromise({
|
|
6248
6533
|
try: () => withSessionRecovery(() => client.pinch(cx, cy, scale, msToSec(duration))),
|
|
6249
6534
|
catch: (e) => new DriverError({ message: `Pinch failed: ${e}` })
|
|
6250
6535
|
}),
|
|
6251
|
-
zoom: (cx, cy, scale, duration) =>
|
|
6536
|
+
zoom: (cx, cy, scale, duration) => Effect11.tryPromise({
|
|
6252
6537
|
try: () => withSessionRecovery(() => client.zoom(cx, cy, scale, msToSec(duration))),
|
|
6253
6538
|
catch: (e) => new DriverError({ message: `Zoom failed: ${e}` })
|
|
6254
6539
|
}),
|
|
6255
|
-
multiTouch: (sequences) =>
|
|
6540
|
+
multiTouch: (sequences) => Effect11.tryPromise({
|
|
6256
6541
|
try: () => withSessionRecovery(() => client.multiTouch(sequences)),
|
|
6257
6542
|
catch: (e) => new DriverError({ message: `Multi-touch failed: ${e}` })
|
|
6258
6543
|
}),
|
|
6259
6544
|
// -----------------------------------------------------------------------
|
|
6260
6545
|
// Text input
|
|
6261
6546
|
// -----------------------------------------------------------------------
|
|
6262
|
-
inputText: (text) =>
|
|
6547
|
+
inputText: (text) => Effect11.tryPromise({
|
|
6263
6548
|
try: () => withSessionRecovery(() => client.sendKeys(text)),
|
|
6264
6549
|
catch: (e) => new DriverError({ message: `Input text failed: ${e}` })
|
|
6265
6550
|
}),
|
|
6266
|
-
pressKey: (key) =>
|
|
6551
|
+
pressKey: (key) => Effect11.tryPromise({
|
|
6267
6552
|
// WDA uses named hardware buttons; map common names, fall back to home
|
|
6268
6553
|
try: async () => {
|
|
6269
6554
|
const buttonMap = {
|
|
@@ -6278,7 +6563,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6278
6563
|
},
|
|
6279
6564
|
catch: (e) => new DriverError({ message: `Press key failed: ${e}` })
|
|
6280
6565
|
}),
|
|
6281
|
-
hideKeyboard: () =>
|
|
6566
|
+
hideKeyboard: () => Effect11.tryPromise({
|
|
6282
6567
|
// Dismiss keyboard by tapping above the keyboard area.
|
|
6283
6568
|
// The previous approach (pressHome) backgrounds the app on iOS.
|
|
6284
6569
|
try: async () => {
|
|
@@ -6291,11 +6576,11 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6291
6576
|
// -----------------------------------------------------------------------
|
|
6292
6577
|
// Queries
|
|
6293
6578
|
// -----------------------------------------------------------------------
|
|
6294
|
-
takeScreenshot: () =>
|
|
6579
|
+
takeScreenshot: () => Effect11.tryPromise({
|
|
6295
6580
|
try: () => withSessionRecovery(() => client.getScreenshot()),
|
|
6296
6581
|
catch: (e) => new DriverError({ message: `Screenshot failed: ${e}` })
|
|
6297
6582
|
}),
|
|
6298
|
-
getDeviceInfo: () =>
|
|
6583
|
+
getDeviceInfo: () => Effect11.tryPromise({
|
|
6299
6584
|
try: async () => {
|
|
6300
6585
|
const size = await withSessionRecovery(() => client.getWindowSize());
|
|
6301
6586
|
return {
|
|
@@ -6313,7 +6598,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6313
6598
|
// -----------------------------------------------------------------------
|
|
6314
6599
|
// App lifecycle
|
|
6315
6600
|
// -----------------------------------------------------------------------
|
|
6316
|
-
launchApp: (appBundleId, opts) =>
|
|
6601
|
+
launchApp: (appBundleId, opts) => Effect11.tryPromise({
|
|
6317
6602
|
try: async () => {
|
|
6318
6603
|
const canFastReset = hasLaunchedOnce && driverOptions?.fastWebViewReset !== false && domChannel.isConnected() && !opts?.deepLink && !opts?.clearKeychain && !hasLaunchDeviceState(opts?.deviceState) && !(opts?.launchArguments && Object.keys(opts.launchArguments).length > 0);
|
|
6319
6604
|
if (canFastReset) {
|
|
@@ -6339,8 +6624,8 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6339
6624
|
if (opts?.clearState && simulatorUdid) {
|
|
6340
6625
|
terminateOnSimulator(simulatorUdid, appBundleId);
|
|
6341
6626
|
try {
|
|
6342
|
-
const { execFileSync:
|
|
6343
|
-
|
|
6627
|
+
const { execFileSync: execFileSync3 } = await import("child_process");
|
|
6628
|
+
execFileSync3(
|
|
6344
6629
|
"xcrun",
|
|
6345
6630
|
["simctl", "privacy", simulatorUdid, "reset", "all", appBundleId],
|
|
6346
6631
|
{
|
|
@@ -6397,7 +6682,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6397
6682
|
},
|
|
6398
6683
|
catch: (e) => new DriverError({ message: `Launch app failed: ${e}` })
|
|
6399
6684
|
}),
|
|
6400
|
-
stopApp: (appBundleId) =>
|
|
6685
|
+
stopApp: (appBundleId) => Effect11.tryPromise({
|
|
6401
6686
|
try: () => {
|
|
6402
6687
|
if (simulatorUdid) {
|
|
6403
6688
|
terminateOnSimulator(simulatorUdid, appBundleId);
|
|
@@ -6407,7 +6692,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6407
6692
|
},
|
|
6408
6693
|
catch: (e) => new DriverError({ message: `Stop app failed: ${e}` })
|
|
6409
6694
|
}),
|
|
6410
|
-
killApp: (appBundleId) =>
|
|
6695
|
+
killApp: (appBundleId) => Effect11.tryPromise({
|
|
6411
6696
|
try: async () => {
|
|
6412
6697
|
await domChannel.disconnect().catch(() => {
|
|
6413
6698
|
});
|
|
@@ -6420,7 +6705,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6420
6705
|
},
|
|
6421
6706
|
catch: (e) => new DriverError({ message: `Kill app failed: ${e}` })
|
|
6422
6707
|
}),
|
|
6423
|
-
clearAppState: (appBundleId) =>
|
|
6708
|
+
clearAppState: (appBundleId) => Effect11.tryPromise({
|
|
6424
6709
|
try: async () => {
|
|
6425
6710
|
if (domChannel.isConnected() && domChannel.clearStorage) {
|
|
6426
6711
|
await domChannel.clearStorage({
|
|
@@ -6443,7 +6728,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6443
6728
|
},
|
|
6444
6729
|
catch: (e) => new DriverError({ message: `Clear app state failed: ${e}` })
|
|
6445
6730
|
}),
|
|
6446
|
-
resetFast: () =>
|
|
6731
|
+
resetFast: () => Effect11.tryPromise({
|
|
6447
6732
|
try: async () => {
|
|
6448
6733
|
if (domChannel.clearStorage) {
|
|
6449
6734
|
await domChannel.clearStorage({
|
|
@@ -6470,7 +6755,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6470
6755
|
// -----------------------------------------------------------------------
|
|
6471
6756
|
// Navigation
|
|
6472
6757
|
// -----------------------------------------------------------------------
|
|
6473
|
-
openLink: (url) =>
|
|
6758
|
+
openLink: (url) => Effect11.tryPromise({
|
|
6474
6759
|
try: async () => {
|
|
6475
6760
|
if (simulatorUdid) {
|
|
6476
6761
|
await openSimulatorUrl(url);
|
|
@@ -6480,7 +6765,7 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6480
6765
|
},
|
|
6481
6766
|
catch: (e) => new DriverError({ message: `Open link failed: ${e}` })
|
|
6482
6767
|
}),
|
|
6483
|
-
back: () =>
|
|
6768
|
+
back: () => Effect11.tryPromise({
|
|
6484
6769
|
// iOS has no hardware back button; pressing home is the closest
|
|
6485
6770
|
// equivalent for dismissing the current context.
|
|
6486
6771
|
try: () => client.pressHome(),
|
|
@@ -6490,13 +6775,13 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6490
6775
|
// Direct DOM evaluation via spana-bridge or WebKit Remote Inspector
|
|
6491
6776
|
// (no Appium required)
|
|
6492
6777
|
// -----------------------------------------------------------------------
|
|
6493
|
-
evaluate: (script, ...args) =>
|
|
6778
|
+
evaluate: (script, ...args) => Effect11.tryPromise({
|
|
6494
6779
|
try: () => domChannel.evaluate(script, ...args),
|
|
6495
6780
|
catch: (e) => new DriverError({
|
|
6496
6781
|
message: `iOS direct WDA evaluate() failed via ${domChannel.kind}: ${e instanceof Error ? e.message : e}. Ensure WKWebView.isInspectable = true (iOS 16.4+) with ios_webkit_debug_proxy running, or include spana-bridge in test builds.`
|
|
6497
6782
|
})
|
|
6498
6783
|
}),
|
|
6499
|
-
getContexts: () =>
|
|
6784
|
+
getContexts: () => Effect11.tryPromise({
|
|
6500
6785
|
try: async () => {
|
|
6501
6786
|
const contexts = ["NATIVE_APP"];
|
|
6502
6787
|
if (domChannel.listTargets) {
|
|
@@ -6515,8 +6800,8 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6515
6800
|
},
|
|
6516
6801
|
catch: (e) => new DriverError({ message: `getContexts failed: ${e}` })
|
|
6517
6802
|
}),
|
|
6518
|
-
getCurrentContext: () =>
|
|
6519
|
-
setContext: (contextId) =>
|
|
6803
|
+
getCurrentContext: () => Effect11.succeed(currentContext),
|
|
6804
|
+
setContext: (contextId) => Effect11.tryPromise({
|
|
6520
6805
|
try: async () => {
|
|
6521
6806
|
if (contextId === "NATIVE_APP") {
|
|
6522
6807
|
currentContext = "NATIVE_APP";
|
|
@@ -6536,25 +6821,29 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6536
6821
|
},
|
|
6537
6822
|
catch: (e) => new DriverError({ message: `setContext failed: ${e}` })
|
|
6538
6823
|
}),
|
|
6539
|
-
mockNetwork: (matcher, response) =>
|
|
6824
|
+
mockNetwork: (matcher, response) => Effect11.tryPromise({
|
|
6540
6825
|
try: async () => {
|
|
6541
6826
|
if (!domChannel.mockNetwork) {
|
|
6542
|
-
throw new Error(
|
|
6827
|
+
throw new Error(
|
|
6828
|
+
"mockNetwork() is not supported on native iOS traffic; install spana-bridge in your WebView to intercept JavaScript requests"
|
|
6829
|
+
);
|
|
6543
6830
|
}
|
|
6544
6831
|
await domChannel.mockNetwork(matcher, response);
|
|
6545
6832
|
},
|
|
6546
6833
|
catch: (e) => new DriverError({ message: `mockNetwork failed: ${e}` })
|
|
6547
6834
|
}),
|
|
6548
|
-
blockNetwork: (matcher) =>
|
|
6835
|
+
blockNetwork: (matcher) => Effect11.tryPromise({
|
|
6549
6836
|
try: async () => {
|
|
6550
6837
|
if (!domChannel.blockNetwork) {
|
|
6551
|
-
throw new Error(
|
|
6838
|
+
throw new Error(
|
|
6839
|
+
"blockNetwork() is not supported on native iOS traffic; install spana-bridge in your WebView to intercept JavaScript requests"
|
|
6840
|
+
);
|
|
6552
6841
|
}
|
|
6553
6842
|
await domChannel.blockNetwork(matcher);
|
|
6554
6843
|
},
|
|
6555
6844
|
catch: (e) => new DriverError({ message: `blockNetwork failed: ${e}` })
|
|
6556
6845
|
}),
|
|
6557
|
-
clearNetworkMocks: () =>
|
|
6846
|
+
clearNetworkMocks: () => Effect11.tryPromise({
|
|
6558
6847
|
try: async () => {
|
|
6559
6848
|
if (domChannel.clearNetworkMocks) {
|
|
6560
6849
|
await domChannel.clearNetworkMocks();
|
|
@@ -6562,18 +6851,18 @@ function createWDADriver(host, port, bundleId, simulatorUdid, snapshotMaxDepth =
|
|
|
6562
6851
|
},
|
|
6563
6852
|
catch: (e) => new DriverError({ message: `clearNetworkMocks failed: ${e}` })
|
|
6564
6853
|
}),
|
|
6565
|
-
getConsoleLogs: () =>
|
|
6854
|
+
getConsoleLogs: () => Effect11.tryPromise({
|
|
6566
6855
|
try: async () => domChannel.getConsoleLogs ? domChannel.getConsoleLogs() : [],
|
|
6567
6856
|
catch: (e) => new DriverError({ message: `getConsoleLogs failed: ${e}` })
|
|
6568
6857
|
}),
|
|
6569
|
-
getJSErrors: () =>
|
|
6858
|
+
getJSErrors: () => Effect11.tryPromise({
|
|
6570
6859
|
try: async () => domChannel.getJSErrors ? domChannel.getJSErrors() : [],
|
|
6571
6860
|
catch: (e) => new DriverError({ message: `getJSErrors failed: ${e}` })
|
|
6572
6861
|
}),
|
|
6573
6862
|
// -----------------------------------------------------------------------
|
|
6574
6863
|
// Network simulation
|
|
6575
6864
|
// -----------------------------------------------------------------------
|
|
6576
|
-
setNetworkConditions: (conditions) =>
|
|
6865
|
+
setNetworkConditions: (conditions) => Effect11.tryPromise({
|
|
6577
6866
|
try: async () => {
|
|
6578
6867
|
if (!simulatorUdid) {
|
|
6579
6868
|
throw new DriverError({
|
|
@@ -6696,7 +6985,7 @@ function parseIOSHierarchy(xml) {
|
|
|
6696
6985
|
}
|
|
6697
6986
|
|
|
6698
6987
|
// src/drivers/electron.ts
|
|
6699
|
-
import { Effect as
|
|
6988
|
+
import { Effect as Effect12 } from "effect";
|
|
6700
6989
|
import {
|
|
6701
6990
|
_electron,
|
|
6702
6991
|
chromium as chromium2
|
|
@@ -6740,7 +7029,7 @@ var CLEAR_STORAGE_SCRIPT2 = `
|
|
|
6740
7029
|
})();
|
|
6741
7030
|
`;
|
|
6742
7031
|
function makeElectronDriver(options) {
|
|
6743
|
-
return
|
|
7032
|
+
return Effect12.gen(function* () {
|
|
6744
7033
|
let electronApp;
|
|
6745
7034
|
let cdpBrowser;
|
|
6746
7035
|
let context;
|
|
@@ -6764,13 +7053,13 @@ function makeElectronDriver(options) {
|
|
|
6764
7053
|
const resolvedCdpUrl = options.cdpUrl ?? (options.cdpPort && !options.entry && !options.executablePath ? `http://127.0.0.1:${options.cdpPort}` : void 0);
|
|
6765
7054
|
if (resolvedCdpUrl) {
|
|
6766
7055
|
const connect = options.connectOverCDP ?? chromium2.connectOverCDP.bind(chromium2);
|
|
6767
|
-
cdpBrowser = yield*
|
|
7056
|
+
cdpBrowser = yield* Effect12.tryPromise({
|
|
6768
7057
|
try: () => connect(resolvedCdpUrl),
|
|
6769
7058
|
catch: (e) => new DriverError({
|
|
6770
7059
|
message: `Failed to connect to Electron over CDP (${resolvedCdpUrl}): ${e}`
|
|
6771
7060
|
})
|
|
6772
7061
|
});
|
|
6773
|
-
page = yield*
|
|
7062
|
+
page = yield* Effect12.tryPromise({
|
|
6774
7063
|
try: async () => {
|
|
6775
7064
|
const contexts = cdpBrowser.contexts();
|
|
6776
7065
|
context = contexts[0];
|
|
@@ -6795,7 +7084,7 @@ function makeElectronDriver(options) {
|
|
|
6795
7084
|
});
|
|
6796
7085
|
}
|
|
6797
7086
|
const launcher = options.launchElectron ?? _electron.launch.bind(_electron);
|
|
6798
|
-
electronApp = yield*
|
|
7087
|
+
electronApp = yield* Effect12.tryPromise({
|
|
6799
7088
|
try: () => launcher({
|
|
6800
7089
|
...options.executablePath ? { executablePath: options.executablePath } : {},
|
|
6801
7090
|
...launchArgs.length > 0 ? { args: launchArgs } : {},
|
|
@@ -6804,7 +7093,7 @@ function makeElectronDriver(options) {
|
|
|
6804
7093
|
}),
|
|
6805
7094
|
catch: (e) => new DriverError({ message: `Failed to launch Electron app: ${e}` })
|
|
6806
7095
|
});
|
|
6807
|
-
page = yield*
|
|
7096
|
+
page = yield* Effect12.tryPromise({
|
|
6808
7097
|
try: async () => {
|
|
6809
7098
|
const win = await electronApp.firstWindow();
|
|
6810
7099
|
context = electronApp.context();
|
|
@@ -6834,26 +7123,26 @@ function makeElectronDriver(options) {
|
|
|
6834
7123
|
};
|
|
6835
7124
|
const service = {
|
|
6836
7125
|
domChannel,
|
|
6837
|
-
beginFlow: () =>
|
|
7126
|
+
beginFlow: () => Effect12.sync(() => {
|
|
6838
7127
|
consoleLogs.length = 0;
|
|
6839
7128
|
jsErrors.length = 0;
|
|
6840
7129
|
}),
|
|
6841
|
-
dumpHierarchy: () =>
|
|
7130
|
+
dumpHierarchy: () => Effect12.tryPromise({
|
|
6842
7131
|
try: async () => {
|
|
6843
7132
|
const tree = await page.evaluate(DOM_HIERARCHY_WALK_SCRIPT);
|
|
6844
7133
|
return JSON.stringify(tree);
|
|
6845
7134
|
},
|
|
6846
7135
|
catch: (e) => new DriverError({ message: `Electron dumpHierarchy failed: ${e}` })
|
|
6847
7136
|
}),
|
|
6848
|
-
tapAtCoordinate: (x, y) =>
|
|
7137
|
+
tapAtCoordinate: (x, y) => Effect12.tryPromise({
|
|
6849
7138
|
try: () => page.mouse.click(x, y),
|
|
6850
7139
|
catch: (e) => new DriverError({ message: `Electron tap failed at (${x}, ${y}): ${e}` })
|
|
6851
7140
|
}),
|
|
6852
|
-
doubleTapAtCoordinate: (x, y) =>
|
|
7141
|
+
doubleTapAtCoordinate: (x, y) => Effect12.tryPromise({
|
|
6853
7142
|
try: () => page.mouse.dblclick(x, y),
|
|
6854
7143
|
catch: (e) => new DriverError({ message: `Electron doubleTap failed at (${x}, ${y}): ${e}` })
|
|
6855
7144
|
}),
|
|
6856
|
-
longPressAtCoordinate: (x, y, duration) =>
|
|
7145
|
+
longPressAtCoordinate: (x, y, duration) => Effect12.tryPromise({
|
|
6857
7146
|
try: async () => {
|
|
6858
7147
|
await page.mouse.move(x, y);
|
|
6859
7148
|
await page.mouse.down();
|
|
@@ -6862,7 +7151,7 @@ function makeElectronDriver(options) {
|
|
|
6862
7151
|
},
|
|
6863
7152
|
catch: (e) => new DriverError({ message: `Electron longPress failed: ${e}` })
|
|
6864
7153
|
}),
|
|
6865
|
-
swipe: (startX, startY, endX, endY, duration) =>
|
|
7154
|
+
swipe: (startX, startY, endX, endY, duration) => Effect12.tryPromise({
|
|
6866
7155
|
try: async () => {
|
|
6867
7156
|
await page.mouse.move(startX, startY);
|
|
6868
7157
|
await page.mouse.wheel(startX - endX, startY - endY);
|
|
@@ -6870,20 +7159,20 @@ function makeElectronDriver(options) {
|
|
|
6870
7159
|
},
|
|
6871
7160
|
catch: (e) => new DriverError({ message: `Electron swipe failed: ${e}` })
|
|
6872
7161
|
}),
|
|
6873
|
-
inputText: (text) =>
|
|
7162
|
+
inputText: (text) => Effect12.tryPromise({
|
|
6874
7163
|
try: () => page.keyboard.insertText(text),
|
|
6875
7164
|
catch: (e) => new DriverError({ message: `Electron inputText failed: ${e}` })
|
|
6876
7165
|
}),
|
|
6877
|
-
pressKey: (key) =>
|
|
7166
|
+
pressKey: (key) => Effect12.tryPromise({
|
|
6878
7167
|
try: () => page.keyboard.press(key),
|
|
6879
7168
|
catch: (e) => new DriverError({ message: `Electron pressKey failed: ${e}` })
|
|
6880
7169
|
}),
|
|
6881
|
-
hideKeyboard: () =>
|
|
6882
|
-
takeScreenshot: () =>
|
|
7170
|
+
hideKeyboard: () => Effect12.void,
|
|
7171
|
+
takeScreenshot: () => Effect12.tryPromise({
|
|
6883
7172
|
try: async () => new Uint8Array(await page.screenshot()),
|
|
6884
7173
|
catch: (e) => new DriverError({ message: `Electron screenshot failed: ${e}` })
|
|
6885
7174
|
}),
|
|
6886
|
-
getDeviceInfo: () =>
|
|
7175
|
+
getDeviceInfo: () => Effect12.tryPromise({
|
|
6887
7176
|
try: async () => {
|
|
6888
7177
|
const viewport = page.viewportSize() ?? { width: 1280, height: 800 };
|
|
6889
7178
|
return {
|
|
@@ -6898,7 +7187,7 @@ function makeElectronDriver(options) {
|
|
|
6898
7187
|
},
|
|
6899
7188
|
catch: (e) => new DriverError({ message: `Electron getDeviceInfo failed: ${e}` })
|
|
6900
7189
|
}),
|
|
6901
|
-
launchApp: (appRef, opts) =>
|
|
7190
|
+
launchApp: (appRef, opts) => Effect12.tryPromise({
|
|
6902
7191
|
try: async () => {
|
|
6903
7192
|
if (opts?.clearState) {
|
|
6904
7193
|
await clearStorageAndCookies();
|
|
@@ -6910,8 +7199,8 @@ function makeElectronDriver(options) {
|
|
|
6910
7199
|
},
|
|
6911
7200
|
catch: (e) => new DriverError({ message: `Electron launchApp failed: ${e}` })
|
|
6912
7201
|
}),
|
|
6913
|
-
stopApp: () =>
|
|
6914
|
-
killApp: () =>
|
|
7202
|
+
stopApp: () => Effect12.void,
|
|
7203
|
+
killApp: () => Effect12.tryPromise({
|
|
6915
7204
|
try: async () => {
|
|
6916
7205
|
await domChannel?.disconnect().catch(() => {
|
|
6917
7206
|
});
|
|
@@ -6923,32 +7212,32 @@ function makeElectronDriver(options) {
|
|
|
6923
7212
|
},
|
|
6924
7213
|
catch: (e) => new DriverError({ message: `Electron killApp failed: ${e}` })
|
|
6925
7214
|
}),
|
|
6926
|
-
clearAppState: () =>
|
|
7215
|
+
clearAppState: () => Effect12.tryPromise({
|
|
6927
7216
|
try: async () => {
|
|
6928
7217
|
await clearStorageAndCookies();
|
|
6929
7218
|
},
|
|
6930
7219
|
catch: (e) => new DriverError({ message: `Electron clearAppState failed: ${e}` })
|
|
6931
7220
|
}),
|
|
6932
|
-
resetFast: () =>
|
|
7221
|
+
resetFast: () => Effect12.tryPromise({
|
|
6933
7222
|
try: async () => {
|
|
6934
7223
|
await clearStorageAndCookies();
|
|
6935
7224
|
await page.reload();
|
|
6936
7225
|
},
|
|
6937
7226
|
catch: (e) => new DriverError({ message: `Electron resetFast failed: ${e}` })
|
|
6938
7227
|
}),
|
|
6939
|
-
openLink: (url) =>
|
|
7228
|
+
openLink: (url) => Effect12.tryPromise({
|
|
6940
7229
|
try: async () => {
|
|
6941
7230
|
await page.goto(url);
|
|
6942
7231
|
},
|
|
6943
7232
|
catch: (e) => new DriverError({ message: `Electron openLink failed: ${e}` })
|
|
6944
7233
|
}),
|
|
6945
|
-
back: () =>
|
|
7234
|
+
back: () => Effect12.tryPromise({
|
|
6946
7235
|
try: async () => {
|
|
6947
7236
|
await page.goBack();
|
|
6948
7237
|
},
|
|
6949
7238
|
catch: (e) => new DriverError({ message: `Electron back failed: ${e}` })
|
|
6950
7239
|
}),
|
|
6951
|
-
evaluate: (script, ...args) =>
|
|
7240
|
+
evaluate: (script, ...args) => Effect12.tryPromise({
|
|
6952
7241
|
try: async () => {
|
|
6953
7242
|
if (domChannel?.isConnected()) {
|
|
6954
7243
|
return await domChannel.evaluate(script, ...args);
|
|
@@ -6966,7 +7255,7 @@ function makeElectronDriver(options) {
|
|
|
6966
7255
|
},
|
|
6967
7256
|
catch: (e) => new DriverError({ message: `Electron evaluate failed: ${e}` })
|
|
6968
7257
|
}),
|
|
6969
|
-
mockNetwork: (matcher, response) =>
|
|
7258
|
+
mockNetwork: (matcher, response) => Effect12.tryPromise({
|
|
6970
7259
|
try: async () => {
|
|
6971
7260
|
if (!context) throw new Error("No Electron BrowserContext available");
|
|
6972
7261
|
await context.route(matcher, async (route) => {
|
|
@@ -6981,7 +7270,7 @@ function makeElectronDriver(options) {
|
|
|
6981
7270
|
},
|
|
6982
7271
|
catch: (e) => new DriverError({ message: `Electron mockNetwork failed: ${e}` })
|
|
6983
7272
|
}),
|
|
6984
|
-
blockNetwork: (matcher) =>
|
|
7273
|
+
blockNetwork: (matcher) => Effect12.tryPromise({
|
|
6985
7274
|
try: async () => {
|
|
6986
7275
|
if (!context) throw new Error("No Electron BrowserContext available");
|
|
6987
7276
|
await context.route(matcher, async (route) => {
|
|
@@ -6991,7 +7280,7 @@ function makeElectronDriver(options) {
|
|
|
6991
7280
|
},
|
|
6992
7281
|
catch: (e) => new DriverError({ message: `Electron blockNetwork failed: ${e}` })
|
|
6993
7282
|
}),
|
|
6994
|
-
clearNetworkMocks: () =>
|
|
7283
|
+
clearNetworkMocks: () => Effect12.tryPromise({
|
|
6995
7284
|
try: async () => {
|
|
6996
7285
|
if (!context) return;
|
|
6997
7286
|
for (const entry of appliedRoutes) {
|
|
@@ -7002,25 +7291,25 @@ function makeElectronDriver(options) {
|
|
|
7002
7291
|
},
|
|
7003
7292
|
catch: (e) => new DriverError({ message: `Electron clearNetworkMocks failed: ${e}` })
|
|
7004
7293
|
}),
|
|
7005
|
-
getConsoleLogs: () =>
|
|
7006
|
-
getJSErrors: () =>
|
|
7294
|
+
getConsoleLogs: () => Effect12.succeed([...consoleLogs]),
|
|
7295
|
+
getJSErrors: () => Effect12.succeed([...jsErrors])
|
|
7007
7296
|
};
|
|
7008
7297
|
return service;
|
|
7009
7298
|
});
|
|
7010
7299
|
}
|
|
7011
7300
|
|
|
7012
7301
|
// src/drivers/uiautomator2/installer.ts
|
|
7013
|
-
import { execFileSync, spawn as spawn2 } from "child_process";
|
|
7302
|
+
import { execFileSync as execFileSync2, spawn as spawn2 } from "child_process";
|
|
7014
7303
|
import { existsSync, readdirSync } from "fs";
|
|
7015
7304
|
import { createRequire } from "module";
|
|
7016
|
-
import { dirname, resolve, join as join2 } from "path";
|
|
7305
|
+
import { dirname as dirname2, resolve, join as join2 } from "path";
|
|
7017
7306
|
import { fileURLToPath } from "url";
|
|
7018
7307
|
var __dirname2 = fileURLToPath(new URL(".", import.meta.url));
|
|
7019
7308
|
var require2 = createRequire(import.meta.url);
|
|
7020
7309
|
function resolveOptionalPackageDir(packageName, subpath) {
|
|
7021
7310
|
try {
|
|
7022
7311
|
const packageJsonPath = require2.resolve(`${packageName}/package.json`);
|
|
7023
|
-
return resolve(
|
|
7312
|
+
return resolve(dirname2(packageJsonPath), subpath);
|
|
7024
7313
|
} catch {
|
|
7025
7314
|
return null;
|
|
7026
7315
|
}
|
|
@@ -7115,7 +7404,7 @@ async function setupUiAutomator2(serial, hostPort, options = {}) {
|
|
|
7115
7404
|
const adb = findADB();
|
|
7116
7405
|
if (adb) {
|
|
7117
7406
|
try {
|
|
7118
|
-
|
|
7407
|
+
execFileSync2(adb, ["-s", serial, "forward", "--remove", `tcp:${port}`], { stdio: "ignore" });
|
|
7119
7408
|
} catch {
|
|
7120
7409
|
}
|
|
7121
7410
|
}
|
|
@@ -7145,7 +7434,7 @@ async function setupUiAutomator2(serial, hostPort, options = {}) {
|
|
|
7145
7434
|
if (warm) return;
|
|
7146
7435
|
try {
|
|
7147
7436
|
if (adb)
|
|
7148
|
-
|
|
7437
|
+
execFileSync2(adb, ["-s", serial, "forward", "--remove", `tcp:${port}`], {
|
|
7149
7438
|
stdio: "ignore"
|
|
7150
7439
|
});
|
|
7151
7440
|
} catch {
|
|
@@ -7192,6 +7481,7 @@ export {
|
|
|
7192
7481
|
createPromiseExpect,
|
|
7193
7482
|
createPromiseApp,
|
|
7194
7483
|
parseWebHierarchy,
|
|
7484
|
+
deviceEffect,
|
|
7195
7485
|
resolveNetworkConditions,
|
|
7196
7486
|
ensureWarmBrowserDaemon,
|
|
7197
7487
|
connectPlaywrightOverCDP,
|
|
@@ -7205,4 +7495,4 @@ export {
|
|
|
7205
7495
|
makeElectronDriver,
|
|
7206
7496
|
setupUiAutomator2
|
|
7207
7497
|
};
|
|
7208
|
-
//# sourceMappingURL=chunk-
|
|
7498
|
+
//# sourceMappingURL=chunk-B35G77DN.js.map
|