当前位置:网站首页>Jmeter beanshell实现把请求生成的参数化数据写入文件
Jmeter beanshell实现把请求生成的参数化数据写入文件
2022-07-17 00:14:00 【失眠的书】
需求:A-B-C三个功能需要单交易负载测试。其中,功能C的请求入参是功能A、B的出参(返回值),为了能够单独压测C功能,需要把A、B生成的出参保存至csv或txt文件中,作为参数化文件。
实现:1)提取功能A产生的(cookie)需要使用Beanshell Preprocessor插件及cookie管理器;cookie管理器(一定要勾上每次迭代都要清理cookies)

Beanshell Preprocessor插件:

Beanshell代码:
String str=prev.getResponseHeaders();//获取请求返回头信息
String start="this.sid=";//定义cookie的开始位置
String end=";Path="://定义cookie的结束位置
String cook =str substring(str.indexOf(start)+start.length0,str.indexOf(end));//根据起止信息获取cookie
vars.put("cookies".cook);//把cookie信息保存到meter变量中,方便后续使用提取功能B产生的(studentid)出参字段,需要使用正规表达式提取器(Regular Exception Extractor);

2)将功能A、B产生的数据写入文件操作,使用jmeter beanshell sampler插件。
Beanshell代码:
import java.io.:
public static void writeExternalfile){
String studentld =vars.get("studentld");//获取studentld
String cookies=vars.get("cookies")://获取cookie
//保存文件名及目录
File file=new File("C:\\tools\\apache-jmeter-3.2-plugins\\bin\\csh\\playGameVar.txt");
FileOutputStream fos=nul;
if(!file.existsO){
file.createNewFile);
fos=new FileOutputStream(file);
}else{
fos=new FileOutputStream(file,true);
}
OutputStreamWriter osw=new OutputStreamWriter(fos,"UTF-8");
try{
osw.write(studentld+","+cookies);//写入studentid与cookie值,并以逗号隔开
osw.write("\r\n");//换行
osw.close0;//关闭
}catch(IOException e){
e.printStackTrace();
}
}
writeExternalfile();//调用写入文件方法看下执行效果:

生成的文件及文件内容:

边栏推荐
- ENVI_ Idl: batch process the re projection of MODIS swath data and output it to GeoTIFF format + detailed analysis
- Unity笔记1
- BUAAOS-Lab0实验报告
- [tools] unity2d character controller, which controls 2D players to move and jump in four directions and horizontal directions
- STL--queue容器
- YYDS! The latest distributed core technology notes summarized by Alibaba technical officers have been launched, which can be regarded as a blessing
- ENVI_ Idl: batch Reproject MODIS swath products and specify the range output as GeoTIFF format + parsing
- UE4 笔记
- Visual Studio 2019-QT调试
- Cookie和Session的区别
猜你喜欢
![[unity panel attribute literacy] set texture import settings after importing textures](/img/c6/4a50bb848560e1e5c72e714d367109.png)
[unity panel attribute literacy] set texture import settings after importing textures

ENVI_IDL:讀取所有OMI產品的NO2柱含量並計算月均值、季均值、年均值+解析

攻防世界----easytornado笔记

【解决方案】win11中本地组策略编辑器(gpedit.msc)打不开

STL--queue容器

ENVI_IDL:读取所有OMI产品的NO2柱含量并计算月均值、季均值、年均值+解析

成信大ENVI_IDL第一周实验测试:数组的简单运算+详细解析

LeetCode:动态规划中的子序列问题

STL--stack容器

ENVI_ IDL: read OMI data (HDF5) and output it as GeoTIFF file + detailed parsing
随机推荐
【工具篇】SQLite本地数据库在Unity3D的应用
二叉树的遍历
池式组件之内存池篇
ENVI_IDL:读取OMI数据(HDF5)并输出为Geotiff文件+详细解析
3D NFT的破茧重生:Caduceus去中心化边缘渲染技术
Leetcode 1: Two Sum
[unity Editor Extension] unity publishes resources to the store process unity asset store publish
STL -- stack container
【Unity面板属性扫盲】导入纹理后设置Texture Import Settings
DoubleDQN的理论基础及其代码实现【Pytorch + Pendulum-v0】
CTFHub----RCE
树和堆知识点总结
成信大ENVI_IDL第二周实验内容:提取所有MODIS气溶胶产品中AOD+详细解析
Summary of tree and heap knowledge points
成信大ENVI_IDL第三周课堂内容1:读取OMI数据(HDF5文件)以及输出+解析
第二讲 BTC-密码学原理(笔记)
ENVI_ Idl: batch re projection of modisswath products (calling the secondary development interface) + parsing
Gdb+vscode for debugging 4 - GDB executes relevant commands
YYDS! The latest distributed core technology notes summarized by Alibaba technical officers have been launched, which can be regarded as a blessing
BUAAOS-Lab0实验报告