30. Full-Stack API Testing with request Context

API Testing in Python with Playwright

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()

Task

  • Implement check_api_status(response, expected_status=200):
  • 1. Return response is not None and response.status == expected_status.
πŸ’‘Common doubts
Did you like the problem?
Lesson 30 of 37
Python
Loading code editor…
Next