Beanshell Sampler JMeter中用于解析RegularExpressionExtractor的错误 [英] Error in Beanshell Sampler JMeter for parsing RegularExpressionExtractor

查看:209
本文介绍了Beanshell Sampler JMeter中用于解析RegularExpressionExtractor的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jar文件中设置以下示例结果

Setting below sample result in jar file

mySampleResult.setResponseData("ReturnCode" + returnCode + "EndReturnCode" ,null);

将jar文件复制到JMeterlib/ext中.

copy the jar file in lib/ext of JMeter.

创建一个项目,其中Regular expression extractor附加到java请求,该请求在jar文件中调用runtest

Create a project where Regular expression extractor is attached to java request which calls runtest in jar file

响应字符串在下面

ReturnCodeThu Feb 16 08:01:56 GMT 2017,Thu Feb 16 09:09:27 GMT 2017,0:1:7:31,98.74105EndReturnCode

正则表达式提取器

Reference Name: returnValue
Regular Expression: ReturnCode(.*?)EndReturnCode

Beanshell代码

Beanshell Code

 ${returnValue}

Beanshell错误

Error in Beanshell

Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval  In file: inline evaluation of: ``  try {     Thu Feb 16 08:01:56 GMT 2017,Thu Feb 16 09:09:27 GMT 2017,0:1:7:31,9 . . . '' Encountered "16" at line 4, column 13.

请让我知道为什么我会收到此错误.

Please let me know that why I am getting this error.

推荐答案

您的${returnValue}语句在语法上是不正确的,您至少需要用诸如"${returnValue}"的引号引起来,以便Beanshell解释器将其视为 Java字符串

Your ${returnValue}statement is syntaxically incorrect, you need at least to surround it with quotation marks like "${returnValue}" so Beanshell interpreter would treat it as a Java String

展望未来,仅将此语句放入Beanshell Sampler并没有任何意义,您应该添加一些进一步的处理,即:

Going forward, just putting this statement inside the Beanshell Sampler doesn't make any sense, you should add some further processing, i.e:

  • return "${returnValue}";-将Beanshell Sampler结果设置为此值
  • SampleResult.setResponseData("${returnValue}".getBytes());-与上述相同,但使用的是 SampleResult 速记
  • print("${returnValue}");-将值输出到 STDOUT
  • log.info("${returnValue}");-将值输出到 jmeter.log 文件
  • return "${returnValue}"; - will set Beanshell Sampler result to this value
  • SampleResult.setResponseData("${returnValue}".getBytes()); - the same as above but using SampleResult shorthand
  • print("${returnValue}"); - output the value to STDOUT
  • log.info("${returnValue}"); - output the value to jmeter.log file

请参见如何使用BeanShell:JMeter最喜欢的内置工具组件有关在JMeter脚本中使用Beanshell的更多信息

See How to Use BeanShell: JMeter's Favorite Built-in Component for more information on using Beanshell in JMeter scripts

这篇关于Beanshell Sampler JMeter中用于解析RegularExpressionExtractor的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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