Several common skills of postman

Single interface test

For a single interface, you can directly use the developer tools in the Chrome browser, and then select copy as curl, and then use import--->paste raw text in postman, and then import all the request parameters of the interface to be generated, from header to form form.

 

 

The following is the effect after import:

 

Manage multiple interfaces

You can use postman's collection, which is something that Postman makes to manage multiple related interfaces.

This group of interfaces can use some common parameters, such as the following figure:

 

Public variables can be used. The method of using these variables is { {XXX}}, just add them where necessary, but you need to pay attention to the validity within the scope of the collection.

Postman provides multiple authentication methods here. The most commonly used is to use the parent collection authentication, or add some key id parameters in the header, such as the setting shown in the figure below, so that we can use multiple interfaces instead of one by one. Set the key id.

 

Crawl network request

Judging from the introduction of the official website, only http crawling is currently supported. HTTPS is still under development. It can be supported after one quarter of the development progress of the official website. Of course, it does not support HTTPS. At present, this crawling is rather tasteless. Of course, it also supports mobile-side crawling, which is meaningless now.

The way postman grabs network requests is divided into 2 steps: the first step: postman's own settings, as shown in the figure below.

 

Step 2: Set the corresponding proxy in your browser, such as Chrome browser, my side is Mac, and you can directly modify the IE settings under Windows.

 

----------

Attachment: The development progress of the official website: In this mid Term, his own notes indicate that it is a quarterly completion progress.

 

Quickly import interface requests to postman

Postman does not support batch import of multiple curl interfaces. This is an official statement, and it seems that there is no standard format for batch import. So it's not easy to use. However, there are curves to save the country. http://www.51testing.com/html/87/n-4462487.html

If you are interested, I studied it myself, but I didn't look at it carefully.

 

 

 Generate token

The postman can generate the token before the interface request, and then add it to the request header.

But the script needs to be written in JS, the following is the sample code:

// JWT generation script adapted from// https://gist.github.com/corbanb/db03150abbe899285d6a86cc480f674dvar jwtSecret = pm.environment.get('jwt_secret') || ''// Set headers for JWTvar header = {  'typ': 'JWT',  'alg': 'HS256'};// Prepare timestamp in secondsvar currentTimestamp = Math.floor(Date.now() / 1000)var data = {  'iss': pm.environment.get('jwt_iss') || '',  'ist': pm.environment.get('jwt_ist') || '',  'iat': currentTimestamp,  'exp': currentTimestamp + 30, // expiry time is 30 seconds from time of creation  'jti': 'jwt_nonce'}function base64url(source) {    // Encode in classical base64    encodedSource = CryptoJS.enc.Base64.stringify(source)        // Remove padding equal characters    encodedSource = encodedSource.replace(/=+$/, '')        // Replace characters according to base64url specifications    encodedSource = encodedSource.replace(/\+/g, '-')    encodedSource = encodedSource.replace(/\//g, '_')        return encodedSource}// encode headervar stringifiedHeader = CryptoJS.enc.Utf8.parse(JSON.stringify(header))var encodedHeader = base64url(stringifiedHeader)// encode datavar stringifiedData = CryptoJS.enc.Utf8.parse(JSON.stringify(data))var encodedData = base64url(stringifiedData)// build tokenvar token = `${encodedHeader}.${encodedData}`// sign tokenvar signature = CryptoJS.HmacSHA256(token, jwtSecret)signature = base64url(signature)var signedToken = `${token}.${signature}`pm.environment.set('jwt_signed', signedToken)console.log('Signed and encoded JWT', signedToken)

This will run before making the request

 

The problem is that you need to use JS to write scripts. This is a bit troublesome, because most tokens are written by back-end business, that is, basically Java code. Java code is developed for you, and you have to change it to JS code. This requirement is a bit high.

If we just create a variable or get a system variable, that's simple, there are shortcut keys on the right.

 

Assert interface request result

Postman can also make assertions. Assertions are to do Tests directly after the interface request is completed, so that the result of the interface request can be directly asserted, such as containing key parameters, or status codes, or response time. The following figure shows the creation after clicking directly from the right.

 

Batch execution of multiple interface requests

Postman can also execute multiple interface requests in batches. In this way, it will be convenient for us to perform automated testing of the corresponding interfaces after executing multiple interfaces at once.

His batch method is to select collection and run the collection directly.

 

In the corresponding collection runner, just click run.

 

If necessary, you can also set parameters, such as executing it several times, retaining the response results, or selecting the corresponding environment, such as development environment, test environment, pre-release environment, online environment, etc.

other

1. Postman can also set up a mock server. This mock means that the current server has not been developed and is temporary using postman. When postman is used to initiate the corresponding interface request, postman will directly intercept it and then go through the set mock server. After processing, return the corresponding response.

This is the advanced usage of postman. Postma allows you to register an account. Because of network reasons, registration failure here will not be demonstrated.

2. These writing methods in postman can refer to the template, which is the position shown in the figure below. After obtaining it directly, it is better than drawing a gourd. Generally speaking, the speed of postman development is still very fast, and the functions are getting more and more powerful.

 

3. Postman also supports integration with Jenkins. The way of integration is to let Jenkins execute the tool under the postman command line, Newman.

Guess you like

Origin blog.csdn.net/JineD/article/details/111522292