Reputation: 33
So right now I have my http request under a while controller and I have a user defined variable Failure set to true. I would like jmeter to keep trying this request until it succeeded (without returned 500). My while loop condition is:
${__javaScript(${Failure})}
I also tried ${Failure} as while condition but getting the same result.
And I have a JSR223 Assertion after the result tree as following:
if (ResponseCode.equals("500") == true) {
vars.put("Failure", true)
}
else {
vars.put("Failure", false)
}
When I ran this, I got into infinite loop even my request succeeded. It seems the Failure value was never updated. Any suggestion on this would be appreciated.
Upvotes: 0
Views: 1326
Reputation: 33
I finally got it working. In my JSR233 assertion, I updated it to:
if (prev.getResponseCode().equals("500")) {
vars.put("Failure", "true")
}
else {
vars.put("Failure", "false")
}
And it works now.
Upvotes: 0
Reputation: 168002
This is because you're trying to add a Boolean object into a function which expects a String. In order to be able to store a Boolean value into a JMeter Variable you need to use vars.putObject() function instead like:
vars.putObject("Failure", true)
or surround true
with quotation marks so it would look like a String to Groovy:
vars.put("Failure", "true");
Amend your JSR223 Assertion code to look like:
if (ResponseCode.equals("500")) {
vars.put("Failure", "true")
}
else {
vars.put("Failure", "false")
}
Amend your While Controller condition to be just ${Failure}
. Using JavaScript is a form of a performance anti-pattern, if you need to perform some scripting - go for Groovy. In particular your case you can just use ${Failure}
variable as the condition given it can be either true
or false
Upvotes: 2