我在JMeter中遇到问题,我收到此错误
2014/08/14 14:13:26 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``String RequestUrl = vars.get("RequestUrl"); String[] params = RequestUrl.split(" . . . '' : Typed variable declaration
2014/08/14 14:13:26 WARN - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``String RequestUrl = vars.get("RequestUrl"); String[] params = RequestUrl.split(" . . . '' : Typed variable declaration
Run Code Online (Sandbox Code Playgroud)
我不知道什么是错的,否则代码似乎工作正常.谁能给我一些建议?
这是有问题的代码块:
String RequestUrl = vars.get("RequestUrl");
String[] params = RequestUrl.split("\\?");
String RequestTask = params[1].split("\\&")[1].split("=")[1];
System.out.println(RequestTask);
vars.put("RequestTask",RequestTask);
Run Code Online (Sandbox Code Playgroud)
应该提到代码是在后处理器中,它与"RequestUrl"的Xpath提取器配对
编辑包括整个错误
Dmi*_*i T 14
我没有看到你的URL以及XPath查询返回什么,但无论如何你的URL解析逻辑看起来很脆弱,因为它强烈依赖于参数顺序和存在,并且如果请求URL更改,可能会让你回来,即额外参数或更改参数顺序或编码的东西等
见下面的参考:
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import java.net.URI;
import java.util.List;
String url = vars.get("RequestUrl");
List params = URLEncodedUtils.parse(new URI(url), "UTF-8");
for (NameValuePair param : params) {
if (param.getName().equals("put your actual param name here")) {
vars.put("RequestTask", param.getValue());
}
}
Run Code Online (Sandbox Code Playgroud)
还值得一试如何使用BeanShell:JMeter最喜欢的内置组件,用于故障排除提示.通常,应使用本地化错误日志记录,如:
log.info("something");
log.error("something else");
Run Code Online (Sandbox Code Playgroud)
因此,如果您没有在日志中看到消息,那么Beanshell无法执行该行并在上面某处失败.
另外,Beanshell错误消息的信息量不大,我在脚本中使用以下构造:
try {
//script logic here
}
catch (Throwable ex) {
log.error("Failed to do this or that", ex);
}
Run Code Online (Sandbox Code Playgroud)
因此可以在jmeter.log文件中读取错误stracktrace.
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
33580 次 |
| 最近记录: |