1、将fastjson-1.2.68.jar放置C:\jmeter\apache-jmeter-5.0\lib路径下
2、CSV 数据文件设置多个手机号
3、添加登录接口,${mobile}调用2种的mobile值
4、登录接口响应数据
5、BeanShell 取样器提取登录接口响应数据
//导入json包
import com.alibaba.fastjson.JSONObject;
//获取获取请求的返回值
String response_data = prev.getResponseDataAsString();
//日志打印获取请求的返回值
log.info(response_data);
//将String类型的返回值构造成JSONObject对象
JSONObject data_obj = JSONObject.parseObject(response_data);
String msg = data_obj.get("msg").toString(); //取出“msg”的值
String token = data_obj.get("data").get("token").toString(); //取出“token”的值
log.info(msg);
log.info(token);
vars.put("token",token);//赋值token供后面接口调用
6、jmeter打印日志正常
2020-04-03 17:26:54,061 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2020-04-03 17:26:54,066 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2020-04-03 17:26:54,068 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2020-04-03 17:26:54,512 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : 线程组
2020-04-03 17:26:54,512 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group 线程组.
2020-04-03 17:26:54,512 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2020-04-03 17:26:54,512 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 perThread=1000.0 delayedStart=false
2020-04-03 17:26:54,523 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2020-04-03 17:26:54,523 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2020-04-03 17:26:54,525 INFO o.a.j.t.JMeterThread: Thread started: 线程组 1-1
2020-04-03 17:26:54,525 INFO o.a.j.s.FileServer: Stored: C:\jmeter\apache-jmeter-5.0\bin\parameter\mobile.csv
2020-04-03 17:26:54,901 INFO o.a.j.u.BeanShellTestElement: {"code":0,"msg":"成功","data":{"token":"bearereyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9tZW1iZXItYXBpLnN0MS50ZXN0LmxhbnhpbmthLmNvbVwvMi4wXC91c2Vyc1wvbG9naW4iLCJpYXQiOjE1ODU5MDYwMTQsImV4cCI6MTU4NzIwMjAxNCwibmJmIjoxNTg1OTA2MDE0LCJqdGkiOiJIa0JhSkl2bTlKVldnQTZ2Iiwic3ViIjo1ODQ5MDIsInBydiI6IjNhN2IwNmU5NTBkMDhlMjMzMjkyMjdjN2E2YTUyMzQyYWJiNGYxOWIiLCJidXNpbmVzc190eXBlIjoiNiJ9.ylbSC_IL_hWjdblFDQQO1TyGexRBFxPZTVPX4ATRJ3k"}}
2020-04-03 17:26:54,902 INFO o.a.j.u.BeanShellTestElement: 成功
2020-04-03 17:26:54,903 INFO o.a.j.u.BeanShellTestElement: bearereyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9tZW1iZXItYXBpLnN0MS50ZXN0LmxhbnhpbmthLmNvbVwvMi4wXC91c2Vyc1wvbG9naW4iLCJpYXQiOjE1ODU5MDYwMTQsImV4cCI6MTU4NzIwMjAxNCwibmJmIjoxNTg1OTA2MDE0LCJqdGkiOiJIa0JhSkl2bTlKVldnQTZ2Iiwic3ViIjo1ODQ5MDIsInBydiI6IjNhN2IwNmU5NTBkMDhlMjMzMjkyMjdjN2E2YTUyMzQyYWJiNGYxOWIiLCJidXNpbmVzc190eXBlIjoiNiJ9.ylbSC_IL_hWjdblFDQQO1TyGexRBFxPZTVPX4ATRJ3k
2020-04-03 17:26:57,255 INFO o.a.j.u.BeanShellTestElement: {"code":0,"msg":"成功","data":{"token":"bearereyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9tZW1iZXItYXBpLnN0MS50ZXN0LmxhbnhpbmthLmNvbVwvMi4wXC91c2Vyc1wvbG9naW4iLCJpYXQiOjE1ODU5MDYwMTcsImV4cCI6MTU4NzIwMjAxNywibmJmIjoxNTg1OTA2MDE3LCJqdGkiOiJKb09tMjBEUkJZYnc4QUxYIiwic3ViIjo1ODY1NTYsInBydiI6IjNhN2IwNmU5NTBkMDhlMjMzMjkyMjdjN2E2YTUyMzQyYWJiNGYxOWIiLCJidXNpbmVzc190eXBlIjoiNiJ9.dsMRw7wCPLo25t0rc7nRM4EUbIeUI4BBH5AkAEu1tZ0"}}
2020-04-03 17:26:57,256 INFO o.a.j.u.BeanShellTestElement: 成功
2020-04-03 17:26:57,256 INFO o.a.j.u.BeanShellTestElement: bearereyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9tZW1iZXItYXBpLnN0MS50ZXN0LmxhbnhpbmthLmNvbVwvMi4wXC91c2Vyc1wvbG9naW4iLCJpYXQiOjE1ODU5MDYwMTcsImV4cCI6MTU4NzIwMjAxNywibmJmIjoxNTg1OTA2MDE3LCJqdGkiOiJKb09tMjBEUkJZYnc4QUxYIiwic3ViIjo1ODY1NTYsInBydiI6IjNhN2IwNmU5NTBkMDhlMjMzMjkyMjdjN2E2YTUyMzQyYWJiNGYxOWIiLCJidXNpbmVzc190eXBlIjoiNiJ9.dsMRw7wCPLo25t0rc7nRM4EUbIeUI4BBH5AkAEu1tZ0
2020-04-03 17:26:59,299 INFO o.a.j.t.JMeterThread: Thread is done: 线程组 1-1
2020-04-03 17:26:59,299 INFO o.a.j.t.JMeterThread: Thread finished: 线程组 1-1
2020-04-03 17:26:59,300 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2020-04-03 17:26:59,300 INFO o.a.j.s.FileServer: Close: C:\jmeter\apache-jmeter-5.0\bin\parameter\mobile.csv
2020-04-03 17:26:59,301 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)
7、debug采样器响应数据
mobile和token值成功提取出来
JMeterVariables:
JMeterThread.last_sample_ok=false
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage@772e9455
START.HMS=091322
START.MS=1585876402673
START.YMD=20200403
TESTSTART.MS=1585906014066
__jm__线程组__idx=0
__jmeter.U_T__=线程组 1-1
mobile=18221124104
token=bearereyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9tZW1iZXItYXBpLnN0MS50ZXN0LmxhbnhpbmthLmNvbVwvMi4wXC91c2Vyc1wvbG9naW4iLCJpYXQiOjE1ODU5MDYwMTQsImV4cCI6MTU4NzIwMjAxNCwibmJmIjoxNTg1OTA2MDE0LCJqdGkiOiJIa0JhSkl2bTlKVldnQTZ2Iiwic3ViIjo1ODQ5MDIsInBydiI6IjNhN2IwNmU5NTBkMDhlMjMzMjkyMjdjN2E2YTUyMzQyYWJiNGYxOWIiLCJidXNpbmVzc190eXBlIjoiNiJ9.ylbSC_IL_hWjdblFDQQO1TyGexRBFxPZTVPX4ATRJ3k
8、调用token接口,参数{"test1":${token}}中token为BeanShell 取样器中的token变量值
9、查看采样器中token值传入是正确的