JMeter – Save Responses to a file

Let’s consider, you run the script in the actual load test and often getting an error at a particular step. Now, you want to know the error message coming inside the response body to check what is the root cause of the error. One of the solutions is to add a ‘View Results Tree’ listener and configure it appropriately so that you can get the response body. But the first thing is that it is not advisable to add a listener during the actual performance test. The second thing is choosing the correct configure options from a long list to get the appropriate log is a tedious task. And, the third thing ‘View Results Tree’ create a heavy file and degrade the performance of the JMeter.

To solve the above-mentioned issue and get the proper response body, JMeter added a new element called ‘Save Responses to a file’.

The element ‘Save Responses to a file’ has a wide variety of options to choose the appropriate log type and save in a file along with a variable to be used later in the test execution.

  • Name: You can provide an arbitrary name to the element
  • Comment: You can provide a comment as a description of the step
  • Save Conditions: You can filter-out the response on the basis of pass/fail status
    • Save Successful Responses only
    • Save Failed Responses only
    • Don’t save Transaction Controller SampleResult
  • Save Details:
    • Variable Name containing saved file name: It is optional. If you want to save the file name in a variable then provide the name of that variable. Eg. varFileName. If there are sub-samples then a numeric suffix will be added to the variable name. Consider a variable name is varFileName then the parent sample file name will be saved in the variable varFileName and the filenames for the child samplers will be saved in varFileName1, varFileName2 etc.
    • Filename prefix (can include folders): Provide the full path where you want to save the file. The default location is jmeter/bin. Never use any Variable like ${varName} or functions like ${__threadNum} in this field.
    • Don’t add number to prefix: Consider you run the JMX with 5 threads for 1 loop then 5 files will be created which are separated by numeric suffix. Eg. saveFile1.json, saveFile2.json, saveFile3.json, saveFile4.json, saveFile5.json. To restrict this behaviour, this option is checked. When you checkmark this option then the file will be overwritten.
    • Don’t add content type suffix:
    • Add timestamp
    • Minimum Length of sequence number
JMeter - Save Responses to a file
Figure 01: Save Response to a file

Purpose:

  1. Basically, ‘Save Responses to a file’ is used for functional test purpose.
  2. For debugging purpose during the Performance Sanity Test.
  3. When the response is too large to display in the ‘View Results Tree’ then ‘Save Responses to a file’ is used to capture the full response.

Important Points:

  1. The file name is created from the specified prefix along with a number (unless this is disabled) every time when the parent sampler is executed. If there are 2 threads with 2 loop count then 4 files will be created. Eg. DemoTestFile1.json, DemoTestFile2.json, DemoTestFile3.json, DemoTestFile4.json etc.
  2. The file extension is created from the document type if known. If not known, the file extension is set to ‘unknown’.
  3. If numbering is disabled and adding a suffix is disabled then the file prefix is taken as the entire file name. This allows a fixed file name to be generated if required.
  4. The generated file name is stored in the sample response and can be saved in the test log output file if required.
  5. The current sample is saved first, followed by any sub-samples (child samples). If a variable name is provided then the names of the files are saved in the order that the sub-samples appear. 

You may be interested in:


Leave a Reply

Your email address will not be published. Required fields are marked *