[英]How to get value of variable defined in testplan and from csv file with groovy in jmeter
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? 我可以得到这个价值吗?
If you want to concatenate 2 variables: user_id
and curTime
如果要串联2个变量: user_id
和curTime
def value = vars.get("user_id") + vars.get("curTime");
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. vars
是JMeterVariables类实例的简写,它提供对范围内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.