postman interface test four

table of Contents

Other useful functions and tools

Group Collection

History

Implement multi-server version with environment variables

Postman supports the use of Environment environment variables to implement multi-server versions

Code generation tool

Test interface


Other useful functions and tools

Group Collection

At the beginning of a project, in order to facilitate subsequent organization and management, put multiple APIs that belong to the project in a group

So first go to create a new Collection: New -> Collection

After using it for a period of time, multiple grouping effects have been built:

The effect after a single group is expanded:

History

Postman supports history history, showing the recently used API: 

Implement multi-server version with environment variables

Existing Problems

During API testing, there are often multiple environments, corresponding to IP addresses (or domain names are also different)

such as:

  • Prod: http://116.62.25.57/ucows

  • Used to complete the development and release to the production environment

  • Dev: http://123.206.191.125/ucows

  • Test environment for online Development during development

  • LocalTest: http://192.168.0.140:80/ucows

  • Used for the local environment in the local area network that cooperates with the back-end developers during development, and is used for joint debugging API interfaces

During API testing, it is often necessary to manually modify the API address:

The efficiency is relatively low, and the address cannot be reserved before the address is changed.

In addition, it is not easy to identify which environment is based on different IP addresses (or domain names).

Postman supports the use of Environment environment variables to implement multi-server versions

Later, it was discovered that there are Environment and Global Variable in Postman, which are used to solve this problem and realize the management of different environments:

Obviously, it can be used to achieve dynamic implementation without manually modifying the server address in the URL to support different server environments:

  • Production environment

  • Development Development Environment

  • Local local area network environment

How to use Environment to implement multi-server version

or:

 

Environments are a group of variables & values, that allow you to quickly switch the context for your requests and collections.

Learn more about environments

You can declare a variable in an environment and give it a starting value, then use it in a request by putting the variable name within curly-braces. Create an environment to get started.

Enter Key and value:

After clicking Add:

[info] Where environment variables can be used

  • URL

  • URL params

  • Header values

  • form-data/url-encoded values

  • Raw body content

  • Helper fields

  • Writing test test script

  • Get or set the value of environment variables through the postman interface.

Here replace the previous IP address (or domain name) in the url with an environment variable:

Move the mouse to the environment variable, and the specific value can be displayed dynamically:

Go to add another development environment:

Then you can add two environment variables, which represent two server addresses and two versions:

Then you can switch between different server environments:

As you can see, the same variable server_address, after switching, the corresponding IP address becomes the IP of the desired development environment:

Postman exports the effect of multiple environment variables in the API document

By the way, let’s take a look. After exporting as an API document, with the interface of this environment variable, what the document looks like:

It is found that before the release, the corresponding environment needs to be selected:

After publishing the document, you can see the selected environment and the IP of the corresponding server:

Of course, after publishing the document, you can also switch the environment in real time:

Benefits of environment variables

When changing the server, directly modify the IP address of the variable:

It can be updated in real time, and the effect can be seen when the mouse is moved to the variable:

Code generation tool

View the original HTTP content of the current request

For the current request, you can also click Code

To view the corresponding original content that conforms to the HTTP protocol:

Code Generation Tools in various languages

such as:

  • Swift language

  • Java language

  • Various other languages ​​also support various other languages:

Currently supported languages ​​are:

  • HTTP

  • C (LibCurl)

  • cURL

  • C#(RestSharp)

  • Go

  • Java

  • OK HTTP

  • Unirest

  • Javascript

  • NodeJS

  • Objective-C(NSURL)

  • OCaml(Cohttp)

  • PHP

  • Python

  • Ruby(NET::Http)

  • Shell

  • Swift(NSURL)

The advantage of the code generation tool is that when writing the code that calls this API, you can refer to the corresponding code, or even copy and paste the corresponding code.

Test interface

After selecting a group, click Runner

Select a group and click Run

You can see the test results: 

Guess you like

Origin blog.csdn.net/weixin_37018468/article/details/106193365