JMeter从正则表达式提取所有值并将其存储在csv中 [英] JMeter extract all values from regular expression and store in a csv

查看:564
本文介绍了JMeter从正则表达式提取所有值并将其存储在csv中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从多个正则表达式中提取正则表达式提取器中的所有提取值,并将其存储为csv格式.

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

我已经尝试过在每次提取值后为每个控制器进行操作,但是控制器一次只允许一个变量.我需要在单个csv中提取多个变量作为数据准备的一部分,并输入到另一个脚本中.任何想法我怎么能达到这个要求.谢谢

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. 添加 JSR223后处理器 之后表达提取器
  2. 将以下代码放入脚本"区域:

  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")  
})

  • 使用所需的CSV文件名称重新标记my.csv,并使用在正则表达式提取器中定义的变量的参考名称重新标记foo

  • 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

    运行脚本后,您将在JMeter的"bin"文件夹中看到一个新的CSV文件,其中包含来自正则表达式提取器的值,每个值都在新行上

    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

    更多信息:

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

    这篇关于JMeter从正则表达式提取所有值并将其存储在csv中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆