测试吧 关注:489,947贴子:16,618,304
  • 0回复贴,共1
求助

Jmeter中BeanShell 预处理第一次成功,第二次失败

只看楼主收藏回复

BeanShell 预处理器:
// fastjson 使用
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.http.util.HTTPArgument;
// 获取请求参数JSON
JSONObject requestJson = JSON.parseObject(ctx.getCurrentSampler().getArguments().getArgument(0).getValue());
log.info(ctx.getCurrentSampler().getArguments().getArgument(0).getValue());
// 操作JSON数据
requestJson.getJSONObject("requestData").remove("pageIndex");
// 获取当前采样器对象
HTTPSamplerProxy sampler = ctx.getCurrentSampler();
// 获取采样器对象的请求参数
Arguments args = sampler.getArguments();
// 获取第一个参数(假设有参数)
HTTPArgument arg = args.getArgument(0);
// 修改参数的值,假设您要将参数的值修改
arg.setValue(requestJson.toString());
// 设置修改后的参数到采样器对象
// 先删除,再添加
sampler.getArguments().removeArgument(0);
sampler.getArguments().addArgument(arg);
// 输出修改后的参数
log.info(ctx.getCurrentSampler().getArguments().getArgument(0).getValue());
报错日志:
521 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: evalSourced file: inline evaluation of: ``// fastjson 使用 import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSO . . . '' : Typed variable declaration
521 WARN o.a.j.m.BeanShellPreProcessor: Problem in BeanShell script. org.apache.jorphan.util.JMeterException: Error invoking bsh method: evalSourced file: inline evaluation of: ``// fastjson 使用 import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSO . . . '' : Typed variable declaration




IP属地:广东来自Android客户端1楼2024-05-05 02:17回复