0

Attempting to create a request with JMeter where the request has to retry until a JSON variable ($.result.status) of the response meets the expected result. In detail, the request should retry untill the value of the variable turns into "completed" from "pending" state.

For this I have used to a While Controller with the following JS condition. It works perfectly in the 1st iteration/loop and exits the While-Controller once the resultStatus turned into "completed"

${__javaScript("${resultStatus}" == "pending" || "${resultStatus}" != "completed" || "${resultStatus}" == "" )}

But, from the 2nd loop onward the While-Controller is getting skipped.

I assume the reason was because the resultStatus variable was assigned to "completed" along with the exit for the While-Controller in the 1st loop and remains as it is when it comes to the While controller in the second loop. Therefore the condition is getting false..

With that assumption, I tried vars.remove for BeanShellPostProcessor in While-Controller with following code snippet. But it didn't resolve my issue.

String x = vars.get("resultStatus");
if ( x == "completed"){
vars.remove("resultStatus", "completed");}

Below is the structure of the Jmeter Tree. enter image description here

  • Red Box : While Controller
  • Red Arrow Point : Response Variable Change
    from Pending to Completed and Step-in to Loop 2

Could it be the reason I assumed for this issue of skipping the While controller from 2nd loop?
If it is; What is approach I should take to clear the variable value?

If it is not the reason I assumed, Can I kindly get assisted with the reason and a solution?

Community
  • 1
  • 1
hirosht
  • 932
  • 2
  • 17
  • 31

3 Answers3

2

Use JSR223 Sampler to reset the value to something else then expected.

-TestPlan

--WhileLoop

---JSR223

Use the below in JSR223:-

vars.put("resultStatus","Reset")

Hope this help.

sunny_teo
  • 1,961
  • 1
  • 7
  • 11
1

remove method get only 1 parameter, the key,

remove(java.lang.String key)

So your syntax is wrong, also compare String using equals method, use:

String x = vars.get("resultStatus");

if ( "completed".equals(x) ){
    vars.remove("resultStatus");
}
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0

JSR223 Sampler will solve this as mentioned in the previous comment.Just to remove the confusion Reset does not change the status we should use the desired value we want the variable to be updated with .

Below is the info from the java docs put(String key, String value) Creates or updates a variable with a String value.

In my case below solution worked for me vars.put("status","PENDING")

Bharath M
  • 21
  • 1