Reputation: 31
I have my jmeter test as below - I have a for each controller, under which there is a JDBC request & an beanshell assertion under it.
My beanshell asserstion code is like this -
String value1 = "${__V(statusapi_${__counter(,)})}";
String value2 = vars.get("status_db_1");
String value9 = vars.get("tenant");
print(value1);
if(value1 != null) {
if(!value1.equals(value2)) {
Failure = true;
FailureMessage = value9 + ": status name doesnt match, api: "+ value1 + " db: "+ value2;
print(FailureMessage);
} } else {
if(value2 != null) {
Failure = true;
FailureMessage = value9 + ": status name doesnt match, api: "+ value1 + " db: "+ value2;
print(FailureMessage);
} }
I am using counter function for value1. I want to know how can I reset this counter to start with 1 for a new for each request ?
Upvotes: 0
Views: 1435
Reputation: 168157
If you need the statusapi_
My expectation is that you're using the wrong test element, __counter() function is incremented each time it's being called. So I believe you should switch to Counter test element and configure it according to your scenario.
The Counter test element produces "normal" JMeter Variable which you can reset using i.e. vars.put("your_counter_reference_name", "1");
in Beanshell PreProcesssor.
Also be aware that starting from JMeter version 3.1 it is recommended to use JSR223 Test Elements and Groovy language for scripting so consider migration to JSR223 Assertion as soon as possible. More information: Apache Groovy - Why and How You Should Use It for more details.
Upvotes: 0