简体   繁体   中英

Jmeter select a random value from previous thread group variables

In my test plan, I have a setup thread group. I save the result of that setup thread group as a variable and use it in my following thread group. I was able to achieve this with the JSON extractor.

What I want to do is run the setup thread group multiple times so it can produce a pool of that variable. And in the following thread group, I randomly pick one from the pool to use. How can I achieve that?

I also have a teardown thread group, that needs to read from the pool of variable and tear down one by one.

  1. Add JSR223 PostProcessor after the JSON Extractor in the setUp Thread Group

  2. Put the following code into "Script" area:

     props.put('id_' + vars.get('__jm__setUp Thread Group__idx'), vars.get('id'))

    this will create the following JMeter Properties:

     id_0=value from 1st iteration id_1=value from 2nd iteration etc.
  3. Then in main or tearDown Thread Group you will be able to get the random value using __P() and __Random() functions combination like:

     ${__P(id_${__Random(0,4,)},)}

Demo:

在此处输入图像描述

More information:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM