[JMETER] Request Body parameters in the interface test to TXT file

tags: test tools

Save the Request Body parameter in JMETER to TXT file

Foreword
This is the problem I encountered in the interface test by myself, that is, we usually need to save the parameters of the response data to the TXT file. It is simple to use the regular expression extractor or the JSON extractor and the Beanshell rear processing program. Essence However, there is another possibility in practical applications. The parameters in the interface request also need to be saved in the TXT file. At this time, the regular extractor cannot be done, and we use the Beanhell rear processing program to do it.

1. You need to extract parameters: Memberid in Body

2. Add Beanshell rear processing program


3. script

import java.net.URLDecoder;
import org.json.*;

// response1 = prev.getsamplerdata (); // Take Request Body data
//log.info(response1);
String samplerData = prev.queryString;  // Take only POST DATA data
log.info(samplerData);
JSONObject aa=new JSONObject(samplerData);
String subData = aa.get("memberId").toString(); // Get the key value of Memberid
log.info(subData);
String r = URLDecoder.decode(subData,"utf-8");   // Transcod, for Chinese characters
log.info("The parameter is:"+r);
FileWriter fstream = new FileWriter("D:\\221411.txt",true);  // Write it to the txt file, and automatically create when there is no file under the path
BufferedWriter out = new BufferedWriter(fstream);
out.write(r+"\n");    // Written data

out.close();
fstream.close();

4.
5. Log

Intelligent Recommendation

Jmeter interface test①——POST request

1. Environment construction Please search on the Internet for detailed installation methods. There are many methods. I will not introduce them in detail here. Only the download address is provided. 1....

[Interface test] jmeter PUT request upload parameters (Solved: the problem of request parameter upload is empty after running)

Today in the jmeter test interface, I occasionally put the request to upload parameters, and the request parameters are empty after running After trying many wrong methods, the author summarizes two t...

Jmeter writes the data returned by the interface to a txt file

1. Call the interface to extract the value of totalvalue from the response message 2. Write totalvalue to txt //Specify which file to write to, format: TXT, csv //C:\\zdh\\TianwangCSV\\summaryData.txt...

Jmeter request file upload interface

1. Upload the picture interface, obtain the relevant information of the interface through the packet capture tool, and then add Content-Disposition:form-data; name="imgType" in the message h...

Jmeter test upload file with parameters

Jmeter test upload file with parameters step: 1. First, grab a package and look at the header, parameters, etc. 2. Add header 3. Add an http request. The marked on the map must be checked. All paramet...

More Recommendation

JMeter basics: the difference between request parameters and body data

When testing with Jmeter, many people do not know the difference and use of request parameters and body data. Here is a brief introduction:   First understand the basic concept of an interface In...

Jmeter interface performance test: BeanShell post-processing program will write the response results to a txt file in the future

Easily write the results into a local txt file in two steps. 1. Extract response data, because most of our work is to write part of the response data into a file, such as the order number; Right-click...

Jmeter completes md5 encrypted interface request parameters

Jmeter completes the interface test is not difficult, the basic use can watch my video: But sometimes the parameters we request may need to be encrypted. For example, the password in the login interfa...

Jmeter completes the md5 encrypted interface request parameters

Baidu search: Xiaoqiang test brand Kick the talk show, entertain technology and systematize fragments, all in Lizhi FM (http://www.lizhi.fm/200893) "Xiaoqiang Software Testing Crazy Lectures-Perf...

Parameters and body data in JMeter

Reprinted https://blog.csdn.net/lluozh2015/article/details/51548243 When doing the concurrent test of the interface, I found that the two parameter formats of Parameters and Body Data in Jmeter are no...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top