0

I have a BeanShell PostProcessor under the setUp Thread Group.
It generates an ArrayList that I want to pass as a system property to the test Thread Groups in the Test Plan.
That array contains the number of threads in the test groups.
What is the syntax? How should I refer an element of that array in the Tread Group "Number of Threads (users)"?

This is what I have in the setUp Thread Group

ArrayList users = new ArrayList();
${__setProperty(users, ${users})};

This is what I put in the Number of Threads

${__P(users).get(0)}

It does not work.
Thanks enter image description here enter image description here

1 Answer 1

1

If you really need the "ArrayList" you can go it using bsh.shared namespace

  1. In setUp Thread Group put the ArrayList into the "bsh.shared" namespace like:

    ArrayList users = new ArrayList();
    users.add(5);
    bsh.shared.users=users;
    
  2. In normal Thread Group you can read the value via __BeanShell function as:

    ${__BeanShell(bsh.shared.users.get(0),)}
    

However I feel that your test is badly designed and you could get rid of scripting or at least of using arrays.

Sign up to request clarification or add additional context in comments.

3 Comments

Dmitri, Your suggestion does not work. I attached the screenshots. Why do you think it's a bad design? I read a JSON file one time in the setUp Thread Group and pass all arrays of variables to the other thread groups in the test plan.
My suggestion does work, your Beanshell PreProcessor in the setUp Thread Group does not work as PostProcessors are designed for using in conjunction with Samplers, if there is no sampler - the postprocessor is being ignored. Change it to sampler and everything will start working as expected. See How to Use BeanShell: JMeter's Favorite Built-in Component article for more details on using Beanshell scripting in JMeter tests.
Thank you, Dmitri. It really works now! In my real example, I have an HTTP sampler and BeanShell PostProcessor attached to it. Your solution will work in that case as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.