Here is my simple Jmeter test plan.
User Parameters look like this:
I'm simply calling one endpoint, reading the response body and according to found IDs with the help of Regex Extractor I'm calling another endpoint. ForEach loop helps make sure for all the found IDs same endpoint is called with ID as parameter in the Path.
What I'm trying to achieve with Another HTTP Request inside ForEach loop is to read the response, and if body contains Monday, increment User Parameter Monday by 1, same for Tuesday and for every other User Parameter. Ideally at the end of the test suite, I should get something like this:
- Monday - 5
- Tuesday - 3
- Wednesday - null or zero
- Thursday - null or zero
- Friday - 1
- Saturday - 12
- Sunday - 8
According to my BeanShell script I hope I'm following all the right paths:
import org.apache.commons.lang.StringUtils;
String response = new String(data);
int Mondays = 0;
int Tuesdays = 0;
int Wednesdays = 0;
int Thursdays = 0;
int Fridays = 0;
int Saturdays = 0;
int Sundays = 0;
if(response.contains("'DayOfWeek':'Monday'")){
Mondays++;
vars.put("Monday", Mondays.toString);
};
if(response.contains("'DayOfWeek':'Tuesday'")){
Tuesdays++;
vars.put("Tuesday", Tuesdays.toString);
};
if(response.contains("'DayOfWeek':'Wednesday'")){
Wednesdays++;
vars.put("Wednesday", Wednesdays.toString);
};
if(response.contains("'DayOfWeek':'Thursday'")){
Thursdays++;
vars.put("Thursday", Thursdays.toString);
};
if(response.contains("'DayOfWeek':'Friday'")){
Fridays++;
vars.put("Friday", Fridays.toString);
};
if(response.contains("'DayOfWeek':'Saturday'")){
Saturdays++;
vars.put("Saturday", Saturdays.toString);
};
if(response.contains("'DayOfWeek':'Sunday'")){
Sundays++;
vars.put("Sunday", Sundays.toString);
};
My small problem here is that User Parameters variables never get updated and always at the end of the run equals to 0. What am I doing wrong in this situation? Has anyone faced this task before?