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. The sampler is recorded as shown in the following:
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 the Body Data leaf item, paste the JSON string into the input field, and finally adjust the presentation format of the JSON data as shown:
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
Using the function helper, like any other sampler, to generate a reference string, such as ${__random (0,9,random_num_0_9)}, which is used to randomly generate a number between 0-9.
Then edit the JSON string in Body Data where it needs to be parameterized and use ${__random (0,9,random_num_0_9)} to 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:
References
- Resolution note For a JMeter script request error HTTP Status 415
- One JMeter script request error Could not read json:unexpected character:expected A valid value resolution note
JMeter stress testing using functions and CSV files to parameterize JSON data