0
votes

I am able to extract values for many variables and are showing in Debug Sampler.

Is there any way to save these all variable values to a CSV file?

I found a solution (using BeanShell script) to save multiple Jmeter variable to CSV but I want all variables values to a single CSV, so that I can use the CSV file for next thread run.

Here is the snapshot of one of the Debug Sampler:

enterCompanyname=APITENANT
CreateTenant_Status=Success
CreateTenant_Status_matchNr=1
Current_UTC_Time=2018-03-07T01:53:18.310Z
DB_DataSource=dev4574857
DB_Password=1234
DB_UserName=web
DeviceCount=19
DevicesPerUser=94
EXCELPATH=X:\QualityAssurance\XLSX_3 columns_1000 rows.xlsx
[email protected]
EndDate=2018-12-31
Exist=false
Exist_matchNr=1
FirstName=API
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage@69ab73cf
LastName=TENANT
LicensePlan=Pro
LicenseType=Device
MaxUsers=11
Password=Password
Protocol=http
RandomNumber=10
1

1 Answers

3
votes
  1. Add JSR223 Sampler to your Test Plan (where you want variables to be saved)
  2. Put the following code into "Script" area:

    def csv = new File('vars.csv')
    vars.entrySet().each {var ->
        csv << var.key + '=' + var.value + System.getProperty('line.separator') 
    }
    
  3. That's it, you will have vars.csv file created in JMeter's "bin" folder having all variables listed. You might also want to replace = with , for better CSV Data Set Config compatibility.

vars is a shorthand to JMeterVariables class instance, it provides read/write access to all JMeter Variables.

Also be aware that starting from JMeter 3.1 users are encouraged to switch to JSR223 Test Elements and Groovy language so consider migrating to Groovy as soon as it will be possible. See Apache Groovy - Why and How You Should Use It for more details.