Write Response to File in JMeter

JMeter provides range of features to carry out effective performance testing. Apart from all the features provided out of the box, it also lets us create custom solutions for our specific requirements. Recently we encountered a need to extract a specific part of response data and write it in an external file. While this may look a daunting task at first, it turned out to be relatively easy by utilizing some JMeter components. We have written this tutorial to show how we can do this. We will write response to file in JMeter. But first, let’s take a look at the scenario in question.

Scenario:

We wanted to retrieve email and access token from response data and write them both in a CSV file for later use. We used Regular Expression Extractor for fetching email and access token from received response data. Now, to write them in CSV file, we’ll need a simple BeanShell script.

Solution:

  • Write a regular expression to extract email from response as below.

    Write Response to File in JMeter

    Fetching Email

  • Write a regular expression to extract access token.

    Write Response to File in JMeter

    Fetching Access Token

  • We now have email and access token values stored in ’email’ and ‘access_t’ variables respectively.
  • Add BeanShell PostProcessor under HTTP Request sampler in JMeter.
  • Write below code in BeanShell PostProcessor.
  • Run your test. A CSV file will be created containing email and access token at the location that you have specified in BeanShell script.

So this is how we write response to file in JMeter. Now that you have this setup working on your system, let us know in comments how we can refine it further.

Reference

Comments
  1. Femi
  2. Bashudha
  3. Tanya
  4. Janardhan
  5. Rohit Tyagi
  6. sachit

Leave a Reply

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