Shanmuga Priya
Shanmuga Priya

Reputation: 1

JMETER: we are trying to return array variable as output from BeanShell Processor

Is it possible ? Can someone provide us with a sample code? We have a beanshell preprocessor returning a set of variables to the JMX script. Can we return a array instead?

Upvotes: 0

Views: 2867

Answers (1)

Dmitri T
Dmitri T

Reputation: 168122

Following options are available:

  1. vars.putObject() - stores an arbitrary Java Object into a JMeter Variable like below:

    List myList = new ArrayList();
    myList.add("something");
    myList.add("something else");
    vars.putObject("myList", myList);
    

vars.putObject()

  1. props.put() or props.putAll() - the same but for JMeter Properties instead of JMeter Variables

  2. Use bsh.shared namespace like:

    In one sampler:

    int [] array = new int {1,2,3};
    bsh.shared.myArray = array;
    

    In another sampler:

    int [] array = bsh.shared.myArray;
    

See How to use BeanShell: JMeter's favorite built-in component for additional information on Beanshell scripting in Apache JMeter.

Upvotes: 2

Related Questions