Postman for HTTP Interface testing

Source: Internet
Author: User

Reprint Address:

http://blog.csdn.net/five3/article/details/53021084

There are many HTTP interface test tools, there are many ways to make HTTP requests, but it can be used directly, and the function is also supported by good, I used to speak, or postman compared to get started.

Advantages:

1. Support Use Case management

2, support get, post, file upload, response verification, variable management, environmental parameters management and other functions

3. Support Batch Operation

4. Support Use case export, import

5. Support the cloud saving use case "paying user"

It can be said that postman satisfies most of the functions of the HTTP interface test, only a small part of the function is not supported, such as: the control of the request process, the front said so much, then we will look at the installation and use of postman.

1. What is Postman

Postman is a chrome plugin tool that we can search and install via Chrome's App Store, which displays a postman icon on the desktop and launches the Postna interface each time you click on the icon.

After launch is the interface above, the left is used to manage the directory structure of Use cases, the right is a specific use case of the request content parameters and response content; The default POSTMAN will bring a demo project called "POSTMAN Echo", which has a variety of scenarios in the use case demo, For newly-started students, you can learn how to use postman by looking at these demo use cases.

2. Create a new project

Just click on the Add Directory icon in the left column to create a new root directory, so that is equal to the creation of a project, we can put a project or a module of the use cases are stored in this directory, and under the root directory we can also create sub-directories to the functional use cases of the subdivision, see the concrete.

2. Add a Use case

After creating the project directory, we can create a new use case, specifically click on the right side of the + sign to add a blank use case template, you can also copy an existing use case to achieve the purpose of creating a new use case, 2 ways to see:

3. Add Request Information

The new use case request content is empty, we need to add the corresponding request information, this part of the operation is in the right side of the information area, the general process is as follows:

    1. Select a request method, such as: Get or post
    2. Fill in the requested URL, such as: http://www.baidu.com
    3. If it is get, the request parameter is written directly to the URL, using the? Connection
    4. If it is post, the request is added to the body
    5. Click "Send" to send the request
    6. View Request Response Content

4. Post Request parameters

The main feature of the POST request is that the request data is placed in the body, not the URL

The above example is the post mode transmission of ordinary parameters, if we need to send a request with a file, it is necessary to change the request format, as follows:

Note that the contents of the red box above are required to correspond.

5. Add header information

Sometimes the request also needs some specific header information, postman can also perfect support, directly click on the headers tag can be the request header information settings

6. pretreatment and Result check

Preprocessing is mainly for some environment variables and the like to set, equivalent to the initialization of data;

Response processing is to analyze and verify the response results, such as checking if code is 200, whether the content is equal to a specific value, contains a specific value, and so on.

Because the preprocessing and the result check are all using JS as the scripting language, you can also make arbitrary JS can implement the scene, to assist the test.

7. Global variables and environment variables

Global variables we can make our own assignment in preprocessing and result processing 2 scripts environment, in the specific test data we can use directly, the specific use is: {{variable_key}}; For example, you can set global variables in a script:

[JavaScript]View plain copy  
    1. Postman.setglobalvariable ("username", "tester");
So in the case data item I can use this, {{username}}, to represent the specific tester value, see

Environment variables can be set to use the same as global variables, but the environment variables we have another portal can be set, that is, environment configuration management, we can pre-establish a number of environment-related variables, according to the actual test requirements before execution, select the corresponding environment variable template, This allows you to quickly switch the environment differences between the test server and the online server. For example: Configure 2 sets of environment variable template, a set of URL is the test environment, another set for the online environment, according to the test object different we choose different environment variable template is OK, and no longer need to modify the test data in the URL.

We extract the requested host and then use different URL values in different environment variable templates, and then we can make the corresponding request test by selecting different environment variable template.

8. Export use case as code

Postman also has a great place is the export use case for code, that is, if you have written the use case can click "Generate Code" to generate code, and there are many languages and libraries can choose, the frame is awesome!

9. Batch execution of Use cases

Finally, we'll look at Postman's bulk execution function, which is the responsibility of the individual runner, which we need to operate in another interface, as follows:

Click on the button above will appear Runer interface, the following direct click "Start Test" can

Reprint Address:

http://blog.csdn.net/five3/article/details/53021084

Postman for HTTP Interface testing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.