如何在JMeter的ForEach Controller中从vars获取对象

时间:2019-01-22 10:25:53

标签: jmeter jmeter-5.0

说我已经在最后一个请求的post beanshell处理器上设置了一个列表。

<!DOCTYPE html> 
<html> 
<body> 

<video id="videoPlayer" width="320" height="176" controls>
  <source src="https://r1---sn-8xjug5oxu-f5fe.googlevideo.com/videoplayback?mime=video%2Fmp4&key=yt6&fvip=6&sparams=dur%2Cei%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&ip=109.197.67.187&ipbits=0&expire=1548168440&lmt=1472784021038997&pl=23&signature=DDDF5812EBA03434A7A729EC800B56146CC05041.C7FA04CAD5D8A50FF75AA9E1F73C0C372DAC83&dur=10393.901&ei=mNhGXIOJFo2V7QT6oKrYAw&source=youtube&itag=22&ratebypass=yes&mt=1548146723&mv=m&ms=au%2Crdu&mm=31%2C29&mn=sn-8xjug5oxu-f5fe%2Csn-f5f7ln7y&id=o-AF-Y-B2o5xYN4x7hMQGhb9cRO7GCMR6bS0U818w8BuKV&requiressl=yes&initcwndbps=1621250&c=WEB" type="video/mp4">
</video>

<script>
    setInterval(function() {
        var vid = document.getElementById("videoPlayer");
        var start_pl = vid.played.start(0);
        var end_pl = vid.played.end(0);
        document.getElementById("start_pl").innerHTML = start_pl;
        document.getElementById("end_pl").innerHTML = end_pl;
      }, 400);
</script>

start: <div id="start_pl"></div>
end: <div id="end_pl"></div>

</body> 
</html>

如何将每个列表值应用于ForEach Contoller中的请求?谢谢!

1 个答案:

答案 0 :(得分:1)

  1. ForEach Controller无法对对象进行操作,您必须以以下形式创建JMeter Variables

    var_1=a
    var_2=b
    

    您可以使用JMeterVariables类实例的vars速记来创建JMeter变量,例如:

    vars.put("var_1", "a");
    vars.put("var_2", "b");
    

    enter image description here

  2. 然后,您可以配置ForEach控制器以使用var前缀并将输出存储到${current_var} JMeter变量中:

    enter image description here

  3. 就是这样,ForEach控制器将迭代创建的变量:

    enter image description here


请注意,starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language用于编写为Groovy performance is much better than Beanshell的脚本。此外,Groovy是一种更“现代”的语言,它支持所有新的Java功能以及标准Java SDK之上的provides extra functionality