Reputation: 1645
I would like to perform an assertion on a sampler only if certain conditions are met (i.e. variables and parameters have a specific value). The assertion should be ignored if the conditions are not met, not fail.
What are my options?
An if controller does not seem to work as it apparently requires the sampler (which always should be invoked) to be in its scope too.
Upvotes: 0
Views: 197
Reputation: 168072
I can only think of using JSR223 Assertion which allows you executing arbitrary Groovy code providing maximum flexibility.
Here is an example simple code:
if (vars.get('foo') == 'bar') { // execute only if JMeter Variable ${foo} is equal to "bar"
if (!prev.getResponseDataAsString().contains('baz')) { // if there is no "buz" word in the response
assertionResult.setFailure(true) //fail the sampler
assertionResult.setFailureMessage('Failed to find word "baz" in the response')
}
}
Check out Scripting JMeter Assertions in Groovy - A Tutorial article for more information.
Upvotes: 1