Interface test tool (postman)

1.0 user interface and steps



1.1 common data transfer formats in requests

1.1.1 request string in URL

Data type: String

Request method: get

Request header: / (not changed)

1.1.2 form

Data type: form

Sample data:

Request method: post

Request header:


1.1.3  json

Data type: json

Sample data:


Request method: post

Request header:


1.1.4 differences between forms and json

formThe most common post data submission method is the default browser data submission method
postThe most popular way of data transmission

two   case

2.1 query parameter cases

2.2 form


three   Use case management

3.1 creating test sets  


  Tags: you can adjust the order

4.0 assertions

4.1 definitions

Let the program replace people to judge whether the results of test case execution meet the expected process

4.2 postman assertion

'Xiao Wang'
'Xiao Wang'go to eat
'Xiao Wang'Go wash the dishes
'Xiao Wang'go to bed
'Xiao Wang'
'Xiao Wang'go to eat
'Xiao Wang'Go wash the dishes
'Xiao Wang'go to bed
username = input('enter one user name')
username go to eat
username Go wash the dishes
username go to bed

4.3 common assertions

4.3.1 assertion response status code

Sample code:
pm.test("Status code is 200", function () {;

pm.test is a method provided by postman. Its name is test

The function of pm.test is that when writing cesium script, if there is an error in the internal processing content of the method, it will not affect the operation of subsequent automation scripts

4.3.2 assert that the response data is json

pm.test("Your test name", function () {
    var jsonData = pm.response.json();

var Keyword to declare a variable

pm.test("Your test name", function () {

4.3.3 the assertion contains the specified string

pm.test("Body matches string", function () {

4.3.4 assert equal to specified string

pm.test("Body is correct", function () {"response_body_string");

Specific application: judge whether to return the specified json Response, such as determining whether the login is successful

pm.test("Wrong user name or password", function () {'{"status":-2,"msg":"Password error!"}');

Note: the problem of quotation marks

4.3.5 assertion response header information

pm.test("Content-Type is present", function () {"Content-Type");

4.3.6 assertion request succeeded

pm.test("Assertion request succeeded", function () {
    pm.expect(pm.response.code)[201, 202,200]);

five   variable

5.1 mapping in Python


5.2 global variables in postman

5.2.1 definitions

Global variables are globally unique and cannot be defined repeatedly. There are multiple environments, such as development environment, production environment and test environment.

5.2.1 setting

Manual setting

Note: it is not allowed to define variables repeatedly

Code settings

pm.globals.set("Variable name of global variable", "The value of the global variable");

stay tests The global variable setting is not effective after the request is sent

5.2.2 acquisition

Manual implementation

{{Global variable name}}

code implementation

// Gets the value corresponding to the global variable name
var name = pm.globals.get('name');

5.3 environment variables in postman

5.3.1 definitions

Between environment and environment, duplicate variables can be defined; An environment can contain multiple environment variables; In the current environment, it is not allowed to define variables repeatedly

5.3.2   set

Manual setting

  Code settings

pm.environment.set("subject", "test");

5.3.3   Get

Manual implementation

{{Variable name of environment variable}}

code implementation

//   Get environment variables
var subject = pm.environment.get("subject");

5.3.4   Attention

Similar to python's LEGB principle, environment variables take precedence over global variables

Tags: Testing PostMan

Posted on Wed, 22 Sep 2021 09:02:58 -0400 by Citizen