Playwright + Python · Lesson 30 of 37
Module 30: API Testing with Playwright Python
Your task
Implement check_api_status(response, expected_status=200):
Write it in the editor, then press Check answer (Ctrl + Enter).
def test_create_and_verify_user(playwright):
api_request = playwright.request.new_context(base_url="https://api.targetqa.com")
# POST create item:
payload = {"name": "Playwright Python Course", "status": "active"}
response = api_request.post("/api/v1/courses", data=payload)
assert response.status == 201
json_data = response.json()
assert json_data["name"] == "Playwright Python Course"
api_request.dispose()Playwright includes a world-class HTTP client called APIRequestContext. In this lesson, you will make GET, POST, and DELETE requests, validate JSON payloads, and combine API seeding with UI verification. Let's master API testing in Python!
Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
Playwright's APIRequestContext seamlessly shares cookies and authentication state with your BrowserContext, enabling hybrid API-to-UI workflows without re-authenticating.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___