I'm trying to save the response of failed requests into log but unsuccessfully.
I have HTTP requests which each one has its own Response assertion, and once in a while through my load test a response doesn't meet the requirements of the Response Assertion, so I want to fail it.
I tried to add this code to the BeanShell Assertion
following this post:
if (Boolean.valueOf(vars.get("DEBUG"))) {
for (a: SampleResult.getAssertionResults()) {
if (a.isError() || a.isFailure()) {
log.error(Thread.currentThread().getName()+": "+SampleLabel+": Assertion failed for response: " + new String((byte[]) ResponseData));
}
}
}
The Test plan itself looks like this:
In user defined variables I've added the following: Name: DEBUG Value: (none)
I ran this program through the non GUI mode - cmd and on purpose made a response fail (response assertion failed it) but I did not get any error response logged to my log file. What am I doing wrong? thanks
I would rather let JMeter do this automatically, it is the matter of a couple of properties, to wit:
First of all, you need to tell JMeter to store its results in XML format:
Second, you can amend the following property values to configure JMeter to store assertion failure message and data into .jtl results file
Probably the most useful option: simply save response data for failed samplers:
The above properties can be either put into user.properties file (located in JMeter's "bin" folder, JMeter restart is required to pick the changes up) or you can pass them via
-J
command line argument like:See Apache JMeter Properties Customization Guide for more information on working with JMeter Properties to tune various aspects of JMeter configuration