บทที่ 18 · Part 5 — Capstone
Workshop Booking Capstone
ประกอบ UI, API, auth, mocking, accessibility และ CI เป็น test plan สำหรับระบบจอง workshop แบบครบวงจร
Workshop Booking Capstone
Capstone นี้ไม่วัดว่าคุณเขียน locator ได้กี่แบบ แต่ให้ส่งมอบ test system ที่ทีมอื่นรัน, อ่าน report และเปลี่ยนต่อได้ โจทย์คือ Workshop Hub ซึ่งมี Organizer, Learner, Admin, REST API, reminder dependency และ browser UI คุณต้องเลือก evidence ที่พอดีกับ risk แทนการทำทุก scenario ผ่าน E2E
จบบทนี้คุณจะ
ประกอบ strategy, fixtures, POM, data, auth, API contracts, network control, accessibility, trace และ CI เป็น repository plan พร้อม acceptance criteria และอธิบาย trade-off ของ coverage ได้
Product Contract
ระบบตัวอย่างมี requirements:
- Organizer สร้างและเปิด workshop ที่ capacity 1–500
- Learner จองได้ 1 ครั้งต่อ workshop; ที่นั่งเต็มแล้วเข้า waitlist
- Learner ยกเลิกก่อน cutoff ที่ server กำหนด
- Organizer เห็น attendee count แต่ไม่เห็นข้อมูลเกิน role scope
- Admin ปิด workshop และระบบแจ้งผู้ได้รับผลกระทบ
- Reminder failure ไม่ rollback reservation แต่ UI ต้องบอกสถานะที่ถูกต้อง
- Browser support และ locale/timezone matrix มาจาก product policy ที่แนบกับ submission
ค่าขอบเขต 1–500 เป็น contract ของโจทย์เท่านั้น ระบบจริงต้องให้ product/domain owner กำหนดและ version
Evidence Architecture
Diagram แสดงว่า risk map เป็น input ไม่ใช่ tests ที่มีอยู่แล้ว Data/auth เป็น dependencies ที่แชร์ pattern ได้ แต่ state ต้อง isolate Report/CI เป็น consumer ของ API/UI evidence
Target Repository Layout
playwright.config.ts
playwright/.auth/ ignored credentials
src/
api/
workshop-routes.ts
reservation-routes.ts
schemas.ts
fixtures/
test.ts
recorded-api.ts
pom/
workshop-catalog-pom.ts
workshop-form-pom.ts
reservation-pom.ts
test-data/
builders.ts
tests/
auth/
learner.setup.ts
organizer.setup.ts
api/
workshops/create.spec.ts
reservations/reserve.spec.ts
authorization/roles.spec.ts
ui/
learner/reserve.spec.ts
learner/cancel.spec.ts
organizer/create.spec.ts
accessibility/catalog.spec.ts
visual/workshop-card.spec.ts
Layout เป็น course convention ปรับตาม repo ได้ แต่ route modules คืน raw response, POM แยก elements/actions/assertions, fixtures เป็นเจ้าของ lifecycle และ specs เป็นเจ้าของ behavior assertions
Minimum Test Matrix
| Capability | Required evidence |
|---|---|
| Create workshop | API success/schema, each constrained field, organizer UI happy path |
| Reserve seat | API success/post-condition, duplicate key, full→waitlist, learner UI journey |
| Authorization | 401, 403, cross-owner resource, hidden UI controls + direct API rejection |
| Cancellation | before cutoff success, after cutoff error contract, visible UI state |
| Reminder failure | route-controlled UI state + unmocked integration contract elsewhere |
| Accessibility | keyboard/focus test, scoped automated scan, small ARIA snapshot |
| Visual/mobile | focused card/dialog baseline, one responsive navigation behavior |
| Operations | first-retry trace, redacted exchanges, CI project and shard-ready data |
Concurrency ของ last seat ต้องมี service/database integration evidence เพิ่มนอก browser suite เพราะ Playwright API requests อย่างเดียวควบคุม transaction interleaving ไม่แม่นพอ Capstone ต้องระบุ gap และ owner ไม่เคลมเกินหลักฐาน
Tracer Bullet แรก
เริ่มจาก behavior เดียวทะลุ architecture:
test(
'BOOK-RESERVE-001 - reserves an available seat and shows it in My workshops',
{ tag: ['@smoke', '@reservations'] },
async ({ learnerPage, workshop }) => {
const catalog = createWorkshopCatalog({ page: learnerPage })
await test.step('Reserve the seeded workshop', async () => {
await catalog.actions.navigate()
await catalog.actions.reserve(workshop.title)
})
await test.step('Show one confirmed reservation', async () => {
await expect(
learnerPage.getByRole('heading', { name: 'Reservation confirmed' }),
).toBeVisible()
await learnerPage.goto('/my-workshops')
await expect(
learnerPage.getByRole('article').filter({ hasText: workshop.title }),
).toContainText('Confirmed')
})
},
)
ให้ tracer ผ่าน local/CI พร้อม trace/report/cleanup ก่อนขยาย negative cases จะเปิดปัญหา config, auth, data และ selectors เร็วกว่าการเขียน 40 specs แล้วค่อย integrate
Implementation Increments
- Foundation — pin 1.62.1, config Chromium, web server/base URL, scripts และ first tracer
- Data/Auth — builders, exact cleanup, learner/organizer setup projects และ ignored auth states
- API Contracts — route modules, Zod schemas, error/security assertions, recorded/redacted exchanges
- UI Interfaces — page/component objects เฉพาะ reuse ที่เกิดแล้ว, semantic locators, behavior steps
- Rare States — reminder error route, full/waitlist data, clock-controlled countdown
- Quality Axes — keyboard, axe, ARIA snapshot, focused visual and mobile project
- CI Scale — all browser policy, fail-on-flaky, artifacts, repeat/parallel audit แล้วจึง shard
ทุก increment ต้องรันได้และให้ evidence บางส่วน ไม่สร้าง framework หลายสัปดาห์ก่อนมี test จริง
Required Failure Drills
จงทำให้ test fail โดยตั้งใจและพิสูจน์ว่า artifact เพียงพอ:
- เปลี่ยน accessible name เพื่อดู strict locator/trace
- ให้ API คืน 422 แทน 201 แล้วดู redacted exchange
- ทำให้ 2 tests ใช้ reference เดียวเพื่อสังเกต parallel collision จากนั้นแก้ด้วย builder
- เปลี่ยน font/width เพื่อ review visual diff
- ให้ reminder route คืน 503 และตรวจ visible degraded state
- หมดอายุ auth state และตรวจ regeneration/401 diagnosis
Drill สำคัญเพราะ suite ถูกใช้ตอนสีแดง ถ้าทดสอบแต่ report สีเขียวเราไม่รู้ว่ามันช่วยแก้ defect ได้จริง
Submission Artifacts
- risk/behavior map พร้อม test seam และสิ่งที่ test ไม่พิสูจน์
- source tree และ README runbook local/CI
- config พร้อมเหตุผลของ browsers, retries, timeouts, workers และ tags
- tests ตาม minimum matrix โดยรันเดี่ยว/parallel/repeat ได้
- HTML report/trace จาก failure drill และตัวอย่าง redacted attachment
- CI workflow + merged report plan หากใช้ shards
- known gaps, issue owner และ review date
- upgrade note ที่อ้าง Playwright 1.62.1/release date และจุด re-check
Definition of Done
- ไม่มี CSS/XPath/positional selector เป็น primary strategy โดยไม่มีเหตุผล
- ทุก test มี unique data และไม่พึ่ง execution order
- POM shape เป็น
elements,actions,assertions - API errors ตรวจ status, code, schema/details และ no leakage
- Auth state ไม่ถูก commit; artifacts redact secret/data สำคัญ
- Rare dependency states deterministic แต่มี unmocked contract coverage
- Accessibility/visual/emulation claims ระบุขอบเขตตรง
- Retry-passed ทำ CI fail หรือเข้า triage policy ไม่ถูก normalize
- Build report บอก failing behavior/step และมี artifact พอวิเคราะห์
- Version/package/browser/image ถูก pin และ upgrade runbook ทำซ้ำได้
สรุปคอร์ส
Automated test suite ที่ดีคือระบบผลิต evidence: strategy เลือกคำถาม, fixtures/data/auth สร้างสภาวะ, Playwright ทำ interaction และ assertions, artifacts อธิบาย failure และ CI ทำให้ evidence reproducible เมื่อแต่ละชั้นมี ownership และขอบเขตชัด จำนวน tests จะตามความเสี่ยงแทนที่จะกลายเป็นเป้าหมายเอง