如何在Blazemeter中运行groovy脚本,尝试访问csv文件数据?

如何在Blazemeter中运行groovy脚本,尝试访问csv文件数据?,csv,groovy,jmeter,blazemeter,Csv,Groovy,Jmeter,Blazemeter,我有一些关于groovy的Jmeter脚本 1.upto(${amount_of_items}, { index -> def data = new File('data/ids.csv').readLines().get(index).split(',') def attr = [:] attr.put('id', data[0].toInteger()) def attributes = [:] def param = [:] param.put('quantity', ${qua

我有一些关于groovy的Jmeter脚本

1.upto(${amount_of_items}, { index ->
def data = new File('data/ids.csv').readLines().get(index).split(',') 
def attr = [:]
attr.put('id', data[0].toInteger()) 
def attributes = [:]
def param = [:]
param.put('quantity', ${quantity})
param.put('status_id', 4)
attributes.put('statuses', [param])
attributes.put('identity', attr)
adjustItems.add(attributes)
})
是否有任何解决方案可以访问我试图从Blazemeter解析的csv

def data = new File('data/ids.csv').readLines().get(index).split(',') 

我是否可以将我的csv上载到Blazemeter中的共享文件夹并在脚本中使用它?

如果您将文件上载到共享文件夹,访问Blazemeter中的文件应该不会有问题。有关更多详细信息,请参阅文章

还根据:

JSR223测试元素具有可以显著提高性能的特性(编译)。要从该功能中获益,请执行以下操作:

使用脚本文件而不是内联它们。如果此功能在ScriptEngine上可用,这将使JMeter编译并缓存它们。 或者使用脚本文本并检查缓存已编译脚本(如果可用)属性

使用此功能时,请确保脚本代码不直接在脚本代码中使用JMeter变量或JMeter函数调用,因为缓存只会缓存第一次替换。请改用脚本参数

因此,我建议修改您的代码,以便对类实例使用
vars
速记,如:

1.upto(vars.get('amount_of_items') as int, { index ->
    def data = new File('data/ids.csv').readLines().get(index).split(',')
    def attr = [:]
    attr.put('id', data[0].toInteger())
    def attributes = [:]
    def param = [:]
    param.put('quantity', vars.get('quantity') as int)
    param.put('status_id', 4)
    attributes.put('statuses', [param])
    attributes.put('identity', attr)
    adjustItems.add(attributes)
})

但并没有关于从共享文件夹设置此文件的绝对路径的信息,例如,当我试图从groovy脚本访问它时,“文件夹/文件名”不起作用