postman for http interface test

There are many HTTP interface testing tools, and there are many ways to make HTTP requests, but they can be used directly, and the functions are well supported. As far as I have used it, postman is more familiar.

 

advantage:

1. Support use case management

2. Support get, post, file upload, response verification, variable management, environment parameter management and other functions

3. Support batch operation

4. Support use case export and import

5. Support cloud storage use case [paid user]

 

It can be said that POSTMAN satisfies most of the functions of the HTTP interface test, and only a few functions are not supported, such as: request process control; so much has been said before, let's take a look at the installation and use of POSTMAN.

 

1. What is POSTMAN

POSTMAN is a plug-in tool for Chrome. We can search and install it through the Chrome application store. After the installation is completed, a postman icon will be displayed on the desktop. Every time you click this icon, you can start the POSTNA interface.

After startup, it is the above interface. The left side is the directory structure used to manage the use case, and the right side is the parameters and response content of the request content of a specific use case; the default postman will come with a demo project called "POSTMAN Echo", which contains There are use case demos for various scenarios. For new students, you can learn how to use POSTMAN by viewing these demo use cases.

 

2. Create a new project

Directly click the add directory icon on the left column to add a new root directory, which is equivalent to creating a new project. We can store the use cases of a project or a module in this directory, and under the root directory we also You can create sub-directories to subdivide functional use cases, as shown in the following figure.

2. Add a use case

After creating the project directory, we can create a new use case. Specifically, click the + sign in the right area to add a template of an empty use case, or copy an existing use case to achieve the purpose of creating a new use case. For two methods, see Down:

 

3. Add request information

The new use case request content is empty, we need to add the corresponding request information, this part of the operation is in the information area on the right, the general process is as follows:

 

  1. Choose a request method, such as: get or post
  2. Fill in the requested url, such as: http://www.baidu.com
  3. If it is get, the request parameters are written directly after the url, with ? connect
  4. If it is a post, the request is added to the body
  5. Click "send" to send the request
  6. View request response content

 

 

4, post request parameters

The main feature of the post request is to put the request data in the body, not after the url

The above example is to transmit common parameters by post. If we need to send a request with a file, we need to change the request format, as follows:

Note that the content marked in the red box above must correspond.

 

5. Add header information

Sometimes some specific header information is required when requesting. Postman can also support it perfectly. You can set the request header information directly by clicking the Headers tag.

 

6. Preprocessing and result checking

Preprocessing is mainly to set some environment variables and the like, which is equivalent to data initialization; as shown in the figure:

Response processing is to analyze and verify the response results, such as checking whether the code is 200, whether the content is equal to a specific value, whether it contains a specific value, and so on.

 

Because both preprocessing and result checking use js as the scripting language, you can also perform any scenarios that js can implement to assist in testing.

 

7. Global variables and environment variables

We can assign global variables in the two script environments of preprocessing and result processing, and we can use them directly in specific test data. The specific usage method is: {{variable_key}}; for example, you can use it in the script Set global variables:

 

[javascript]  view plain copy  
 
  1. postman.setGlobalVariable("username""tester");  

Then I can use it like this in the use case data item, {{username}}, to represent the specific tester value, see the following figure for details

 

The setting of environment variables is basically the same as that of global variables, except that we have another entry for setting environment variables, that is, in the environment configuration management, we can pre-establish a set of variables related to the environment. Select the corresponding environment variable template before the test requirement is executed, so that the environment difference between the test server and the online server can be quickly switched. For example: configure 2 sets of environment variable templates, one set of url is the test environment, the other set is the online environment, we can choose different environment variable templates according to different test objects, and no longer need to modify the url in the test data.

Above, we extract the requested host, and then use different url values ​​in different environment variable templates. Later, we can perform corresponding request tests by selecting different environment variable templates.

8. Export use cases as code

Another great thing about POSTMAN is to export the use case as CODE, that is, if you have finished writing the use case, you can click "Generate Code" to generate the code with one click, and there are many languages ​​and class libraries to choose from, the frame is great Great!

 

9. Batch execution of use cases

Finally, let's take a look at the batch execution function of POSTMAN. This function is handled by a separate runner. We need to operate in another interface, as follows:

Click the above buttons in turn, the runer interface will appear, just click "Start Test" as follows

 

 

 

 

http://blog.csdn.net/five3/article/details/53021084

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326272447&siteId=291194637