Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions test/integration/android-emulator-e2e/live-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,37 @@ export const { assertElementText, assertWaitSelector, assertWaitText, capturePng
PUBLIC_COMMANDS.wait,
);

export async function scrollToVisibleSelector(
context: LiveContext,
selector: string,
): Promise<void> {
for (let attempt = 0; attempt < 6; attempt += 1) {
const result = await runStep(
context,
`check ${selector} visibility (${attempt + 1})`,
['is', 'visible', selector],
{ allowFailure: true },
);
if (result.status === 0) {
assert.equal(result.json?.data?.pass, true, JSON.stringify(result.json));
return;
}
const reason = result.json?.error?.details?.reason;
assert.ok(
reason === 'selector_not_found' || reason === 'predicate_failed',
`could not observe ${selector}: ${JSON.stringify(result.json)}`,
);
if (attempt < 5) {
await runStep(context, `scroll toward ${selector} (${attempt + 1})`, [
'scroll',
'down',
'0.25',
]);
}
}
assert.fail(`${selector} did not become visible after five scrolls`);
}

export function assertDiffLine(
result: CliJsonResult,
kind: SnapshotDiffLine['kind'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
assertWaitText,
capturePng,
requireAndroidResourceId,
scrollToVisibleSelector,
} from './live-assertions.ts';
import { type LiveContext, runStep, verifyBehavior, verifyCommand } from './live-harness.ts';

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

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

await scrollToVisibleSelector(context, 'id="automation-longpress"');
await runStep(context, 'long press semantic canary', [
'longpress',
'id="automation-longpress"',
'800',
]);
await scrollToVisibleSelector(context, 'id="automation-longpress-count"');
await assertWaitText(context, 'Long presses: 1');
verifyCommand(context, C.longPress, '800ms hold increments durable fixture long-press counter');

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

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