Jmeter将两个参数传递给自定义函数 [英] Jmeter passing two parameters to a custom function
问题描述
在Jmeter中,我可以通过一个参数传递工作来获取自定义函数,但是我不能通过两个参数传递工作来获取自定义函数
In Jmeter I am able to get a custom function with one parameter passing work, however I am not able to get a custom function with two parameter passing working
在BeanShellFunction.bshrc中,我已定义
In BeanShellFunction.bshrc I have defined
printStr1(String str1)
{
System.out.println(str1);
}
printStr2(String str1, String str2)
{
System.out.println(str1, str2);
}
在我的Jmeter BeanShell断言中
In my Jmeter BeanShell Assertion I have
${__BeanShell(printStr1("hello"))}
${__BeanShell(printStr2("hello", "howAreYou"))}
我确实看到了->你好 我看不到第二个功能的结果 某种程度上,第二个参数传递不起作用
I do see --> hello I do not see the second function results somehow the 2nd parameter passing is not working
从jmeter日志中,我看到: 2018-04-11 18:17:56,348错误oajuBeanShellInterpreter:调用bsh方法时出错:eval在文件中:内联评估::"printStr2("hello";在第1行遇到了"(\"hello \";",第10列.
From jmeter log I see: 2018-04-11 18:17:56,348 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval In file: inline evaluation of: ``printStr2("hello";'' Encountered "( \"hello\" ;" at line 1, column 10.
推荐答案
You need to amend your
printStr2
function as PrintStream.println() method can accept only a single string. Change it to something like:
printStr2(String str1, String str2)
{
System.out.println(str1 + str2);
}
根据JMeter 文档:
如果函数参数包含逗号,请确保使用"\"将其转义,否则JMeter会将其视为参数定界符
If a function parameter contains a comma, then be sure to escape this with "\", otherwise JMeter will treat it as a parameter delimiter
您需要修改__Beanshell函数调用以转义逗号,例如:
You need to amend your __Beanshell function call to escape the comma like:
${__BeanShell(printStr2("hello "\, "howAreYou"),)}
有关更多信息,请参见 Apache JMeter函数-简介文章,以获取更多信息.有关使用JMeter功能的信息.
See Apache JMeter Functions - An Introduction article for more information on using JMeter functions.
这篇关于Jmeter将两个参数传递给自定义函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!