Test Overview
This test checks if the backend API correctly processes a user login request. It verifies that the API returns the expected success message and status code, confirming the backend logic works as intended.
This test checks if the backend API correctly processes a user login request. It verifies that the API returns the expected success message and status code, confirming the backend logic works as intended.
import requests def test_user_login_api(): url = "https://example.com/api/login" payload = {"username": "testuser", "password": "testpass"} response = requests.post(url, json=payload) assert response.status_code == 200 json_data = response.json() assert json_data.get("message") == "Login successful" assert "token" in json_data if __name__ == "__main__": test_user_login_api()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test environment ready, network connection available | - | PASS |
| 2 | Sends POST request to https://example.com/api/login with username and password | Request sent to backend API endpoint | - | PASS |
| 3 | Receives response from API with status code and JSON body | Response received: status 200, body contains message and token | Check if status code is 200 | PASS |
| 4 | Parses JSON response and verifies 'message' equals 'Login successful' | JSON parsed, message field extracted | Assert message == 'Login successful' | PASS |
| 5 | Verifies that 'token' field exists in JSON response | JSON parsed, token field checked | Assert 'token' in response JSON | PASS |
| 6 | Test ends successfully | All assertions passed, backend logic validated | - | PASS |