jmeter线程组多个请求之间的参数关联

先看整个jmeter脚本的目录

场景:request-2发起请求的参数来自request-1的返回值,需要拿到request-1的返回值拼装到request-2的请求域中

常用可以使用jmeter的正则获取,本人认为那种方式不直观也不好弄,最好是用编程解释json的方式

1.下载json的包,放入/lib/ext中

2.在request-1下面新建BeanShell PostProcessor

   首先看一下返回的json

  

  我们要取得“mu”的值,以及“em”的值,这有点json基础的都挺简单的,具体看代码,一层层的解释就行了

  

import org.json.*;

String response = prev.getResponseDataAsString();

JSONObject jsonObject = new JSONObject(response);

String em = jsonObject.getJSONArray("data").getJSONObject(0).getJSONArray("em").get(0).toString();

vars.put("ch_url",em);
String mu = jsonObject.getJSONArray("data").getJSONObject(0).getString("mu");
log.info(mu);

猜你喜欢

转载自www.cnblogs.com/mosicol/p/12530736.html