Study Summary--jmeter do the HTTP interface function test

Source: Internet
Author: User
Tags http cookie

JMeter testing of various types of interfaces

Before the interface test is done by default, a clear interface document (such as http://test.nnzhp.cn/wiki/index.php?doc-view-59) has been given, and the local JMeter 3.x environment is well equipped.

Open JMeter, add a thread group and view results tree for that thread group. Several of the following interface requests are added and run in this thread group.

1. Common get requests with Key-value

e.g. getting user information

Add an HTTP request, fill in the server domain name or IP, select Get, fill in the path, add parameters, run and view the results.

2. Post requests with JSON string parameters

e.g. getting user balances

Add the HTTP request, fill in the server domain name or IP, select Post, fill in the path, select the body data tag in the parameter area, write the JSON string parameters, note the JSON format; Run and view the results.

3. HTTP permission validation is required for the request

e.g. modifying user balances

Add the HTTP request, fill in the server domain name or IP, select Post, fill in the path, fill in the parameters;

Add Authorization Manager, right-click on thread Group, Add-config component,->http Authorization Manager;

Open the HTTP Authorization Manager, add the path in the base URL, fill in the user name, password (the interface document will be given), add the domain is the requested server domain name or IP;

Run the request and view the results. (The interface temporarily has a problem request to return 500, as long as the understanding of the need to verify the permissions of the interface to do so)

4. Request headers need to be added when requesting

e.g. obtaining user Information 2

Add the HTTP request, fill in the server domain name or IP, select Post, fill in the path, fill in the parameters;

Add the HTTP header manager, right-click on the thread group, Add-config component,->http information header manager;

Open the HTTP header manager, and refer to the interface documentation to fill in the header information;

Run the request and view the results.

5. Need to add a cookie when requesting

e.g. modifying user balances 2

Add the HTTP request, fill in the server domain name or IP, select Post, fill in the path, fill in the parameters;

Add an HTTP cookie manager, right-click on the thread group, add-on configuration component->http Cookie Manager;

Open the cookie manager and fill in the cookie information with the interface documentation;

Send the request and view the results.

6. Request to upload a file via an interface

e.g. uploading files

Add the HTTP request, fill in the server domain name or IP, select Post, fill in the path, select the files upload tag in the parameter area, add the full file name (including the absolute path, or click the Browse button to add), write the parameter name, send the request and view the result.

JMeter the parameterization

1. Specifying parameter values

This method is commonly used to solve multiple requests in the thread group to share the same data, such as all of our requests have the same IP address, when the address changes can be changed completely.

Add user-defined variables, right-click the user-defined variable, add-on, configuration components, and so on thread group.

Open user-defined variables, add variables, write names and values;

The variable name can be referenced everywhere in the script, and the reference variable is in the format of the ${variable name};

2. Generating parameters with functions

During the test, sometimes the data is not suitable to be specified, you can choose to use the function to generate, the following are the most commonly used.

    • ? Generate random numbers with functions: (__random)

In the JMeter, click the Options, Function Assistant dialog box;

In the popup dialog box, select __random, fill in the range of random numbers, click the Generate button, you will see the string you need;

Attempt to use the generated random number in the request and paste the newly copied string into the requested parameter;

Send the request to view the parameter values in the request, the parameters are in effect.

    • ? Generate current time with function: (__time)

    • ? Generate a generic unique identifier with a function: (__UUID)

3. File transfer

Used to read the parameters maintained in the file, such as the contents of the parameter file as follows;

Note that the total parameter of the JMeter read file is started from the first line, and never make the following error.

In JMeter, right-click Thread Group, add-on configuration component,->csv Data set Config;

Open the Settings window, write the full name of the parameter file (with absolute path), variable name, delimiter with the default comma, indicating that the parameter table when the parameter file is prepared with a comma separated from the column;

When referencing parameters in the request should be Jiangzi: ${username} ${pwd}, use them to replace the corresponding parameter values.

4. Associated Parameters

In a thread group, an association is required when you want to use the response result of one request as an entry to another request.

    • ? associating with regular expressions

The idea is to extract the value you need from the response data of a request, and then enter the value in another request with the following actions:

Add a regular expression extractor with the request to extract the response data, right-click on the add-on processor, and the regular expression extractor;

In the regular expression extractor to fill in the reference name, do not say also know the purpose of the regular expression, the simplest way is to extract the target value in the response to the left and right several characters containing the target value of a line copy, paste into the regular expression box, the target value is replaced by a pair of parentheses, Enclose the appropriate matching into for example (. *), and note that when copying in response data, avoid the characters that need to be escaped if you can't avoid them, escape them; templates are usually filled with $1$; the matching number 1 represents the first value of the region match;

Use ${age} to enter the parameter to another request to see if the result is successfully passed.

    • ? Using the JSON Path Extractor plug-in association

For response values in JSON format only, right click on the request to add the processor->json Path Extractor;

Populate the JSON Path extractor with the reference name and Jsonpath Expression;

The parameter is entered in another request, and the same as the result of the previous referral succeeds.

Note that the JSON Path extractor plugin can only be installed in versions above jmeter3.x.

Jmeter Add assertion Check Results

Right-click the request to add the assertion----response assertion;

Add and write what you want to see in the response result;

Send a request to view the results;

Jmeter Operation MySQL

Test plan Add. Jar Package Mysql-connector-java-5.1.7-bin.jar is used to enable jmeter to read MySQL;

Thread Group Add JDBC Connection configuration (Add, configure components, JDBC Connection config) for configuring JMeter and MySQL connections;

The JDBC Driver class is a fixed, Driver reference for jmeter operation of various types of data;

Thread Group Add JDBC request (add->sampler-> JDBC request) to write SQL to operate MySQL;

Send a request for a successful access to mSQL.

Study Summary--jmeter do the HTTP interface function test

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.