JMeter extract all values from regular expression and store in a csv

半腔热情 提交于 2019-12-11 15:16:34

问题


I am trying to extract all extracted values from regular expression extractor from multiple regular expressions and store it in a csv format.

I have tried for each controller after each extraction of values, how ever controller allows only one variable at a time. I would need to extract multiple variables in a single csv as part of data preparation and input to an another script. Any idea how can i achieve this requirement. Thanks


回答1:


  1. Add JSR223 PostProcessor after the Regular Expression Extractor
  2. Put the following code into "Script" area:

    def csv = new File("my.csv")
    1.upto(vars.get("foo_matchNr") as int, {
        csv << vars.get("foo_$it") << System.getProperty("line.separator")  
    })
    
  3. Replate my.csv with the desired name of the CSV file and foo with the reference name of the variable defined in the Regular Expression Extractor

  4. Once you run your script you will see a new CSV file in JMeter's "bin" folder containing values from the Regular Expression Extractor, each value on a new line

More information:

  • Groovy Looping Structures
  • Apache Groovy - Why and How You Should Use It



回答2:


In regular expression extractor use "Match No." as -1 to get multiple values. Then use each controller to get the values like Eachvariable_1, Eachvariable_2 etc. Alternatively, you can fetch the values directly like var_1, var_2. Here, var is the name of the regular expression created variable.

Then, use JSR223 post processor and write the extracted values in the csv. Hope this helps.

Also, note the below point if you are using For Each Controller:-

JMeter will expose the looping index as a variable named jm__idx. So for example, if your Loop Controller is named FEC, then you can access the looping index through ${__jm__FEC__idx}. Index starts at 0



来源:https://stackoverflow.com/questions/51284957/jmeter-extract-all-values-from-regular-expression-and-store-in-a-csv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!