问题
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:
- Add JSR223 PostProcessor after the Regular Expression Extractor
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") })
Replate
my.csv
with the desired name of the CSV file andfoo
with the reference name of the variable defined in the Regular Expression ExtractorOnce 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