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
In BeanShellFunction.bshrc I have defined
printStr1(String str1)
{
System.out.println(str1);
}
printStr2(String str1, String str2)
{
System.out.println(str1, str2);
}
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
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);
}
As per JMeter documentation:
If a function parameter contains a comma, then be sure to escape this with "\", otherwise JMeter will treat it as a parameter delimiter
You need to amend your __Beanshell function call to escape the comma like:
${__BeanShell(printStr2("hello "\, "howAreYou"),)}
See Apache JMeter Functions - An Introduction article for more information on using JMeter functions.