Jmeter BeanShell取样器


Jmeter BeanShell取样器

BeanShell是符合Java语法格式的Java脚本,官网是:http://www.beanshell.org/manual/bshmanual.html

实例

  • 创建BeanShell Sampler,输入如下脚本
import java.text.SimpleDateFormat;
import java.util.*;

String str1 = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
String str2 = new SimpleDateFormat("HH:mm:ss.SSS").format(new Date());
vars.put("time1", str1);
vars.put("time2", str2);
  • 创建http请求取样器,在消息体数据中输入如下内容:
{
    "Time1":${time1},
    "Time2":${time2}
}
  • 添加查看结果树,在请求->Request Body中看到如下内容:
GET http://www.baidu.com/
GET data:
{
    "Time1":2019-10-28,
    "Time2":12:22:01.936
}
[no cookies]