Jmeter - 找到正确的项目后停止读取CSV文件 [英] Jmeter - Stop reading CSV file after find out right item

查看:281
本文介绍了Jmeter - 找到正确的项目后停止读取CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CSV档案,例如:

I have a CSV file like:


brandid1,brandurl1,producturl1

brandid1,brandurl1,producturl1

brandid2,brandurl2,producturl2

brandid2,brandurl2,producturl2

brandid3,brandurl3,producturl3

brandid3,brandurl3,producturl3

和从先前响应获得的变量$ {brandid}。 现在我想从CSV文件中找到一个brandurl和producturl如果brandid是相同的(例如:$ {brandid} == $ {brandid2},它将返回brandurl2和producturl2)Them脚本将停止而不运行整个csv文件。

and a variable ${brandid} that get from previously response. Now i want to find a brandurl and producturl from CSV file if brandid are same (ex: ${brandid} == ${brandid2}, it will return brandurl2 and producturl2) Them script will stop without run whole csv file.

我必须使用While控制器和BSF预处理器,但脚本总是运行整个csv文件。

I have to use "While" controller and BSF Preprocessor but the script always run whole csv file.


While($ {tmp}==1)

While ("${tmp}"=="1")

- http请求(使用brandurl,producturl)

--http request (use brandurl,producturl)

- csv档案

- HTTP标头管理员

--HTTP Header Manager

- BSF PreProcessor

--BSF PreProcessor

在全局中声明tmp tmp = 1 和BSF如下:

With tmp declare in global tmp=1 and BSF as below:

  var brand_idOfWH = vars.get("brand_idOfWH");
var brandid_csv = vars.get("brandid");

 var brandurl = vars.get("brandurl");
 vars.put("brand_url",brandurl);

 var producturl = vars.get("producturl");
 vars.put("product_url",producturl);

if (brand_idOfWH == brandid_csv)
{
 vars.put("tmp","0");
}

请帮助我停止阅读CSV文件$ c> brandid

Please help me to stop reading CSV file if i find out right brandid

推荐答案


  1. 控制器,根据文档,它接受功能变量,它不能解析您的表达式,因此它不会退出循环。正确的函数如下:

  1. You are misusing While Controller, as per documentation it accepts either function or variable, it cannot parse your expression hence it won't exit the loop. The correct function will look something like:

${__javaScript("${tmp}" == "1",)}


  • 不建议使用BSF测试元素进行脚本。如果您必须通过脚本克服JMeter限制,请考虑使用 JSR223测试元素和groovy作为一种语言 - 这样你会得到最佳的性能。请参见 Beanshell vs JSR223 vs Java JMeter脚本:性能 - 您已等待!指南,了解有关安装Groovy脚本引擎支持和Groovy脚本最佳做法的详细说明。

  • It isn't very recommended to use BSF test elements for scripting. If you ever have to overcome a JMeter limitation via scripting consider using JSR223 Test Elements and "groovy" as a language - this way you'll get optimal performance. See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! guide for detailed instructions on installing Groovy scripting engine support and Groovy scripting best practices.
  • 这篇关于Jmeter - 找到正确的项目后停止读取CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆