- 将Beanshell PreProcessor添加为要参数化的请求的子代
- 将以下代码放入预处理器的“脚本”区域:
StringBuilder result = new StringBuilder(); String newline = System.getProperty("line.separator"); int max = Integer.parseInt(Parameters); Random random = new Random(); result.append("{"); result.append(""productIds" : ["); result.append(newline); for (int i = 1; i < max; i++) { result.append(""").append(random.nextInt()).append("","); result.append(newline); } result.append("]"); result.append(newline); result.append("}"); vars.put("json", result.toString());- 将您的$ {productsCount}值放入“ Parameters”节中
- 根据
${json}需要引用生成的有效负载
请参阅如何使用BeanShell:JMeter最喜欢的内置组件指南,以获取有关Apache JMeter中Beanshell脚本的更多详细信息。



