Interface parameterization, return value transfer

Interface parameterization, during the software testing interview process, is often asked:

Simple interface testing process, multiple interface calls, parameter transfer between interfaces, input parameters of interface return values, how to deal with interfaces that do not respond for a long time, the difference between interface use cases and functional use cases, etc., when using postman for interface testing, in In the test of multiple interfaces, the return value of the previous interface is required as the input parameter of the next interface

1. When requesting, you will encounter a request that requires a TOKEN. You need to request a request to obtain a TOKEN first, and then paste the returned value to the place where you want to request next time. This is very troublesome.

You can use this interface parameterization method to deal with

1. Get the return value of the previous interface and store it in a variable

2. Set the return value as an environment variable or a global variable globals

3. Set the parameter form of the next interface

Specific operation process

Send the interface successfully, receive the response data
and get the json data in the response message

var json = JSON.parse(responseBody); 

set global variables

pm.globals.set("appId",jsonData.data.appId);
pm.globals.set("scene",jsonData.data.scene);

Run the first interface first and save the value of the environment variable

Reference variables in the second interface, generally use {} to get values

Use { {scene}} and { {appId}} to get the values ​​of scene and appId

If it is a get request, it is directly quoted in {{variable name}} in the url

Post request at that time, quoted in the body

2. Regular expression extractor

The token value in the response data of a login interface,

It needs to be used in subsequent interfaces (for example: creating users).

Response data after jmeter login:

{
 "id":167,
 "username":"laownag",
  "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InhpYW9oZWkiLCJpZCI6NzY3LCJpYXQiOjE1OTIzNjQ3OTksImV4cCI6MTY3ODc2NDc5OX0.ObD1Qr4WPpF_AZW8AR0joSKTrYArKnPoq0Fbtrhsp44"
}

Select RegExpTester (regular expression tester) in the view result tree,

Enter the regular expression to extract the value and click Test to check whether the data can be extracted.

After the login interface is sent, right click to add --> select post processor --> regular expression extractor

The value filled in by the regular expression extractor
insert image description here

Regular expression value: Since the obtained token value starts with "token":" in the login response data, the middle () is filled with a regular expression and ends with ".

Regular expression comment: Multiple regular expressions can be written, separated by commas

. means match any character

Indicates matching one or more, and cannot match empty characters
Indicates matching zero or more, can match empty characters
? Indicates matching 0 or 1 time

Template explanation: 1 11 means to take the value of the first regular expression, use 1 11,2 22 for multiple regular expressions

Matching numbers: 0 means random value; 1 means the first value; 2 means the second value...

Default value: If the regular expression does not match a value (the regular expression is wrongly written), the default value is used

Use ${variable name} in the interface request that needs to be called

The variable name value set by the calling regex extractor

Finally, I would like to thank everyone who has read my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, you can take it away if you need it:

insert image description here

Software testing interview applet

The software test question bank maxed out by millions of people! ! ! Who is who knows! ! ! The most comprehensive quiz mini program on the whole network, you can use your mobile phone to do the quizzes, on the subway or on the bus, roll it up!

The following interview question sections are covered:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. web, app, interface automation, 7. performance testing, 8. programming basics, 9. hr interview questions, 10. open test questions, 11. security testing, 12. computer basics

These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can help you too!

Guess you like

Origin blog.csdn.net/lzz718719/article/details/132481948