Manuals / API Testing / Chapter 7

C · Automation & CI · intermediate · Week 4–6 · Chapter 7 of 11

Code-based API automation

Postman scales to a point; code scales further. Automate with Python requests, JavaScript fetch/axios, or Playwright APIRequestContext — pick one stack.

Path progress
57%

Step 1 of 4

Pick your stack

Python: requests + pytest. JS: fetch + Jest/Vitest. Playwright: request fixture for hybrid UI+API teams.

Pick your stackDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Pick your stackdrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

Example

# Python + pytest + requests
import requests

def test_get_user():
    r = requests.get("https://jsonplaceholder.typicode.com/users/1")
    assert r.status_code == 200
    assert "@" in r.json()["email"]

Do this now

Install stack. One test: GET users/1, assert status 200 and email contains @.

Was this step clear?
Chapter learning outcomes
  • requests / fetch patterns
  • pytest or Jest structure
  • Setup and teardown
  • Assertions on JSON

Clear these before you leave

Side quest

Hybrid awareness

Read Playwright API testing doc. Sketch one UI test that seeds via API.