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 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 even using only these 3 methods, we can easily handle the error messages.
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 to be shown here. For this, we can make a configuration in a JSR223 PostProcessor like the following: