Use request value from list of values in JMeter

前端 未结 4 1036
萌比男神i
萌比男神i 2021-02-07 04:21

I\'m sure I\'ve already done this in the past but somehow I cannot figure out how ;-) So, here\'s my problem:

I\'m trying to create a JUnit test plan in which a HTTP re

4条回答
  •  北海茫月
    2021-02-07 05:17

    Concerning implementing ${__StringFromArrayAtRandomIndex('3', '2', '54', '42')}.

    Suppose you can easily implement your scenario using e.g. BeanShell Sampler / BeanShell PostProcessor with a bit of code.

    E.g.:

    • Set your source variable (via e.g. User Defined Variables):

      Name        Value          
      categories  3,2,54,42,37
      

      (i.e. use comma as delimiter, no spaces before and after comma).

    • Use add BeanShell Sampler/PostProcessor with the following code:

      import java.util.Random;
      
      String[] categories = (vars.get("categories")).split(",");
      
      int idx = new Random().nextInt(categories.length);
      String category = (categories[idx]);
      
      vars.put("categoryId", category);
      
    • Refer further in the script randomly picked form list value as ${categoryId}.

提交回复
热议问题