Reputation: 357
How to add assertion on response message in jsr223 postprocessor using java code.
I tried using AssertionResult.setFailure(true);
but it is not working
Upvotes: 3
Views: 2949
Reputation: 58862
Use JSR223 Assertion instead JSR223 PostProcessor
JSR223 Assertion allows JSR223 script code to be used to check the status of the previous sample.
You are missing calling setFailureMessage
AssertionResult.setFailureMessage("Your reason for failure");
The script can check various aspects of the
SampleResult
. If an error is detected, the script should useAssertionResult.setFailureMessage("message")
andAssertionResult.setFailure(true)
.
Upvotes: 2
Reputation: 168157
Something like:
def expectedMessage = 'some expected message'
def actualMessage = prev.getResponseMessage()
if (expectedMessage != actualMessage) {
AssertionResult.setFailure(true)
}
Should do the trick for you, in the above example prev
stands for previous SampleResult
Demo:
More information: Scripting JMeter Assertions in Groovy - A Tutorial
Also get used to look at jmeter.log file, it might be the case your script fails somewhere somehow
Upvotes: 0