4
votes

I'm newbie to Jmeter, my http request body is like:

{
   "List":{
      "ListAPPInfo":[
         {
            "first_time":"2013-06-24 10:00:00",
            "lasttime":"2013-06-24 10:00:00"
         }
      ],
      "device_id":"015d24a409441203",
      "device_model":"Nexus 7"
   }
}

I want to send Http sampler with random parameter like first_time value start at 2013-01-01 ends 2013-12-31

1

1 Answers

4
votes

You want to add sort of this tree node:

Simple Controller
  |_ HTTP Request Defaults
  |_ Your Request Controller
    |_ Random Variable Year
    |_ Random Variable Month
    |_ Other...

Now parameters of your random variable: Year

Random Variable: 
Variable Name: RND_YEAR
Output Format: 0000
Minimum Value: 0000
Maximum Value: 2999

Month

Random Variable: 
Variable Name: RND_MONTH
Output Format: 00
Minimum Value: 01
Maximum Value: 12

Day

Random Variable: 
Variable Name: RND_DAY
Output Format: 00
Minimum Value: 01
Maximum Value: 30

And other variables.

Please note, count of numbers in Format and Value should be equal.

Now put this kind of text ${RND_VARIABLE} into Your Request Controller request.

Like this:

{
   "List":{
      "ListAPPInfo":[
         {
            "first_time":"${RND_YEAR}-${RND_MONTH}-${RND_DAY} 10:00:00",
            "lasttime":"2013-06-24 10:00:00"
         }
      ],
      "device_id":"015d24a409441203",
      "device_model":"Nexus 7"
   }
}

Save and start your testplan.

You can use BeanShell processor to generate your random date http://justjmeter.blogspot.ru/2012/04/2.html http://jmeter.apache.org/usermanual/functions.html

If you want to substitute random string elements of some collection, you should write your own beanshell function inside of BeanShell PreProcessor on java.

import java.util.Random;

enum locales {UK, RU};
Random randGenerator = new Random();
int randInt = randGenerator.nextInt(locales.values().length);
vars.put("randomLocale",locales.values()[randInt].toString());

Then as usual you paste ${randomLocale} inside of your request.