QA
Junior~10 minAPI testingrequest fixtureStatus codesNegative tests

API: login happy path and negative cases

App: SwagShop, a practice e-commerce demo store (Saucedemo-style). Login: standard_user, locked_out_user, problem_user, performance_glitch_user / secret_sauce. REST API: tests call it as /api/... through the request fixture or page.request; GET /api lists every endpoint ↗.

Next scenario →

Interview scenario

"Before the UI suite we want API coverage of authentication. Hit POST /api/auth/login with the request fixture: a valid login must return a token and the user, a wrong password must be a 401, the locked-out user must be a 423, and GET /api/me without logging in must be a 401."

Acceptance criteria

  1. POST /api/auth/login with standard_user / secret_sauce: assert the response is OK, the body has a token and user.username is standard_user.
  2. A wrong password returns 401 with error.code invalid_credentials.
  3. locked_out_user returns 423 with error.code locked.
  4. GET /api/me before logging in returns 401.
tests/example.spec.tsPlaywright · TypeScript

Runs in your browser with a Playwright-compatible API: locators, auto-waiting actions, expect, imports between files and test.extend fixtures. Saved in this browser. Ctrl/⌘ + Enter runs.

Save your lab code to a GitHub repo in your name, automatically after every run.Sign in with GitHub
/sandbox/swagshopOpen ↗

Test output

Press Run tests to watch your code drive the practice app in the preview.

Reference solution

Try it yourself first. Then compare with the Playwright solution and the same test in Selenium Java with TestNG.