i am testing on a API and the response for the get request is given in the format of JSON. so by using JSON extractor i extracted the required data for my next sampler requests. the configuration of JSON extractor looks like this
Names of created variable = PET_ID
JSON path Expressions = $..[*].[?(@.name == 'doggie')].id
Match No. = -1
Default values = ERROR
by using the jsr223 post processor i stored the extracted values into a csv data set file and the code looks like this:
import org.apache.commons.io.FileUtils
import java.text.SimpleDateFormat;
// Get total number of matches. (Returns string)
def path = "C:/Users/M Rakesh/Downloads/JMETER/apache-jmeter-5.6.2/bin/test_csv_files/results.csv"
def resultCount = vars.get("PET_ID_matchNr")
log.warn 'Output to jmeter console ' + resultCount
// Generate timestamp to create uniue file name.
// String fileSuffix = new SimpleDateFormat("ddMMyyyyHHmm").format(new Date())
// Create file Object
f = new File("test_csv_files/results.csv")
for (int i=1; i<=resultCount.toInteger(); i++)
{
// Get each matching result one by one.
records = vars.get("PET_ID_"+i)
// Write result to csv file.
FileUtils.writeStringToFile(f,records + System.getProperty("line.separator"),true)
}
the stored values look like this
i cannot use the values which are stored in the csv file due to the data type and it is not showing the full id number
here are my questions:
- i want to store the full id number and use it later
- i want delete the data after the test execution is completed and recreate the csv file before the test execution. in this way i can save some storage while doing the test in load testing.
thank in advance for your help…!!