Playwright Lab Manual and Instructor Notes
Playwright Lab Manual and Instructor Notes
This guide is for running a live lab based on the Playwright work completed in this repository.
It is designed to answer the questions that drove the plan:
- What is Playwright codegen and how should we use it?
- How do we move from generated draft code to readable tests?
- How do we debug failures with trace, screenshot, and video artifacts?
- What should be in browser tests vs lower-level tests?
- How can AI/agents help without lowering quality?
- How can we automate issue reproduction using Playwright and agents?
Audience and Outcomes
By the end of this lab, learners should be able to:
- Generate a Playwright draft test and explain why generated code is only a starting point.
- Refactor toward stable, semantic locators and intent-based assertions.
- Produce and inspect artifacts from an intentional failure.
- Classify test scenarios into the right test layer.
- Use an AI-assisted workflow with explicit human review gates.
Where the Supporting Material Lives
- End-to-end test docs:
tests/EndToEndTests/README.md - Test strategy page:
docs/explore/tests.md - Level 2 skill:
.claude/skills/playwright-dotnet-refactor/SKILL.md - Refactor prompt template:
.claude/skills/playwright-dotnet-refactor/assets/refactor-prompt-template.md - Issue repro skill:
.claude/skills/playwright-issue-repro-report/SKILL.md - Issue repro workflow:
.claude/skills/playwright-issue-repro-report/references/WORKFLOW.md - Issue prompt/comment templates:
.claude/skills/playwright-issue-repro-report/templates/
Lab Prerequisites
Run these once before the session:
dotnet build tests/EndToEndTests/EndToEndTests.csproj
pwsh tests/EndToEndTests/bin/Debug/net10.0/playwright.ps1 install
Sanity check (should pass with one intentionally skipped demo test):
dotnet test tests/EndToEndTests/EndToEndTests.csproj
Start the app for interactive codegen demos (separate terminal):
dotnet run --project src/Web/Web.csproj
Keep this terminal running while you execute codegen steps.
Suggested 75-Minute Flow
- 0-10 min: Framing and key questions.
- 10-25 min: Demo 1 (Codegen to cleaned test thinking).
- 25-45 min: Demo 2 (Intentional failure and artifacts).
- 45-60 min: Demo 3 (Test strategy and layer mapping).
- 60-72 min: Demo 4 (AI-assisted workflow).
- 72-75 min: Wrap-up and Q&A.
Instructor Script by Question
Question 1: What is Playwright codegen?
Instructor answer:
- Codegen records interactions and outputs runnable Playwright code.
- It is a drafting accelerator, not final test quality.
- We always refactor generated output to improve selector stability and readability.
Live steps:
- Ensure the app is running in a separate terminal:
dotnet run --project src/Web/Web.csproj
- Run codegen:
pwsh tests/EndToEndTests/bin/Debug/net10.0/playwright.ps1 codegen https://localhost:5001
In the browser, perform:
- Open home page.
- Click first Add to Basket.
- Click Basket.
- Confirm basket line item is visible.
Teaching notes:
- Call out any brittle selector the recorder chooses.
- Ask participants: “Would this selector survive a UI refactor?”
Question 2: How do we clean generated tests?
Instructor answer:
- Preserve user intent, then simplify.
- Prefer semantic locators: role, label/text, test-id.
- Keep assertions user-visible and behavior-oriented.
- Extract helpers only when they improve readability.
Show examples in repo:
tests/EndToEndTests/Playwright/CatalogTests.cstests/EndToEndTests/Playwright/Pages/CatalogPage.cs
Optional AI assist:
- Use
.claude/skills/playwright-dotnet-refactor/assets/refactor-prompt-template.md
Question 3: How do we debug failures with artifacts?
Instructor answer:
- We use intentional failure to practice diagnosis.
- Artifacts show what happened during the failed run.
- Trace is usually the fastest path to root cause.
Live steps:
- Temporarily remove
Skipfrom:tests/EndToEndTests/Playwright/BasketTests.cs
- Run only the failing scenario:
dotnet test tests/EndToEndTests/EndToEndTests.csproj --filter FullyQualifiedName~BasketTests.Cart_AddItem_ShowsExpectedTotal
- Inspect artifact folder:
TestResults/PlaywrightArtifacts/<test-name>-<timestamp>/failure.pngTestResults/PlaywrightArtifacts/<test-name>-<timestamp>/trace.zipTestResults/PlaywrightArtifacts/<test-name>-<timestamp>/video/
- Open trace locally:
pwsh tests/EndToEndTests/bin/Debug/net10.0/playwright.ps1 show-trace TestResults/PlaywrightArtifacts/<folder>/trace.zip
- Or use hosted viewer at https://trace.playwright.dev.
- Re-add
Skipafter demo to keep default suite green.
Talking point:
- These are execution artifacts, not visual regression baselines.
Question 4: What belongs in Playwright vs other tests?
Instructor answer:
- Playwright: critical user journeys and wiring confidence.
- Unit/integration/API: business rule permutations and contract detail.
Use the matrix from docs/explore/tests.md and ask participants to classify:
- Home page catalog render.
- Add to basket happy path.
- Discount edge combinations.
- API auth and payload contract.
Question 5: How should AI/agents be used safely?
Instructor answer:
- Agents accelerate exploration and first drafts.
- Human review is mandatory before run/merge.
- Guardrails: preserve intent, semantic locators, user-visible assertions.
Run this workflow:
- Ask agent to explore catalog flows.
- Ask for 3-5 scenario proposals and layer classification.
- Ask for one draft Playwright C# test.
- Human review/edit.
- Run targeted test.
- If failed, inspect artifacts.
- Ask agent to diagnose from outputs and trace observations.
Issue-to-Repro Demo (Skill-Driven, Low Copy/Paste)
Use this as an optional advanced segment when teaching issue triage workflows.
Reusable skill assets
- Skill:
.claude/skills/playwright-issue-repro-report/SKILL.md - Workflow reference:
.claude/skills/playwright-issue-repro-report/references/WORKFLOW.md - Repro prompt template:
.claude/skills/playwright-issue-repro-report/templates/issue-repro-prompt.md - Issue comment template:
.claude/skills/playwright-issue-repro-report/templates/issue-comment-template.md
Instructor flow
- Start from a real GitHub issue URL/number.
- Open
templates/issue-repro-prompt.mdand fill only issue-specific inputs. - Ask the agent to execute the filled prompt and produce:
- Repro status (reproduced/not reproduced/inconclusive)
- Deterministic repro steps
- Test snippet or file update proposal
- Artifact locations
- Run the targeted repro test command from agent output.
- Collect evidence from
TestResults/PlaywrightArtifacts/.... - Open
templates/issue-comment-template.mdand fill with actual repro results. - Post the comment with artifacts.
Posting artifacts to the GitHub issue
Option A: GitHub web UI (recommended for live demo)
- Open the issue comment box.
- Drag-and-drop
failure.pngand a zipped video artifact. - Paste the populated comment template text.
- Include trace path or hosted link instructions.
Option B: GitHub CLI
- Save populated comment body to a local markdown file.
- Ensure artifact links are reachable URLs.
- Post:
gh issue comment <issue-number> --body-file <comment-file>.md
Evidence quality checklist
- Repro status clearly stated.
- Expected vs observed behavior both documented.
- Screenshot included for visual proof.
- Trace included for timeline/root-cause analysis.
- Next action and owner suggested.
Demo Command Block (Copy/Paste)
# Terminal 1 (keep running for codegen demos)
dotnet run --project src/Web/Web.csproj
# Terminal 2
dotnet build tests/EndToEndTests/EndToEndTests.csproj
pwsh tests/EndToEndTests/bin/Debug/net10.0/playwright.ps1 install
dotnet test tests/EndToEndTests/EndToEndTests.csproj
pwsh tests/EndToEndTests/bin/Debug/net10.0/playwright.ps1 codegen https://localhost:5001
dotnet test tests/EndToEndTests/EndToEndTests.csproj --filter FullyQualifiedName~CatalogTests
dotnet test tests/EndToEndTests/EndToEndTests.csproj --filter FullyQualifiedName~BasketTests.Cart_AddItem_ShowsExpectedTotal
# Optional: post issue comment from CLI after preparing comment markdown
# gh issue comment <issue-number> --body-file <comment-file>.md
After finishing interactive demos, stop the running app with Ctrl+C in Terminal 1.
Facilitation Notes
- Keep one terminal for commands and one editor window for code review.
- Narrate intent before each command (why this step exists).
- Pause after each demo to collect one “what changed confidence” reflection.
- Timebox deep debugging rabbit holes; prioritize workflow learning.
Common Pitfalls and Recovery
- Browser not installed:
- Re-run
pwsh tests/EndToEndTests/bin/Debug/net10.0/playwright.ps1 install.
- Re-run
- HTTPS/localhost issues:
- Ensure app starts from test fixture and wait for startup.
- Flaky locator from generated code:
- Replace with role/text/test-id locator.
- Suite left red after artifact demo:
- Restore
Skipon intentional failure test.
- Restore
Debrief Questions
- Which generated selector looked most brittle, and how did you improve it?
- What signal in trace/screenshot gave the fastest clue?
- Which scenario should move out of browser tests first and why?
- Where did AI save time, and where was human judgment essential?
Completion Criteria for This Lab
- Participants can explain codegen as draft-first workflow.
- Participants can run and inspect failure artifacts.
- Participants can classify scenarios by test layer.
- Participants can apply AI-assisted workflow with guardrails.