Skip to content

Waiting and assertions

Terminal output arrives asynchronously over the PTY. Rather than sleeping for fixed intervals, synchronize on the exact screen state or process event your test requires.

Goal Operation Default timeout class
Text, style, or link appears or disappears locator.expect() / locator.wait() (expect text, wait text) text (5000 ms)
Shell prompt ready after open waitReady (wait ready) ready (30000 ms)
Submitted shell command finishes waitCommand + expectOutput / expectExitCode command (30000 ms)
Directly launched program exits waitExit + expectExitCode exit (30000 ms)
Cursor, terminal mode, or color changes expectCursor, expectMode, expectColors text (5000 ms)
Window title, OSC 52 clipboard, or bell expectTitle / waitTitle, waitClipboard, expectBellCount / waitBell text (5000 ms)
Screen stops changing waitIdle (wait idle) idle (5000 ms)

waitIdle only confirms that no new visual changes arrived during the quiet window; it does not prove a command succeeded or finished rendering. Prefer locator assertions, waitCommand, or waitExit whenever possible.

locator.expect() retries until at least one selected match is visible. Pass not: true (not_=True in Python, --not on the CLI) or wait_hidden in Rust to wait until transient UI like a loading indicator disappears.

await terminal.getByText("Loading...").expect({ not: true, timeout: 10_000 });
await terminal
.getByText("Ready")
.withStyle({ foreground: "green" })
.expect();

In shell sessions (open), call waitCommand after submit before asserting expectOutput or expectExitCode. expectOutput checks the captured output of the last completed shell command (excluding the shell prompt itself) and accepts regex: true (--regex). In direct program sessions (run), call waitExit and expectExitCode.

await terminal.submit("printf 'build ok\\n'");
await terminal.waitCommand();
await terminal.expectOutput("build ok");
await terminal.expectExitCode(0);

Poll terminal emulator state directly in Rust without manual loops when testing TUI chrome, alternate-screen transitions, raw input modes, or dynamic OSC 4/10/11/12 color changes. expectCursor checks any combination of zero-based x, y, visible, and cursor shape ("block", "underline", "bar"). expectMode checks boolean terminal modes such as "alternate_screen", "bracketed_paste", "focus_events", "application_cursor", or mouse reporting modes. expectColors checks foreground, background, cursor color, or indexed palette entries.

await terminal.expectMode("alternate_screen", true);
await terminal.expectCursor({ x: 4, y: 2, visible: true, shape: "bar" });
await terminal.expectColors({
foreground: "#e6edf3",
palette: [[1, "#ff6b6b"]],
});

expectTitle and waitTitle match OSC 0 / OSC 2 window titles, with optional regex and not flags. waitClipboard() waits for the next OSC 52 clipboard update, or accepts a string or regular expression to wait until the clipboard matches specific content. waitBell() waits for the next BEL (\x07) event, while expectBellCount(count) waits until the cumulative session bell count reaches count.

When any assertion times out, tui-test attaches structured failure details (and optional exported artifacts) directly to the returned error; see traces and diagnostics.