当前位置:网站首页>Postman -- use

Postman -- use

2022-07-02 10:23:00 Lost ~ know to return

Introduction and classification of interface testing

Interface test is a kind of test between system components
Excuse is a service provided by software to the outside , Used for data transmission
classification :
External interface : Test the interface between the tested system and the external system
Internal interface : Internal interfaces are only provided for internal interfaces ( Just test the positive example )
Internal interfaces are provided for external interfaces ( Full test )
Why software needs interfaces ?
Because the interface allows internal data to be modified externally
Why do interface tests :
Many systems are front end and rear end separated , The development progress is different , The interface developed at the beginning needs to be tested ,mock

Interface test essence : It is to test whether the interface can interact with data normally , Access control and exception scenarios

Interface testing process and use case design

Get api file , Get it through the bag grabbing tool , Familiar with interface business , Address of the interface , Authentication method , Enter the reference , The ginseng , Error code
Write use cases for interfaces , review
Example :
Input positive reference , The interface can return normally
Counter example :
The authentication code is empty , Authentication code error , The authentication code has expired
Parameter counter example :
The parameter is empty. , Wrong parameter type , Parameter length anomaly
Error code :
Other error scenarios :
Interface blacklist , Interface call times limit , Paging scene
Hello ! This is the first time you use Markdown Editor The welcome page shown . If you want to learn how to use Markdown Editor , You can read this article carefully , Get to know Markdown Basic grammar knowledge of .

POSTMAN Perform interface tests

Request page
params:get Request parameters
Body:post Request parameters
none: No parameters
form-data: Key value pairs can also support file transfer
x-www-form-urlencoded: Key value vs. parameter
raw:json,text,xml,html,js
binary: Pass parameters in binary mode
pre-request-script: Script before request
Tests: Assertion after request
cookies: Used to manage cookie Information
Cookie: Responsive cookie Information
Header: Response head
Test Result: assertion results
200: Status code
OK: State information
681ms: Interface response time
343B: Number of response sub sections
Response tab
Body: The data returned by the interface
Pretty: With json,xml.html Different formats return data information
Raw: View the returned data as text
PreView: View the corresponding data in the form of web pages

Interview questions :
Get and Post Differences in requests
1、get The request is to get data ,post Request general submission data
2、post Request ratio get Request security
The essential difference is that the way of parameter transmission is different ,:
get The transmission parameter is followed by ? Pass parameters in the same way , Between multiple parameters & link
post Request in body In the form of a form

problem :
Multiple environments , development environment , Test environment , Production environment
Interface Association : Manual association is required
Parameters need to be modified manually

postman Environment and global variables

environment variable : Environment variables are global variables
 Insert picture description here

Global variables : Variables that can be accessed in any interface

Gets the values of environment variables and global variables : adopt **{ { Variable name }}**

Interface Association :

json The extractor implements Interface Association

 First interface , Generate global variables 
//json To extract access_token Value 
// Convert the returned string format data into the form of an object 
var result = JSON.parse(responseBody);
console.log(result.access_token)
// Will get access_token Set to global variable 
pm.globals.set("access_token", result.access_token);
 The second interface : adopt {
    {
     Variable name }} call 

 Insert picture description here
Through regular expressions

 Insert picture description here

The regular expression extractor implements interface correlation

 First interface 
//  The regular expression extractor implements interface correlation , Represents a match 
var result = responseBody.match(new RegExp('"access_token":"(.*?)"'))
console.log(result[1])
// Set to global variable 
pm.globals.set("access_token", result[1]);
 The second interface 
{
    {
    access_token}}

Postman Built in dynamic parameters and customized dynamic parameters in

postman Built in dynamic parameters , Value method :
shortcoming : Cannot make assertions

{
    {
    $timestamp}} Generate timestamp of current time 
{
    {
    $randomint}} Generate 0-1000 Random number between 
{
    {
    $guid}}	 Generate a random guid character string 

Custom dynamic parameters are set between requests
pre-request-script: Script before request

//  Get the current timestamp manually 
times = Date.now();
//  Set to global variable 
pm.globals.set("times", times);

 Insert picture description here

postman The assertion of

Status code:Code is 200
Response body:Contains string : Check that the response character also contains the specified string 
Response body:json value check : Checking response json Value 
Response body:is equal to a string : Check that a response string is equal to 
Response headers:Content-Type header check : Check whether the response contains a response header 
Response time is less 200ms : Check request takes less than 200ms

Get custom parameters in assertions

  • Global variables
pm.test(" The check response contains the tag name ", function () {
    
    pm.expect(pm.response.text()).to.include(" Tyrant " + pm.globals("times"));
});

Global assertion

postman Batch run test cases

 Insert picture description here
 Insert picture description here
Save the file to the working directory
 Insert picture description here

 Insert picture description here

csv Document and json Handling of documents

csv file

1、 establish csv file ,
2、nopad++ open csv file , Write data files
 Insert picture description here

3、 Change the parameter to { {key value }}
 Insert picture description here
 Insert picture description here

4、 Modify assertion

5、 modify access_token

6、 Run test cases ,csv How to select files ,

json

data format ,
establish json File format , Write data as follows

[{
    "grancd_text":"chuihcuie","appname":"hjiioiojvioa","secret":"xxxxxxcccccxxxx","access_v":"jjioejionojo756790u90xxx"},{
    "grancd_text":"hioioa","appname":"jshdich","secret":"xxxxxxcccccxxxx","access_v":"nfihihia"},
{
    "grancd_text":"bdjkchi","appname":"hcuihi9","secret":"xxxxxxcccccxxxx","access_v":"fghj789uhghjb"}]

function

Must have an interface with a request header

Host Requested host address
Connection How to connect
Accept The data format received by the client
X-Request-With Asynchronous requests
User-Agent User type of client
Referer source
Cookie Cookie Information
Content-Type Format of request content

postman Interface Mock Service The server

mock simulation
The back-end interface has not been developed , The front-end business needs to call the back-end interface

postman Of Cookie authentication

What is? cookie
cookie Authentication principle
When the client accesses the server for the first time , Then the server will generate Cookie Information , And respond to the header set-cookie It's generated inside cookie The message is sent to the client
When the client first 2-N When accessing the server for the first time , Then the client will be in the request header cookie close cookie Information , So as to realize authentication

cookie The classification of :
conversation cookie: Save in memory , The downtime will be cleared automatically after the browser is closed
persistent cookie: Save on hard disk , The browser will not clear after closing , Only when the expiration time is up will it be cleared automatically
 Insert picture description here
token authentication
 Insert picture description here

 Insert picture description here
 Insert picture description here

Newman

postman It is designed for interface testing .
 Insert picture description here
newman Usage method :
Export use cases , Everywhere environment , Export global variables , Test data
 Insert picture description here
 Insert picture description here

postman+Newman+jenkins Implementing continuous integration

1、 New projects
2、 Set up a custom workspace
3、 perform windows Batch command for

 Insert picture description here

Interface test protocol

1、webservice agreement : Address of the interface :http://…?wsdl
soap agreement ,wsdl
restful The rules
get get data ,post Submit data ,put Modifying data ,delete Delete data

原网站

版权声明
本文为[Lost ~ know to return]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/183/202207020630096523.html