Use the Postman tool for interface testing – environment variables and request parameter formats!

Introduction

In the previous note, we mainly introduced the basic knowledge and basic functions of interface testing. This chapter mainly introduces how to use postman for interface testing.

Configure environment variables and global variables

Environment variables and global variables

In environment management, you can also click “Global” to add global variables. Environment variables only take effect when the environment is selected. Global variables take effect in any environment. Variables in the test set only take effect in the current test set. When test set variables, environment variables,

When global variables have duplicate variable names, the priority is: environment variables > global variables > test set variables.

Add environment variables: Set-add-Fill in environment variable information

We can set multiple variables in the environment for use in requests.

How to use environment variables: Select the environment and use {{variable name}} in the request URL or request body to use environment variables. Variables can be in various formats of the request body. Used in, but cannot be used directly in pre-request scripts (Pre-request Script) and post-request scripts (Tests).

Note: Environment variables only take effect when you select the environment in the upper right corner.

After selecting the environment variable, you can adjust it normally:

Add global variables: Settings-Global-Fill in global variable information

Examples of using global variables:

Now I have also found a lot of testing friends and created a communication group to share technology, sharing a lot of technical documents and video tutorials we collected.
If you don’t want to experience the feeling of not being able to find resources when studying on your own, having no one to answer your questions, and persisting for a few days before giving up.
You can join us to communicate. And there are many technical experts who have made certain achievements in automation, performance, security, test development, etc.
Share their experience, and also share many live lectures and technical salons
You can learn for free! Focus on it! Open source! ! !
QQ group number: 110685036

URL parameters

Params:

When there are many parameters in the request URL, it is inconvenient to add and view them. You can click the Params button under the URL input box to add variables and values in a table. After adding from the table, the variables and values will be automatically added to the URL.

Note: The parameters in the URL are connected through “?” and are automatically generated in the Params table in the form of key=values, as shown in the figure above.

Request parameter parsing

1. Request design

  • Authorization: If the interface requires authorization, you can set the authorization method (type) and authorization information on this page
  • Header: Request header, you can set the request type (Content-Type) and Cookie
  • Body: Request data
  • form-data: mixed form, supports uploading files; x-www-form-urlencoded: text form; raw: original format, supports JSON/XML format (can be selected later); binary: binary format, used to send binary data stream
  • Pre-request Script: Pre-request script, Javascript syntax, used to generate some dynamic data or do some processing before sending the request
  • Tests: post-request script, Javascript syntax, used to do some processing or assert results after the request is returned.

1.1 Request method for Postman to send request data in various formats (note: if you select a different request, Content-Type information will be automatically added to the header):

  • form-data: hybrid form, supports uploading files;
  • x-www-form-urlencoded: text form;
  • raw: original format, supports JSON/XML format (can be selected later);
  • binary: binary format, used to send binary data stream

Request parameter type (format)

The first type: form-data mixed form format parameter passing example (upload file – select file type, transfer text select text type):

form-data mainly uploads parameters in the form of key-value pairs, and can also upload files. When the uploaded field is a file, there will be Content-Type to describe the file type; content-disposition is used to describe some information about the field. ;

Supports post requests with multiple parameters:

View request body information:

Second type: x-www-form-urlencoded (text form) parameter passing example:

The biggest difference between this kind of parameter passing and form-data is that x-www-form-urlencode can only pass parameters in the form of key-value pairs and cannot upload files. At the same time, the parameters are separated by & amp; separate.

View request body information:

The obtained parameters are consistent with the requested parameters, and are connected with “&”.

raw: original format, supports json and xml format parameter passing examples:

This is relatively powerful and can upload files in any format. Specifically, you can upload text files, json files, xml files, html files, etc.

View request body information:

As you can see, the request body is in the form of a json string, and the request type is: application/json

The above is the analysis of the configuration of environment variables, request parameters and methods. We will continue to talk about postman assertions and methods of extracting parameters later.

END Today’s sharing ends here. If it helps you, leave a message! Like and follow to avoid getting lost!