This project demonstrates real-world UI and API test automation using Playwright.
It showcases login session handling, end-to-end shopping workflow, and API testing (mocked to avoid external dependency failures).
- Login (executed once, session reused for all tests)
- Add product to cart
- Complete checkout process
The public RealWorld API is unreliable, so the project includes a mocked API workflow that:
- Logs in
- Creates an article
- Deletes the article
This demonstrates API request handling and validation without depending on unstable external servers.
| Tool | Purpose |
|---|---|
| Playwright | UI & API automation |
| Node.js / JavaScript | Test language and runtime |
| Storage State | Saves login session for reuse |
| Mock API | Stable API testing workflow |
playwright/
├── tests/
│ ├── setup-login.spec.js # Saves login session once
│ ├── login.spec.js # Skipped after session reuse
│ ├── add-to-cart.spec.js # UI test
│ ├── checkout.spec.js # UI test
│ └── api-products.spec.js # Mock API test
└── .auth/
└── user.json # Saved login session
playwright.config.js # Global Playwright config
setup-login.spec.jssigns into SauceDemo.- Playwright stores the authenticated session in:
playwright/.auth/user.json
- Other UI tests use this saved session → no repeated logins.
Benefits:
- Faster test runs
- Eliminates login flakiness
- Reflects industry best practice
npm installnpx playwright test playwright/tests/setup-login.spec.jsnpx playwright testnpx playwright test --ui| Test | What It Does | Why It Matters |
|---|---|---|
| Add to Cart | Chooses product → Adds to cart → Verifies badge count | Shows UI interactions & assertions |
| Checkout | Completes full purchase steps | Demonstrates end-to-end coverage |
| Session Save | Saves login session to file | Real QA environments use session reuse |
The mock API test demonstrates:
- Sending authenticated API requests
- Creating & deleting data
- Validating responses
This avoids failures caused by:
DNS errors, 404s, or offline public REST APIs.