0
0
Postmantesting~10 mins

Alert configuration in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if an alert is correctly triggered when an API response contains an error status. It verifies that the alert message matches the expected error message.

Test Code - Postman
Postman
pm.test("Alert triggers on error status", function () {
    pm.response.to.have.status(400);
    const jsonData = pm.response.json();
    pm.expect(jsonData.error).to.eql("Invalid request data");
    pm.environment.set("alertMessage", jsonData.error);
});
pm.test("Alert message is set correctly", function () {
    pm.expect(pm.environment.get("alertMessage")).to.eql("Invalid request data");
});
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts and sends API requestPostman sends request to API endpoint-PASS
2Checks if response status is 400 (error)Response received with status 400pm.response.to.have.status(400)PASS
3Parses JSON response and checks error messageResponse body contains {"error": "Invalid request data"}pm.expect(jsonData.error).to.eql("Invalid request data")PASS
4Sets environment variable 'alertMessage' with error messageEnvironment variable 'alertMessage' set to 'Invalid request data'-PASS
5Verifies environment variable 'alertMessage' matches expected messageEnvironment variable 'alertMessage' is 'Invalid request data'pm.expect(pm.environment.get("alertMessage")).to.eql("Invalid request data")PASS
Failure Scenario
Failing Condition: API response status is not 400 or error message differs
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test check first after receiving the API response?
AIf the response body is empty
BIf the response status is 400
CIf the alert message is displayed on screen
DIf the environment variable is cleared
Key Result
Always verify both the response status and the content of the response when testing alert triggers to ensure accurate detection of errors.