简体   繁体   中英

how to save regular expression extractor output in a file(csv or any other format) in Jmeter

Hi StackOverflow Community,

I m working on Jmeter.I build a script running for our Web Application

In one request i fetched a value from Http Response using Regular Expression Extractor..all well..

RegEx_PRNumber I want to save this value in a file(csv,txt any format not an issue)

How this can be done in Jmeter

Thnks in Advance

To save the extracted value to a csv file follow the below procedure.

  1. Remove Regex extractor as we will extract from the response using JSR223 Post Processor
  2. Add JSR223 Post Processor and paste the below code in the script section. Choose language as " Groovy 2.4.12 / Groovy scripting engine 2.0 "

     import java.util.regex.Matcher; import java.util.regex.Pattern; import java.io.FileWriter; import java.io.Writer; String stringToSearch=prev.getResponseDataAsString(); Pattern p = Pattern.compile('value="(PR.+?)"'); Matcher match = p.matcher(stringToSearch); if (match.find()) { def value = match.group(1) log.info('------------------') log.info(value) // to check in the jmeter log for the extracted data vars.put('a', value) } //get path of csv file (creates new one if its not exists) FileWriter fileWriter = new FileWriter("C:\\Users\\Tarik\\Desktop\\example.csv",true); // true to append BufferedWriter out = new BufferedWriter(fileWriter); out.write(vars.get("a")); out.close(); fileWriter.close();

在此处输入图像描述

This worked, thank you. Used 'println' instead of 'write' to have consecutive values in a new line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM