Home page

Wednesday, December 12, 2018

Jmeter: How to generate new number like Data1, Data2, Data3... in Jmeter?

1. Add Config Element > User Defined variable under Test Plan
2. Add 2 variables like i) Name = counter & Value = 0 ii) Name = test
3. Add loop counter under Thread
4. Add BeanShell preprocessor
5. Add following code in BeanShell preprocessor


String s = "Data";
//Read value of user-defined variable "counter" > convert to int > increment by 1.
int counter = Integer.parseInt(vars.get("counter")) + 1; 

//convert counter to string and change value of user-defined variable.
vars.put("counter",Integer.toString(counter));

//Change value of user-defined variable "test"
vars.put("test",s.concat(Integer.toString(counter)));

Note: Use user-defined variable "test" in HTTP request sampler as ${test}

No comments:

Post a Comment