Module L1-M07 exercises: Reusable test framework and UI test pack for ShopEasy chat v2

Study time
≈ 14 h (estimate)
Updated
2026-11-03
Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Estimated time: ~14 hours for someone new to Python (an estimate, not yet measured with real learners). Starter file: code-labs/l1-m07/exercises/test_chat_v2.py.

Main practical exercise

Business context

The ShopEasy frontend team (fictional) has rewritten the chat page (v2) "to make it leaner". Before v2 goes to production, you are given two jobs: bring the aiqa framework into a state the whole team can use (a smoke group, CI, reports), and write a UI test pack for v2.

Input data

  • Expected behaviour of the chat page: the same as v1 (the table in L03 section 4.5), plus two requirements: a message longer than 2000 characters is rejected with an error message, neither sent nor silently truncated (contract C6 of L1-M04; v1 does exactly that), and the page has no horizontal scroll bar with any answer.
  • Running v2: AIQA_UI_VERSION=v2 python -m pytest exercises/test_chat_v2.py (PowerShell: $env:AIQA_UI_VERSION="v2", then run pytest). When you are done, remove this variable (unset AIQA_UI_VERSION; PowerShell: Remove-Item Env:AIQA_UI_VERSION), otherwise every later run, including tests/ui, runs on v2. When you check AC1, set AIQA_UI_VERSION=v1 explicitly. The fake backend has ready-made rules in DEMO_RULES in src/aiqa/chat_app/server.py.
  • Black-box rule: test the page through the browser. Do not read static/v2.html to find bugs; use it after writing the tests, to explain the cause in the defect report.

Tasks

  1. UI test pack for v2. Write tests in exercises/test_chat_v2.py. The lesson's test suite (tests/ui) is the starting point, but it is not enough: v2 has bugs that suite does not catch. Use locators based on roles or labels, and expect(...) instead of sleep.
  2. Smoke group and report. Register the smoke marker (L01), choose the smoke set, then run: python -m pytest -m smoke --junitxml=reports/smoke.xml and python report.py reports/smoke.xml.
  3. CI. Put the workflow into .github/workflows/ in your own repository, add a smoke job that runs before unit, and keep the live job manual. If the framework sits in a subdirectory, add defaults: run: working-directory: <directory> (an example is at the top of ci/github-actions.yml). If you have a GitHub account, push and attach the link to the run. If not, rerun the workflow's commands locally (L04 section 5.1) and state clearly "not run on GitHub".
  4. Verify your tests. For any configuration tests you add, run python mutate.py. For the UI pack, prove that each test is green on v1 and red on v2 precisely because of the bug it targets.
  5. Defect report reports/v2-ui-defects.md: each bug has reproduction steps, expected, actual, severity (security bugs rated according to OWASP LLM05), and the cause in v2.html (after the tests are written).
  6. Least privilege (mandatory): 3-5 sentences: how would you configure an AI assistant that can run commands in this project (permissions, the sources it may read, what you approve by hand), and why?
  7. AI usage log (if you use an AI assistant): what you asked it to do, which parts you kept, which parts you fixed, and how you verified them.

Deliverables

exercises/test_chat_v2.py
pyproject.toml (marker smoke) + test đã gắn smoke
reports/smoke.xml + reports/smoke-summary.md
.github/workflows/aiqa.yml (+ link lần chạy, hoặc ghi chú "chưa chạy trên GitHub" kèm output chạy lại trên máy)
reports/v2-ui-defects.md
reports/least-privilege.md
reports/ai-usage.md (nếu có dùng)

In English: pyproject.toml with the smoke marker, plus the tests tagged smoke; the workflow file plus the link to the run, or the note "not run on GitHub" with the output of the local rerun; reports/ai-usage.md only if you used an AI assistant.

Acceptance criteria (mandatory)

# Criterion
AC1 Every UI test passes on v1 (AIQA_UI_VERSION=v1); every test that fails on v2 targets exactly one bug
AC2 No time.sleep in the UI tests; locators start from a role or a label (the selector li[data-role=...] inside role="log" is accepted)
AC3 At least 6 different v2 bugs found, of which at least 2 are not caught by the lesson's test suite (tests/ui)
AC4 The live job in the workflow still runs only by hand; secrets appear only in the live job
AC5 The JUnit report and the summary are real (not written by hand)
AC6 No real API key or real data in the submission

Scoring rubric (100 points)

Dimension 0 1 2 3 Weight
UI test design AC1 not met AC1 met, only repeats the lesson's test suite AC1-AC3 met; each test targets one behaviour As level 2, plus tests for behaviours the lesson's suite does not cover, combining page and server observations 25
Implementation Does not run Runs, but has sleep or brittle CSS locators AC2 met; fixtures used correctly As level 2, with clear failure messages, independent tests, runs with both v1 and v2 25
Framework and CI Missing A workflow exists but violates AC4 AC4, AC5 met; a smoke group exists As level 2, plus a real run on GitHub, or a complete local rerun with a note on the limits 10
Defect analysis AC3 not met 6 bugs, severity missing ≥ 6 bugs, each with reproduction and severity As level 2, plus a security bug rated correctly (LLM05) and at least one bug outside the table in L03 section 4.5 15
Reporting Missing Vague All fields present, reproducible Concise, with the cause in the code and a proposed fix 15
Verification and reflection Missing Generic Proves that each test is green on v1 and red on v2 As level 2, plus a mutation check or an AI usage log with concrete verification 10

Score per dimension = (level reached / 3) × weight. Mapping to the module: practical = UI test design + Implementation (50); applied QA analysis = Framework and CI + Defect analysis (25); review/reflection = Reporting + Verification and reflection (25).

Hints

Hint 1Running the lesson's test suite against v2 is the first step, not the last. Reread "Input data" and try the unusual outputs that the fake backend can return.
Hint 2For each requirement, is there a boundary the lesson's test suite has not tried?

Independent challenge (practical challenge)

There is no code to run. This assesses design skills.

Context: EduTalk (fictional) has a chat interface for speaking practice: learners record audio, the system calls a model to grade it and displays feedback as Markdown. The team wants CI to run the UI tests on every pull request and the live tests against the real model once a week.

Tasks:

  1. Design the framework structure (directories, markers, main fixtures) and the mock/live configuration.
  2. List 10 UI tests, including at least 2 tests for the LLM05 risk when rendering Markdown.
  3. Sketch the workflow (in words or in YAML) with a weekly job, a budget and reviewers.

Separate rubric (100 points, pass at ≥ 70):

Dimension 0 1 2 3 Weight
Framework Missing Mock and live not separated Configuration, markers, safe defaults As level 2, plus contract tests for mock and live 30
UI tests Missing Happy path only 10 tests covering waiting, error and history states As level 2, plus 2 concrete LLM05 tests (a javascript: link, HTML inside Markdown) 35
CI Missing Live runs automatically Live on a schedule, with a budget As level 2, plus an environment with reviewers and reports kept on failure 35

Rules

  • Do not use a real API key or real data in your submission. If you run the live job on GitHub, use a separate API key with a spend limit (L1-M03-L01).
  • Do not modify src/aiqa/chat_app/static/v2.html: it is the product under test.