Handling Error Messages of JMeter Tests in Loadium

Errors found during testing is a part of the process, tests are done to find them after all. After finding an error, understanding its reason is crucial. Some errors are easy to understand and recognize if they reveal themselves clearly, but sometimes errors are hard to detect and if their reason isn’t clear it might even lead to more confusing results.
There might be several reasons for an error to occur. It could be due to a logical error in the script, or while the script is doing its work properly, server might mess up when processing it.

Jmeter Functions

JMeter has a built-in functionality that allows us to handle error messages. Since JMeter is a Java application which is an OOP language, there is access to some objects that come in handy. One of them is the “Prev” class’ “prev” object that allows us to do workarounds for error messages, which you can find the complete documentation here:
Let’s take a look at some methods from this class:
  • getResponseCode() – Returns the last executed sample’s response code
  • setResponseCode() – Sets a custom response code to the last executed sample
  • getResponseDataAsString() – Returns the last executed sample’s response body
By using only these 3 methods, we can easily handle the error messages.

Example Case

Sometimes the message contained in the response code or the code itself isn’t self-explanatory enough. Likewise, there may be more detailed information of the error in the response body, and since what’s included in the body by default is not available to be seen in the report screen “Error” page, a configuration can be done to make it visible.
For example, the response error message “Internal Server Error” does not show the reason clearly, and if there is a possibility that its body contains information about the error, it is better for it to be shown here. For this, we can make a configuration in a JSR223 PostProcessor like the following:
And with the function:
if(prev.getResponseCode() == "500"){ prev.setResponseMessage(prev.getResponseDataAsString());
In Jmeter, instead of standart "Internal Server Error" message, we will get a message as shown below:
While in Loadium Report Screen, we will get the following result in Response Codes Page or Errors Page:
Happy testing!
If you don't see the answer to your question here, please reach out to us to let us know! We're always improving our documentation.