Ghost
Ghost

Reputation: 569

Jmeter Groovy class properties

In my Jmeter script at the beginning of the thread I have defined a class and a list array of those that class:

class TempClass{
   String Name;
   String Prop1;
}
props.put("TempClass", TempClass);
ArrayList<TempClass> tempList = new ArrayList<TempClass>();
vars.putObject("tempList", tempList);

I would like instantiate that class on one of the HTTP Req. post Processor with Groovy, then add its properties and add that class to an array of those classes.

i.e

//def t1 = new TempClass();
t1 = props.get("TempClass");
t1.Name= "Suzie";
t1.Prop1 = "3";


tempList = vars.getObject("tempList");    
tempList.add(t1);  
vars.putObject("tempList", tempList);

I get an error when I instantiate the class:

 No such property: Name for class: TempClass

Please help thanks

Upvotes: 0

Views: 952

Answers (1)

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34516

Correct code should be:

class TempClass{
   String name;
   String prop1;
}
props.put("TempClass", new TempClass());
ArrayList<TempClass> tempList = new ArrayList<TempClass>();
vars.putObject("tempList", tempList);

Then:

def t1 = props.get("TempClass");
t1.name= "Suzie";
t1.prop1 = "3";
tempList = vars.getObject("tempList");    
tempList.add(t1);  
vars.putObject("tempList", tempList);

Few notes about JMeter as I am not sure what you are trying to do:

  • Properties (props) are shared accross threads
  • Variables are specific to each user

Upvotes: 1

Related Questions