Search code examples
javajmeterassertionsbeanshell

Jmeter - using jmeter function as bsh.args


I'm trying to send a function as a parameter in bealshell assertion component. the parameter is

${__V(SB_names_${counter})}

it's basically a dynamic string that is different in every iteration. I'm trying to access this parameter by

vars.get(bsh.args[2]);

since it's the 3rd parameter in the list, but I keep getting null.

enter image description here

is it possible at all to use jmeter function as parameter? or is the problem is with getting the parameter? Thanks.


Solution

  • It should work fine just:

    1. Make sure the variable is defined
    2. Remove all commas from "Parameters" section
    3. Remove all extra whitespaces from "Parameters" section.

    As a workaround you can consider getting the desired value from vars object which stands for JMeterVariables like:

    String sb_name = vars.get("SB_names_" + vars.get("counter"));
    

    Demo:

    Beanshell function

    Also consider moving to JSR223 Assertion and Groovy language as it is better from performance perspective. See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! guide for more information on groovy engine installation and scripting best practices.