By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
The model is fine. The endpoint is fine. The bug is in the UI: the answer streams in, the component re-renders on every token, the 'Send' button re-enables too early, and clicking it mid-stream sends a duplicate question. Playwright is how you catch that class of bug.
| Behaviour | What to assert | Why it breaks |
|---|---|---|
| Streaming render | Text grows, then stops; final text is complete | Assertions run against a half-rendered answer |
| Send disabled during stream | Button is disabled until the stream ends | Rapid clicks duplicate the request and double the cost |
| Citations / sources UI | Source chips appear and match the answer | Sources render after the text, so early assertions miss them |
| Error and retry states | A failed call shows a message and a retry that works | Silent failure leaves a blank bubble |
Never waitForTimeout. Wait for a stable condition: the spinner disappears, the send button re-enables, or a sentinel element appears.
# Python Playwright, sync API
from playwright.sync_api import expect
def ask(page, question: str):
page.get_by_placeholder("Ask Nova anything").fill(question)
page.get_by_role("button", name="Send").click()
# The UI removes the typing indicator when the stream completes
expect(page.get_by_test_id("typing-indicator")).to_have_count(0, timeout=30_000)
def test_answer_and_sources_render(page):
ask(page, "Can I return a sale item?")
answer = page.get_by_test_id("answer")
expect(answer).to_contain_text("14 days")
expect(page.get_by_test_id("source-chip").first).to_be_visible()
expect(page.get_by_role("button", name="Send")).to_be_enabled()UI tests should test the UI. Point the app at a stub server that returns a fixed answer slowly, in chunks, so the streaming path is exercised without a real model call. Keep one or two real end-to-end tests for the integration, and mock everything else.
def test_error_state(page, stub_server):
stub_server.fail_next(503)
ask(page, "Can I return a sale item?")
expect(page.get_by_role("alert")).to_contain_text("try again")
expect(page.get_by_role("button", name="Retry")).to_be_enabled()Do not test answer quality in a browser test. It is slow, expensive and non-deterministic. Browser tests verify that quality reaches the user: the answer renders, sources attach, errors surface, and feedback buttons work. Quality lives in your eval suite.
Key takeaways
AI UIs add streaming, duplicate-send, source rendering and error-state bugs.
Wait for stable UI conditions, never fixed timeouts.
Use data-testid attributes; copy changes constantly.
Mock the model in UI tests; keep a couple of real end-to-end runs.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.