当前位置:网站首页>Getting started with postman

Getting started with postman

2022-06-26 10:43:00 Erlin likes meat

Catalog

Postman The page layout  

postman Basic knowledge required for interface testing  

Postman Interface Association  

Postman Response assertion  

Postman A parameterized  

Postman random number  

Postman The monitor  

Postman Auto generate script language  

Reference material  


Postman The page layout  

PS: Different versions Postman The interface is slightly different , But each icon The meaning of has not changed much

Upper menu bar : 

Runner Run collection request  

Add New page  

Sender icon Grab api request  

Wrench icon Set up  

Left menu bar : 

Filter filter  

History Record request , In days  

Collections You can use items as sets , Easy to manage  

Intermediate request bar : 

Request method : Include get post put delete etc.

Request address : Including the agreement 、 domain name 、 Address of the interface  

Params and get Use it together  

Send send and download 

Save Save request  

The middle part : 

Authorization: authentication  

Headers: Request header  

Body: Request body  

Pre-request Script Request pre script  

Tests : Assertion  

Cookies : Management request related cookies 

Lower status bar : 

Hide the left menu bar  

Search for  

Console—— Display output results

Last request  

Change the display mode —— about 、 Switch up, down and back

postman Basic knowledge required for interface testing  

Necessary conditions for interface test : 

  • Address of the interface  
  • agreement  
  • Request mode  
  • Request header  
  • Request parameters  

Common request methods : 

  • GET 

  • POST 

  • PUT 

  • PATCH

  • DELETE

Format of parameter transfer : 

  • Request body submission  

  • Form submission  

Collection runner  How to run the test set

  • Select test set  

  • Choose a test environment  

  • Set the number of iterations iterations 

  • Set the interval between interfaces delay 

  • Show request log all fail 

  • Select parameters data file  

 

Postman Interface Association  

Connection way : 

  • Set the environment variable  

  • Set global variables  

  • Tests Set a variable  

Set a variable : stay pre-request scripts in , Choose the one below set variable 

Then rewrite it as needed variable_key&variable_value 

Can be scripted , Set up directly : 

pm.globals.set("variable_key", "variable_value"); 

pm.collectionVariables.set("variable_key", "variable_value"); 

pm.environment.set("variable_key", "variable_value"); 

Global variables are used in any environment , Still no environment It's OK to use it in . But in different environments, you can only use environment variables inside your own environment , You cannot use other environment specific environment variables . 

Use tests Assert setting variables ,cookies and session Return header present ,token There is a return body , Return to the message . 

Log in and return to token, obtain token 

stay tests in , Write the following statement : 

//  Get response data json object  

var Data = pm.response.json(); 

//  Extract... From the response data token 

var test = Data.token; 

//  Set up token For environment variables  

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

 

Postman Response assertion  

postman Several ways to respond to assertions  

  • Response body:contains string Verify whether the returned result contains a character  

  • Response body:is equal to a string Check the return result ( Whole ) Whether it is equal to the string  

  • Response body:JSON value check Verify whether a field value in the returned result is equal to a value  

  • Response header:content-type header check Verify whether the response header contains a string  

  • Response time is less than 200ms Verify that the response time is less than 200ms 

  • Status code:code is 200 Check whether the response header contains a value  

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

    pm.expect(pm.response.text()).to.include("string_you_want_to_search"); 

}); 

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

    var jsonData = pm.response.json(); 

    pm.expect(jsonData.value).to.eql(100); 

}); 

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

    pm.response.to.have.body("response_body_string"); 

}); 

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

    pm.response.to.have.header("Content-Type"); 

}); 

pm.test("Response time is less than 200ms", function () { 

    pm.expect(pm.response.responseTime).to.be.below(200); 

}); 

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

    pm.response.to.have.status(200); 

}); 


Postman A parameterized  

Main file formats :txt json csv 

Store data as txt csv json In file , have access to runner The introduction of the file , Conduct mass testing  

Be careful TXT Import format :

The first line refers to the variable name , Then each line is the corresponding value , Use English commas in the middle

Postman random number  

Using random numbers can be used in mass testing and automated testing , When transferring parameters to the same parameter that cannot be repeated , Ensure that the parameters are not repeated . 

Postman The monitor  

It can be tested regularly , And send the test results to the email . 

Postman Auto generate script language  

code- Choice language - Copy

Reference material  

Postman A complete course - Simple books (jianshu.com)

The most comprehensive postman Tool usage tutorial ! Collected - cloud + Community - Tencent cloud (tencent.com)

Introduction | Postman Learning Center

原网站

版权声明
本文为[Erlin likes meat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260948257857.html