Test Examples

As we understood from the previous section, Test scripts are executed after a request has been sent, and the server has received a response.

Here, we will discuss some examples of tests. Most of the examples are available in the snippets of the Postman. We can run multiple tests for a single request.

Environments

Setting an Environment Variable


Test Examples

We can also set a nested object as an environment variable:

Getting an Environment Variable


Test Examples

Clear an Environment Variable


Test Examples

Collection

Setting a Collection Variable

Get a Collection Variable

Clear a Collection Variable

Globals

Setting a Global Variable


Test Examples

Getting a Global Variable


Test Examples

Clear a Global Variable


Test Examples

Response Handling

Search for a String in Response Body

Check if Response Body is equal to a String

Check for a JSON Value

Check if Content-Type header is present

Response Time is less than 200 ms

Status code is 200

Code name contains a string

Successful POST request status code






Latest Courses