Control UI E2E
Use this for Control UI changes that need a real browser flow with deterministic Gateway data.
Test Shape
- Use
ui/src/**/*.e2e.test.ts for full GUI flows.
- Use
ui/src/test-helpers/control-ui-e2e.ts to start the Vite Control UI and install a mocked Gateway WebSocket.
- Keep scenarios deterministic. Do not use live provider keys, real channel credentials, or a real Gateway unless the user explicitly asks for live proof.
- Prefer existing
.browser.test.ts or unit tests for narrow rendering logic; use this E2E lane when the proof should cover routing, app boot, Gateway handshake, requests, and visible UI behavior together.
Commands
- Target one E2E test in a Codex worktree:
node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/chat-flow.messaging.e2e.test.ts
- Run the whole local lane in a normal checkout:
pnpm test:ui:e2e
Use an existing ready dependency installation or a prepared normal checkout;
do not reconcile a shared install while other jobs use it. Follow
$openclaw-testing: trusted development proof may run locally, and remote
proof needs a browser/platform, clean-environment, or source-isolation reason.
Visual Proof Default
For appearance changes, capture inspected before/after visual evidence. For
other behavior, use the clearest appropriate boundary proof; a video and a
screenshot set are not mandatory when assertions already demonstrate the change.
- Keep the Vitest E2E assertions deterministic; do not commit generated screenshots or videos.
- After or alongside the focused E2E test, run the mocked Control UI app when available, for example
pnpm dev:ui:mock -- --port <port>.
- Drive Chromium with Playwright against the local mock URL. Capture the states
needed to demonstrate the change, using screenshots or a short video.
- Use
browser.newContext({ recordVideo: { dir, size }, viewport }), page.screenshot({ path }), and close the context before reporting the video path.
- The session-host command-state proof uses viewport-only captures, verified with Playwright 1.62.1 and Chrome 151.0.7922.34 (Linux real Gateway; macOS arm64 synthetic reproduction). Other recording owners have not been migrated or certified by this fix; verify their required screenshot content and finalized video separately. See the verified capture path and upstream limitation.
- Allocate retained proof with
createControlUiE2eArtifactDir(scope, parentDir?) from ui/src/test-helpers/control-ui-e2e-artifacts.ts. Each call atomically creates a fresh directory and logs its actual path. An explicit parent wins, then the trimmed existing OPENCLAW_UI_E2E_ARTIFACT_DIR, then the repository's .artifacts/control-ui-e2e parent. Existing custom output controls select parents; do not add or rewrite env vars to enable capture.
- Allocate during the test/scenario or
beforeEach, once per attempt; standalone scripts allocate once per invocation. Pass the owner explicitly to shared capture helpers. Keep the original gates, feature/stage names, viewports, waits, and recording options. Use distinct filenames for distinct stages and keep screenshots, reports, and video together.
- Retain successful and failed evidence. Report actual allocated paths, including relocated filename overrides. Manually delete only exact owned directories after review; never clear shared parents before a replay. Disposable build/media fixtures and owned temporary raw video may keep their cleanup. New synthetic captures do not recover overwritten evidence.
- Timeout diagnostics use fresh children beneath their existing diagnostic parent. Mantis retains every capture attempt under an invocation-owned directory and refuses to overwrite reports. Real-Gateway suites,
chat-outbox-*, and chat-attachment-read-lifecycle remain separate owners; coordinate before claiming replay-safe retention there.
- Treat recording as validation, not only demo capture. If the recorder fails or shows surprising behavior, stop, fix the behavior, add or update a regression test, then rerecord.
- If visual proof is blocked, state the exact blocker and still report the textual E2E evidence.
Mock Pattern
Start the app server, install the mock before page.goto, then assert both Gateway traffic and visible UI:
const server = await startControlUiE2eServer();
const page = await context.newPage();
const gateway = await installMockGateway(page, {
historyMessages: [{ role: "assistant", content: [{ type: "text", text: "Ready." }] }],
});
await page.goto(`${server.baseUrl}chat`);
await page.locator(".agent-chat__composer-combobox textarea").fill("hello");
await page.getByRole("button", { name: "Send message" }).click();
const request = await gateway.waitForRequest("chat.send");
await gateway.emitChatFinal({ runId: String(request.params.idempotencyKey), text: "Done." });
await page.getByText("Done.").waitFor();
Extend installMockGateway with typed scenario options or method responses when a new flow needs more Gateway surface.
Standalone Recording
When recording an already-running mocked Control UI URL, use a temporary Playwright script or playwright test spec and keep the recording flow focused:
- Open the mock URL, interact through stable
data-* selectors or user-facing role selectors, and wait on asserted states instead of relying on fixed sleeps.
- Assert both visible UI state and mocked Gateway traffic for request-driven flows. For example, verify the expected count/row is visible and that
sessions.list was called with the expected search, offset, and limit.
- Use short sleeps only after assertions to make the captured video readable.
- Store the generated video in the invocation's fresh allocated directory; do not commit it or remove older captures.
1---2name: control-ui-e2e3description: Use when testing, fixing, or extending the OpenClaw Control UI GUI with Vitest + Playwright end-to-end checks, mocked Gateway WebSocket flows, mocked dashboard runs, screenshots/videos, or agent-verifiable browser proof.4---5
6# Control UI E2E
7
8Use this for Control UI changes that need a real browser flow with deterministic Gateway data.
9
10## Test Shape
11
12- Use `ui/src/**/*.e2e.test.ts` for full GUI flows.
13- Use `ui/src/test-helpers/control-ui-e2e.ts` to start the Vite Control UI and install a mocked Gateway WebSocket.
14- Keep scenarios deterministic. Do not use live provider keys, real channel credentials, or a real Gateway unless the user explicitly asks for live proof.
15- Prefer existing `.browser.test.ts` or unit tests for narrow rendering logic; use this E2E lane when the proof should cover routing, app boot, Gateway handshake, requests, and visible UI behavior together.
16
17## Commands
18
19- Target one E2E test in a Codex worktree:
20
21```bash
22node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/chat-flow.messaging.e2e.test.ts
23```
24
25- Run the whole local lane in a normal checkout:
26
27```bash
28pnpm test:ui:e2e
29```
30
31Use an existing ready dependency installation or a prepared normal checkout;
32do not reconcile a shared install while other jobs use it. Follow
33`$openclaw-testing`: trusted development proof may run locally, and remote
34proof needs a browser/platform, clean-environment, or source-isolation reason.
35
36## Visual Proof Default
37
38For appearance changes, capture inspected before/after visual evidence. For
39other behavior, use the clearest appropriate boundary proof; a video and a
40screenshot set are not mandatory when assertions already demonstrate the change.
41
42- Keep the Vitest E2E assertions deterministic; do not commit generated screenshots or videos.
43- After or alongside the focused E2E test, run the mocked Control UI app when available, for example `pnpm dev:ui:mock -- --port <port>`.
44- Drive Chromium with Playwright against the local mock URL. Capture the states
45 needed to demonstrate the change, using screenshots or a short video.
46- Use `browser.newContext({ recordVideo: { dir, size }, viewport })`, `page.screenshot({ path })`, and close the context before reporting the video path.
47- The session-host command-state proof uses viewport-only captures, verified with Playwright 1.62.1 and Chrome 151.0.7922.34 (Linux real Gateway; macOS arm64 synthetic reproduction). Other recording owners have not been migrated or certified by this fix; verify their required screenshot content and finalized video separately. See [the verified capture path and upstream limitation](https://docs.openclaw.ai/reference/test#screenshots-during-chromium-recordings).
48- Allocate retained proof with `createControlUiE2eArtifactDir(scope, parentDir?)` from `ui/src/test-helpers/control-ui-e2e-artifacts.ts`. Each call atomically creates a fresh directory and logs its actual path. An explicit parent wins, then the trimmed existing `OPENCLAW_UI_E2E_ARTIFACT_DIR`, then the repository's `.artifacts/control-ui-e2e` parent. Existing custom output controls select parents; do not add or rewrite env vars to enable capture.
49- Allocate during the test/scenario or `beforeEach`, once per attempt; standalone scripts allocate once per invocation. Pass the owner explicitly to shared capture helpers. Keep the original gates, feature/stage names, viewports, waits, and recording options. Use distinct filenames for distinct stages and keep screenshots, reports, and video together.
50- Retain successful and failed evidence. Report actual allocated paths, including relocated filename overrides. Manually delete only exact owned directories after review; never clear shared parents before a replay. Disposable build/media fixtures and owned temporary raw video may keep their cleanup. New synthetic captures do not recover overwritten evidence.
51- Timeout diagnostics use fresh children beneath their existing diagnostic parent. Mantis retains every capture attempt under an invocation-owned directory and refuses to overwrite reports. Real-Gateway suites, `chat-outbox-*`, and `chat-attachment-read-lifecycle` remain separate owners; coordinate before claiming replay-safe retention there.
52- Treat recording as validation, not only demo capture. If the recorder fails or shows surprising behavior, stop, fix the behavior, add or update a regression test, then rerecord.
53- If visual proof is blocked, state the exact blocker and still report the textual E2E evidence.
54
55## Mock Pattern
56
57Start the app server, install the mock before `page.goto`, then assert both Gateway traffic and visible UI:
58
59```ts
60const server = await startControlUiE2eServer();
61const page = await context.newPage();
62const gateway = await installMockGateway(page, {
63 historyMessages: [{ role: "assistant", content: [{ type: "text", text: "Ready." }] }],
64});
65
66await page.goto(`${server.baseUrl}chat`);
67await page.locator(".agent-chat__composer-combobox textarea").fill("hello");
68await page.getByRole("button", { name: "Send message" }).click();
69
70const request = await gateway.waitForRequest("chat.send");
71await gateway.emitChatFinal({ runId: String(request.params.idempotencyKey), text: "Done." });
72await page.getByText("Done.").waitFor();
73```
74
75Extend `installMockGateway` with typed scenario options or method responses when a new flow needs more Gateway surface.
76
77## Standalone Recording
78
79When recording an already-running mocked Control UI URL, use a temporary Playwright script or `playwright test` spec and keep the recording flow focused:
80
81- Open the mock URL, interact through stable `data-*` selectors or user-facing role selectors, and wait on asserted states instead of relying on fixed sleeps.
82- Assert both visible UI state and mocked Gateway traffic for request-driven flows. For example, verify the expected count/row is visible and that `sessions.list` was called with the expected `search`, `offset`, and `limit`.
83- Use short sleeps only after assertions to make the captured video readable.
84- Store the generated video in the invocation's fresh allocated directory; do not commit it or remove older captures.