Search code examples
jmetervoidbeanshelluser-defined

How to write dynamic variable in beanshell post processor?


We have user defined variable name as "search".

I am using below line to write in csv file in beanshell postprocessor but its showing me "void" in csv file:

print(${search});

please help.


Solution

    1. Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting therefore consider switching to Groovy
    2. Don't refer JMeter Functions and/or Variables in scripts directly as it might cause unexpected behavior or script malfunction. Either use "Parameters" tab or go for code-based equivalents
    3. Beanshell print() function basically writes the value to STDOUT, if you want to write the value to a file you should do it differently.

    Assuming all above you should be using something like:

    new File("/path/to/your/file.csv") << vars.get("search")
    

    More information: Apache Groovy - Why and How You Should Use It