Termwright TUI Testing (Focused)
Quick, agent-friendly workflow for testing terminal UIs with minimal ceremony.
First Step: Discover Features
termwright info steps # List step types
termwright info steps waitForText # Specific step syntax
termwright info keys # Valid key names
termwright info protocols # Daemon methods
Discovery Quick Reference
| Need | Command |
|---|---|
| Step syntax | termwright info steps <step> |
| Key names | termwright info keys |
| Protocol method | termwright info protocols <method> |
| Capabilities | termwright info capabilities |
| JSON output | Add --json to any info command |
Core Workflow (Preferred)
- Write a step file (YAML or JSON)
- Run with
run-steps - Inspect artifacts and trace on failure
Example Step File
session:
command: ["vim", "test.txt"]
cols: 120
rows: 40
steps:
- waitForText: {text: "VIM", timeoutMs: 5000}
- press: {key: i}
- type: {text: "Hello"}
- press: {key: Escape}
- expectText: {text: "Hello"}
- notExpectText: {text: "ERROR"}
- screenshot: {name: "vim-content"}
artifacts:
mode: onFailure
dir: ./termwright-artifacts
Run the Test
termwright run-steps --trace test.yaml
Negative Assertions
Check that content is NOT present:
steps:
- notExpectText: {text: "ERROR"} # Immediate check
- notExpectPattern: {pattern: "fail|crash"} # Regex check
- waitForTextGone: {text: "Loading...", timeoutMs: 5000} # Wait to disappear
Artifact/Trace Behavior
onFailure: savefailure-###-screen.txt/jsononly when a step failsalways: savestep-###-screen.txt/jsonafter every stepoff: no artifacts (screenshots require non-off mode)--trace: addstrace.jsonwith step timings and hashes
One-off Commands (Exec)
SOCK=$(termwright daemon --background -- vim test.txt)
termwright exec --socket "$SOCK" --method screen --params '{"format":"text"}'
termwright exec --socket "$SOCK" --method close
Parallel Sessions (Hub)
termwright hub start --count 3 --output sessions.json -- ./my-app
termwright hub stop --input sessions.json
Debugging Tips
- Use
waitForIdlebefore assertions to reduce flakiness - Check
screen.jsonfor color/cursor mismatches - Use
--tracewhen diagnosing timing issues - Run
termwright info stepsto discover available step types
