Skip to content

Commit 5ba4ac7

Browse files
authored
test(android): reveal smoke canaries by visibility (#2369)
1 parent 233a34d commit 5ba4ac7

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

test/integration/android-emulator-e2e/live-assertions.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,37 @@ export const { assertElementText, assertWaitSelector, assertWaitText, capturePng
2222
PUBLIC_COMMANDS.wait,
2323
);
2424

25+
export async function scrollToVisibleSelector(
26+
context: LiveContext,
27+
selector: string,
28+
): Promise<void> {
29+
for (let attempt = 0; attempt < 6; attempt += 1) {
30+
const result = await runStep(
31+
context,
32+
`check ${selector} visibility (${attempt + 1})`,
33+
['is', 'visible', selector],
34+
{ allowFailure: true },
35+
);
36+
if (result.status === 0) {
37+
assert.equal(result.json?.data?.pass, true, JSON.stringify(result.json));
38+
return;
39+
}
40+
const reason = result.json?.error?.details?.reason;
41+
assert.ok(
42+
reason === 'selector_not_found' || reason === 'predicate_failed',
43+
`could not observe ${selector}: ${JSON.stringify(result.json)}`,
44+
);
45+
if (attempt < 5) {
46+
await runStep(context, `scroll toward ${selector} (${attempt + 1})`, [
47+
'scroll',
48+
'down',
49+
'0.25',
50+
]);
51+
}
52+
}
53+
assert.fail(`${selector} did not become visible after five scrolls`);
54+
}
55+
2556
export function assertDiffLine(
2657
result: CliJsonResult,
2758
kind: SnapshotDiffLine['kind'],

test/integration/android-emulator-e2e/live-automation-scenario.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
assertWaitText,
1313
capturePng,
1414
requireAndroidResourceId,
15+
scrollToVisibleSelector,
1516
} from './live-assertions.ts';
1617
import { type LiveContext, runStep, verifyBehavior, verifyCommand } from './live-harness.ts';
1718

@@ -126,19 +127,24 @@ export async function assertAutomationSystem(context: LiveContext): Promise<void
126127
'fixture automation-window value changed to landscape and back to portrait',
127128
);
128129

129-
await runStep(context, 'reveal input canaries', ['scroll', 'down', '0.7']);
130+
await runStep(context, 'restore automation route top after rotation', ['scroll', 'top']);
131+
await scrollToVisibleSelector(context, 'id="automation-press"');
130132
await runStep(context, 'press semantic canary', ['press', 'id="automation-press"']);
133+
await scrollToVisibleSelector(context, 'id="automation-last-input"');
131134
await assertWaitText(context, 'Last input: press');
132135
verifyCommand(context, C.press, 'semantic press updates durable fixture input state');
133136

137+
await scrollToVisibleSelector(context, 'id="automation-longpress"');
134138
await runStep(context, 'long press semantic canary', [
135139
'longpress',
136140
'id="automation-longpress"',
137141
'800',
138142
]);
143+
await scrollToVisibleSelector(context, 'id="automation-longpress-count"');
139144
await assertWaitText(context, 'Long presses: 1');
140145
verifyCommand(context, C.longPress, '800ms hold increments durable fixture long-press counter');
141146

147+
await scrollToVisibleSelector(context, 'id="automation-open-alert"');
142148
await runStep(context, 'open Android native alert', ['click', 'id="automation-open-alert"']);
143149
await assertWaitText(context, 'Automation confirmation');
144150
const alertSnapshot = await runStep(context, 'capture native alert through persistent helper', [
@@ -164,6 +170,7 @@ export async function assertAutomationSystem(context: LiveContext): Promise<void
164170
const alert = await runStep(context, 'inspect Android native alert', ['alert', 'get']);
165171
assertJsonContains(alert, 'Automation confirmation', 'alert get should expose fixture dialog');
166172
await runStep(context, 'dismiss Android native alert', ['alert', 'dismiss']);
173+
await scrollToVisibleSelector(context, 'id="automation-alert-result"');
167174
// The dismissal is confirmed, but the fixture's re-render after the button callback is the
168175
// app's own timing: wait for the outcome, then pin it to the canary element.
169176
await assertWaitText(context, 'Alert result: cancelled');
@@ -175,7 +182,7 @@ export async function assertAutomationSystem(context: LiveContext): Promise<void
175182
verifyCommand(context, C.alert, 'alert wait/get/dismiss/accept produce fixture-visible results');
176183

177184
await assertHomeAndRecentsRestoration(context);
178-
await runStep(context, 'reveal Android alert canary for diff baseline', ['scroll', 'down', '1']);
185+
await scrollToVisibleSelector(context, 'id="automation-open-alert"');
179186
await runStep(context, 'establish automation diff baseline', ['snapshot', '-i']);
180187
await runStep(context, 'return from automation route with Back', ['back']);
181188
const diff = await runStep(context, 'observe automation-to-settings diff', [

0 commit comments

Comments
 (0)