简体   繁体   English

如何在jmeter中使用groovy从testplan和csv文件中获取定义的变量值

[英]How to get value of variable defined in testplan and from csv file with groovy in jmeter

我在测试计划中定义了变量名消息。我希望它成为Groovy中数据的价值。实施此后,我得到错误。

I am trying to pass a variable in groovy in JSR223 sampler. 我正在尝试在JSR223采样器中的groovy中传递变量。 The variable is defined in test plan. 该变量在测试计划中定义。 Basically there are ${user_id} and ${__time(,curTime)} defined for value of Message in Test Plan ${user_id} is the value i am getting from csv file and ${__time(,curTime)} is function for current time in millisecond. 基本上有$ {user_id}和$ {__ time(,curTime)}为测试计划中的Message值定义$ {user_id}是我从csv文件中获取的值,而$ {__ time(,curTime)}是当前函数时间(以毫秒为单位)。 Basically i want a value in output as user_id corresponding with timestamp in millisecond. 基本上我想在输出中作为user_id的值与毫秒中的时间戳相对应。

For Eg if value of ${user_id} is abcd and value of ${__time(,curTime)} is 1478965236574 then, i am expecting value as abcd1478965236574 in the variable data in JSR223 sampler. 对于例如,如果的$ {USER_ID}值是ABCD和${__时间(,CURTIME)}是1478965236574然后,我期待值如在JSR223采样可变数据abcd1478965236574。 Can i get this value? 我可以得到这个价值吗?

  1. If you want to concatenate 2 variables: user_id and curTime 如果要串联2个变量: user_idcurTime

     def value = vars.get("user_id") + vars.get("curTime"); 
  2. If you want to generate the new timestamp" 如果您想生成新的时间戳”

     def value = vars.get("user_id") + System.currentTimeMillis() 

vars is a shorthand to JMeterVariables class instance which provides read/write access to JMeter Variables in scope. varsJMeterVariables类实例的简写,它提供对范围内JMeter变量的读/写访问。

Remember that you should not inline JMeter Variables and Functions like ${Message} into the script body, use vars.get("Message") instead as inlining variables causes compilation caching failure hence you loose the major Groovy benefit. 请记住,不要将${Message}类的JMeter变量和函数内联到脚本主体中,而应使用vars.get("Message")因为内联变量会导致编译缓存失败,因此会失去Groovy的主要优点。 See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! 请参见Beanshell,JSR223和Java JMeter脚本:您一直在等待的性能下降! for more detailed explanation and scripting best practices. 以获得更详细的说明和脚本最佳实践。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取结果值附加到jmeter中的CSV文件中(groovy) - How to get the result values appended to an CSV file in jmeter(groovy) 如何使用Groovy从CSV文件中获取条目的相邻值 - How to get the adjacent value of an entry from CSV file using Groovy jmeter - 如何从原始 csv 和 groovy 创建新的 csv - jmeter - how to creat new csv from original csv with groovy 如何在 groovy 中从 Jmeter 获取 CookieManager? - How to get CookieManager from Jmeter in groovy? 如何获取groovy中变量的值 - How to get a value of variable in groovy Groovy从文件获取变量。 变量=值 - Groovy get variables from file. variable=value 如何根据变量值识别 csv 文件中的一行,并在 Groovy 中从该行开始迭代文件行? - How can I Identify a line in a csv file based on a variable value and start iterating over the file lines from that line onwards in Groovy? JMeter groovy:如何从json中获取属性值以数字开头的属性值 - JMeter groovy: how to get attributes value from json with attributes starting with a number 如何在groovy Jmeter中将变量从采样器移动到采样器 - How to move variable from sampler to sampler in groovy Jmeter 如何在Groovy脚本中查找yaml文件中定义的映射,并分配给Pipeline UI提供的基于变量的输入 - How to lookup map defined in yaml file in the Groovy script and assign to variable based input provided from Pipeline UI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM