Postman assertions/handling of environment variables

Source: Internet
Author: User

We do interface testing with an assertion operation, and a variable is used frequently, which can be handled with environment variables.

Directory

1. The assertion of Postman

2. Environment variables of postman

1. The assertion of Postman

Also take Postman's login interface as an example, click the response Body:contain string on the right side of postman to see which strings are included in the last request interface and can be used as assertions, such as:

If you want to use the field of a response as an accurate assertion, such as a response to a Json string, click Response Body:json Value check on the right side of postman, then find the field you want to assert by using the JSON value method, and then process

2. Environment variables of postman

The first: variables are frequently used, such as IP and port numbers, and can be processed using environment variables.

Click the settings icon, add a variable, add a temporary environment variable, fill in the key and value, select the environment variable to add, call in {{XX}} format

Second: Temporary environment variables need each time a specific choice, more trouble, can be set to global environment variables

Same as adding temporary environment variables, but when added, select Globle to add, other consistent, but no specific selection

Third: sometimes want to extract the result of the last request as a parameter of the next request, this with the jpress delete interface as an example, first to get the new ID, and then to delete

The first step: fill in the following code in the test where you want to get the response result request

var jsondata = json.parse (responsebody);p ostman.setenvironmentvariable ("id", jsondata.data);

 

 

Step Two: Add environment variables

When you perform the delete interface, you can click Add, then Delete, or you may not succeed

Similarly, it can be set as a global variable in the form of other operations consistent with previous

Postman assertions/handling of environment variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.