0
0
Postmantesting~10 mins

GraphQL body in Postman - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test sends a GraphQL query in the request body using Postman. It verifies that the response contains the expected data field with correct values.

Test Code - Postman Test Script
Postman
pm.test("GraphQL response contains user data", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.data).to.have.property('user');
    pm.expect(jsonData.data.user).to.have.property('id').that.is.a('string');
    pm.expect(jsonData.data.user).to.have.property('name').that.is.a('string');
});
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test startsPostman is ready with GraphQL request body set-PASS
2Send POST request with GraphQL query in bodyRequest sent to GraphQL endpoint with body containing query { user { id name } }-PASS
3Receive response from serverResponse received with JSON body containing data.user object-PASS
4Parse response JSONResponse body parsed into jsonData object-PASS
5Check if 'data' property existsjsonData contains 'data' keypm.expect(jsonData.data).to.have.property('user')PASS
6Check if 'user' object has 'id' property of type stringjsonData.data.user has 'id' key with string valuepm.expect(jsonData.data.user).to.have.property('id').that.is.a('string')PASS
7Check if 'user' object has 'name' property of type stringjsonData.data.user has 'name' key with string valuepm.expect(jsonData.data.user).to.have.property('name').that.is.a('string')PASS
8Test ends with all assertions passedAll expected fields verified in response-PASS
Failure Scenario
Failing Condition: Response JSON does not contain 'data.user' or 'id'/'name' fields are missing or not strings
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify first in the GraphQL response?
AThat the 'data' object contains a 'user' property
BThat the HTTP status code is 200
CThat the response time is less than 1 second
DThat the 'errors' field is empty
Key Result
Always verify the structure and data types of the GraphQL response fields to ensure the API returns the expected data format.