当前位置:网站首页>Jmeter BeanShell post processor

Jmeter BeanShell post processor

2022-08-09 10:47:00 three squirrels

In some scenarios, we need to obtain the token of the login interface and save it locally, because the subsequent interface stress test needs to pass the token as a parameter. Students with coding ability can write a script to solve it. This articleLet's talk about the implementation of jmeter.Using the BeanShell post processor can help us write the token to a local file.

1. For example, there is now a login interface, and the interface returns the following information:

2. First add a json extractor to extract the token field in the json string:

3. Add a BeanShell post-processor to write the extracted data to a file.

Scrip is a java language, you need to implement the writing file yourself:

FileWriter fstream = new FileWriter("D:\\token.csv",true);BufferedWriter out = newBufferedWriter(fstream);//phone isThe input parameters of the login interface are written to the file together here.out.write(vars.get("phone")+',');out.write(vars.get("token")+'\n');out.close();fstream.close();

Look at the effect:

原网站

版权声明
本文为[three squirrels]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208091043258013.html