test with postman code example

Example 1: how do you test in postman

I mostly use preInstalled js testScripts in postman
in Tests tab. Basically test will execute after
response received for verification. So when I send
the request by clicking SEND postman runs the test
script and after response gives me test result

Some of the snippets I use:

Get an environment variable
Set an environment variable
Clear a environment variable
Clear a global veriable
Get a global variable
Set a global variable
Send a request
Response convert xml to json
Response time is less than
etc.

Example:
pm.test("Status test", function () {
    pm.response.to.have.status(200);
});

pm.test("response must be valid and have a body", function () {
     pm.response.to.be.ok;
     pm.response.to.be.withBody;
     pm.response.to.be.json;
});

Example 2: how to test response in postman

Basicall we are checking response body
to verify if request matches with response.
In the response we are verifying
(body, status code, header, response time,
 test structure of json against the given jsonSchema)

Tags:

Misc Example