JMeter JSON data parameterization assertion, etc.

Source: Internet
Author: User

In HTTP Load testing, the submission of JSON data is a daunting issue. This article details how to make a JSON test submission for JMeter and how to parameterize it.
Step 1 HTTP JSON request Sampler Recording
This tool can be used for recording with JMeter agents or Badboy.

Step 2 Adds the HTTP information manager to the sampler
Right-click on the sampler, the right-click menu, select "Add", "Configure components," HTTP header Manager, and then the information header add a name of Content-type, the value is Application/json:

After adding the HTTP information manager, select the sampler and edit its Content encoding to UTF-8:

Step 3 Adds a response assertion to the sampler
For example, in the JSON string requesting the return, "status": 0 Represents the processing success, and the status value for the other indicates various processing failures. Then right-click on the sampler, the right-click menu select "Add", "assertion---" response assertion, the response field to be tested check "response text", the Pattern matching rule check "Substring", the mode to test to add and edit its contents as "status": 0.

Step 4 Editing the JSON format of the sampler
Select the sampler, Parameters Ye Xiangri Copy the JSON string, then click on the Body Data leaf item and paste the JSON string in the input field (for JSON string extraction, you can use Badboy to record yourself, you can also use the Chrome browser to bring the tool " JavaScript console-Network for capture), and finally adjust the presentation format of the JSON data as shown in:

HTTP JSON can be submitted at this time, but the data is still written dead. So how do you parameterize these JSON data like other non-JSON-submitted samplers?
Step 5 parameterization of HTTP JSON data using functions
Use the function helper, like other samplers, to generate a reference string, such as

${__random (0,9,random_num_0_9)}

, its role is to randomly generate a number between 0-9.
Then edit the JSON string in Body Data where it needs to be parameterized, using the

${__random (0,9,random_num_0_9)}

Overwrite the part that needs to be parameterized:

Step 6 uses CSV data set Config to parameterize the JSON
Right-click on the Thread Group, right menu select Add, configure component, CSV Data Set config,filename input e:/defonds/work/20141105/json.txt (to use absolute path), Variable Names input Citycode,cityname,subcategorycode,subcategoryname, edit the E:/defonds/work/20141105/json.txt content as shown:

Finally, edit the JSON string in Body Data where it needs to be parameterized, and use parameters such as ${citycode} to cover the parts that need to be parameterized:

You can then use the parameterized JSON string for stress testing:

from:http://blog.csdn.net/defonds/article/details/40824011

JMeter JSON data parameterization assertion, etc.

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.