Skip to content

Commit a174c73

Browse files
committed
Stabilize Android UIAutomator integration probe
1 parent 9ea73b8 commit a174c73

1 file changed

Lines changed: 65 additions & 28 deletions

File tree

scripts/integration/android.mjs

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,38 +127,48 @@ async function runCliSurface() {
127127
assert.ok(Number(profile.screenWidth) > 0, "missing Android screenWidth");
128128
assert.ok(Number(profile.screenHeight) > 0, "missing Android screenHeight");
129129
});
130-
const tree = await measuredStep("CLI describe Android tree", () => {
131-
const payload = simdeckJson([
132-
"describe",
133-
androidUDID,
134-
"--source",
135-
"android-uiautomator",
136-
"--format",
137-
"compact-json",
138-
"--max-depth",
139-
"2",
140-
]);
130+
const tree = await measuredStep("CLI describe Android tree", async () => {
131+
const payload = await retryAsync(
132+
() =>
133+
simdeckJson([
134+
"describe",
135+
androidUDID,
136+
"--source",
137+
"android-uiautomator",
138+
"--format",
139+
"compact-json",
140+
"--max-depth",
141+
"2",
142+
]),
143+
"CLI describe Android tree",
144+
{ attempts: 8, delayMs: 2_000 },
145+
);
141146
assertRoots(payload, "CLI describe");
142147
return payload;
143148
});
144-
await measuredStep("CLI describe Android point", () => {
149+
await measuredStep("CLI describe Android point", async () => {
145150
const point = centerOfFirstRoot(tree);
146151
if (!point) {
147152
throw new Error("Unable to derive point from Android tree root.");
148153
}
149154
assertRoots(
150-
simdeckJson([
151-
"describe",
152-
androidUDID,
153-
"--source",
154-
"android-uiautomator",
155-
"--format",
156-
"compact-json",
157-
"--point",
158-
`${point.x},${point.y}`,
159-
"--max-depth",
160-
"1",
161-
]),
155+
await retryAsync(
156+
() =>
157+
simdeckJson([
158+
"describe",
159+
androidUDID,
160+
"--source",
161+
"android-uiautomator",
162+
"--format",
163+
"compact-json",
164+
"--point",
165+
`${point.x},${point.y}`,
166+
"--max-depth",
167+
"1",
168+
]),
169+
"CLI describe Android point",
170+
{ attempts: 4, delayMs: 1_000 },
171+
),
162172
"CLI point describe",
163173
);
164174
});
@@ -317,10 +327,15 @@ async function runJsSurface() {
317327
});
318328
await measuredStep("JS Android tree", async () => {
319329
assertRoots(
320-
await session.tree(androidUDID, {
321-
source: "android-uiautomator",
322-
maxDepth: 2,
323-
}),
330+
await retryAsync(
331+
() =>
332+
session.tree(androidUDID, {
333+
source: "android-uiautomator",
334+
maxDepth: 2,
335+
}),
336+
"JS Android tree",
337+
{ attempts: 6, delayMs: 2_000 },
338+
),
324339
"JS tree",
325340
);
326341
});
@@ -583,6 +598,28 @@ async function measuredStep(label, run, options = {}) {
583598
}
584599
}
585600

601+
async function retryAsync(run, label, options = {}) {
602+
const attempts = options.attempts ?? 3;
603+
const delayMs = options.delayMs ?? 1_000;
604+
let lastError = null;
605+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
606+
try {
607+
return await run();
608+
} catch (error) {
609+
lastError = error;
610+
if (attempt < attempts) {
611+
if (verbose) {
612+
console.log(
613+
`${label} attempt ${attempt}/${attempts} failed: ${error.message}`,
614+
);
615+
}
616+
await sleep(delayMs);
617+
}
618+
}
619+
}
620+
throw lastError;
621+
}
622+
586623
function printTimingSummary() {
587624
if (!verbose || stepTimings.length === 0) {
588625
return;

0 commit comments

Comments
 (0)