How to save request and response details in JMeter only when an error occurs

on 27 February 2023 CI, CONTINUOUS INTEGRATION, DEVOPS, JMETER, monitoring, PERFORMANCE and Tags: , , , , , with 0 comments

When an request error occurs during a performance test, you usually want to have more details on the request and response to understand root cause of the issue and provide more details to the development team so that they are able to reproduce and fix the issue.

Configuring your test plan

To save request and response details in JMeter only when an error occurs, you can use the combination of a “Response Assertion” and a Listener “Simple Data Writer

Response Assertion

This component will help you defined what is an “Error” in your test case.

It can be added by “Add > Assertions > Response Assertion”.
By default JMeter will consider any HTTP response code >= 400 as an error, in this case you have nothing to do.
But usually, you’ll want to have additional checks on a response by checking the presence of a text in the response for example.

Read this blog for more details on this component.

Saving errors to a file

This listener allows you to save the results of your test to a file. You can add this listener by right-clicking on the “Thread Group” or “Test Plan” and selecting “Add > Listener > Simple Data Writer”.

In our case, we only want to save Errors so we check “Errors” checkbox:

Simple Data Writer setup

We then set “Filename” field to:


Finally, to have the full details of HTTP request and response, we click on “Configure” button and check the fields we want so that we have this:

Simple Data Writer save to file Configuration

Reading error file

Then you can run your test, you will have an additional output file called “errors.xml” that will contain the full details of requests that failed.

You can read this file using JMeter, by adding a “View Results Tree” and clicking on “Browse” button, it will show you all elements of a request / response including headers for HTTP for example:

About UbikLoadPack: