jmeter beanshell调用jmeter函数 [英] jmeter beanshell call jmeter function

查看:485
本文介绍了jmeter beanshell调用jmeter函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我配置了一个HTTP请求采样器.在请求正文中,我调出我编写的beanshell函数:

I have a HTTP request sampler configured. In the request body, I call out to a beanshell function I wrote:

${__BeanShell(createHeader("GET"\,"Customer"\,"${__UUID}"\,"${__time(yyyy-MM-dd'T'hh:mm:ss)}"))}

该函数仅使用传入的参数构建一些请求字符串.我想删除jmeter函数调用(__UUID和__time),然后直接从beanshell函数中调用它们.我找不到办法. 谢谢

The function just builds some request strings with the passed-in parameters. I want to remove the jmeter function calls (__UUID and __time), and call them directly from within the beanshell function. I could not find a way to do that. Thanks

推荐答案

  1. 不要将 JMeter函数或变量内联到脚本中您的案例中,您将不得不去寻找基于代码的对等物,例如:

  1. Don't inline JMeter Functions or Variables into scripts, in your case you will have to go for code-based equivalents instead, to wit:

  • __UUID()-> UUID.randomUUID().toString()
  • __time()-> new java.text.SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss").format(new Date())
  • __UUID() -> UUID.randomUUID().toString()
  • __time() -> new java.text.SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss").format(new Date())

从JMeter 3.1开始,建议使用JSR223测试元素和Groovy语言(用于脚本编写),您的情况是 __groovy()函数.如果要重新使用createHeader方法-可以将其放入单独的.groovy文件中,并定义

Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting, in your case it would be __groovy() function. If you want to re-use createHeader method - you can put it into a separate .groovy file and define groovy.utilities property pointing to this file.

请参阅 Apache Groovy-为什么和如何使用它文章,有关在JMeter测试中使用Groovy脚本的更多信息.

See Apache Groovy - Why and How You Should Use It article for more information on using Groovy scripting in JMeter tests.

这篇关于jmeter beanshell调用jmeter函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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