Playwright Python 8 | 1st API Test

Publié le: 01 juillet 2025
sur la chaîne: Automation Step by Step
14,249
149

WHAT is API Testing
API testing means sending HTTP requests (like GET, POST, PUT, DELETE) to application's backend and verifying the response (status code, body, headers)

We test:
Is the response correct?
Is the status code right? (e.g., 200 OK, 404 Not Found)
Is the returned response body valid?
-
DEMO - How to send API Requests
Step 1 - Create a file under tests folder test_api_get.py
Step 2 - Write first API test
Step 3 - Run the test pytest tests/test_api_get.py
can add -s to show the output
-
def test_api_get_request(playwright):
request = playwright.request.new_context()
response = request.get("https://jsonplaceholder.typicode.com/...")

assert response.status == 200
json_data = response.json()
print(json_data)
assert json_data["id"] == 1
request.dispose()
-

Send request with headers

response = request.get(
"https://jsonplaceholder.typicode.com/...",
headers={"Authorization": "Bearer your_token_here", "X-Api-Key": "abc123"},
)

-

Send create headers block separately

request = playwright.request.new_context(
extra_http_headers={
"Authorization": "Bearer your_token_here",
"Accept": "application/json",
"X-Custom-Header": "value123"
}

response = request.get("https://api.example.com/protected-end...")
-

How to assert Responses

Print response status
print("Status Code:", response.status)

Print the JSON response body
print("Response JSON:", response.json())

Validate values inside JSON
assert json_data["id"] == 1
assert json_data["userId"] == 1
print("ID and userId match expected values")





-



▬▬▬▬▬▬▬

Share with all who may need this

If my work has helped you, consider helping any animal near you, in any way you can

Never Stop Learning
Raghav Pal



▬▬▬▬ USEFUL LINKS ▬▬▬▬


✅ ALL TUTORIALS - https://AutomationStepByStep.com/


Tools & Tips - https://bit.ly/2oBfwoR
QnA Friday - https://bit.ly/2NgwGpw
Sunday Special - https://bit.ly/2wB23BO



🙌 Connect with Raghav:

Ask Raghav: https://bit.ly/2CoJGWf
GitHub: https://github.com/Raghav-Pal
Udemy: https://www.udemy.com/user/raghav-pal-3/



Shorts Eng - https://bit.ly/3H9bifV

➡️ Subscribe for more videos:    / @raghavpal  


Sur cette page du site, vous pouvez voir la vidéo en ligne Playwright Python 8 | 1st API Test durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Automation Step by Step 01 juillet 2025, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 14,249 fois et il a aimé 149 téléspectateurs. Bon visionnage!