Postman use interface testing tools to do (b) - the environment variables and request parameters format

  introduction

  In a previous note we introduce the basic knowledge and basic functions of interface testing, this chapter describes how to use the postman do interface testing.

 

  Configuring the environment and global variables

Environment and global variables

  Environmental management can also click on the "Global" add global variables, environment variables only become effective when the environment if selected, global variables to take effect in any environment, the test set of variables is only effective on the current test set, when the test set variables, environment variables,

When global variables duplicate variable name, priority: environmental variables> Global Variables> test set variables.

 

Add the environment variable: set the environment variable information to fill -add-

 

 

We can set up multiple variables in the environment, for use in the request.

Usage Environment variables:  select an environment, using {{}} variable name to use environment variables, which can be used in a variety of formats request the Body, but not directly on the request before the script (Pre-request in the request URL or request in Body script) and request the script (Tests) are used.

Note: The environment variable is selected in the top right corner of the environment when we come into effect.

 

After an additional environment variable can be selected properly transferred through:

 

 

 

  Adding global variables: Set -Global- global variable information to fill in

 

 

 

 Examples of the use of global variables:

 

 

 

 

 

  URL parameters

Params

When the request URL parameters lot, convenient to add and view, you can click the button below URL entered Params box, in tabular form and add the variable values ​​from the addition of tables, variables and values ​​are automatically added to the URL.

 

Note: URL parameters by ligation to form key = values ​​in Params table generated automatically, as shown above, "?."

 

 

  Request parameter parsing

 1, request design

  • Authorization: If the interface requires authorization, you can set License (type) and authorization information on this page
  • Header: request header, the request may be provided type (Content-Type) and Cookie
  • Body: request data
  • form-data: mixing forms, supports uploading files; x-www-form-urlencoded: text form; raw: original format, supports JSON / XML format (hereinafter alternatively); binary: the binary format for transmitting a binary data stream
  • Pre-request Script: previous request script, Javascript syntaxes to generate some dynamic data or doing some processing before sending request
  • Tests: After the request script, Javascript syntax for doing some processing or assert the request returns the result 

   1.1 Postman transmission request data in various formats request method (Note: select a different request, however, will automatically add Content-Type information in the Header):

  • form-data: mixed forms, supports uploading files;
  • x-www-form-urlencoded: text form;
  • raw: original format, supports JSON / XML format (hereinafter optional);
  • binary: binary format for transmitting a binary data stream

 

  Request parameter type (format)

The first: form-data format parameter passing form mixed sample (upload files - to select the type of file, text selection text transfer type):

form-data mainly in the form of key-value pairs to upload parameters, but can also upload a file, when the file is uploaded field, there will be described the file Content-Type type; content-disposition, to illustrate some of the information fields ;

 

 

 

 

Support for multiple parameters of post requests:

 

 

View information request body:

 

 

 

 

The second: x-www-form-urlencoded (text form) Reference Example pass:

Transfer and form-data maximum difference of this parameter is, x-www-form-urlencode only in the form of key-value pairs transmission parameters, not upload files, while between the parameters & separated by delimiters.

 

 

View information request body:

 

 

 Get the same parameters and the parameters of the request, and the "&" consistent connection.

 

  raw: original format, and support json xml format transfer parameters example:

The more powerful, you can upload any file format specific text file you can upload text, json files, xml files, html files.

 

View information request body:

As can be seen, the body is json string request, the request type is: application / json

 

 

 

These are the environment variable configuration, request parameters and analytical methods, continue to talk about the method behind the postman assertion and extraction parameters.

 

Published 82 original articles · won praise 43 · views 180 000 +

Guess you like

Origin blog.csdn.net/liudinglong1989/article/details/104688563