jmeter中的Excel处理可添加多个动态行 [英] Excel handling in jmeter to add multiple dynamic rows

查看:109
本文介绍了jmeter中的Excel处理可添加多个动态行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为jmeter中的上载场景创建一个excel文件.Excel具有3列,行数是来自参数文件的动态值.对于不同的Excel,行值不能具有相同的数据.所以我正在使用随机字符串来创建数据.通过对行数进行硬编码,我可以使用apache poi使用以下代码创建文件,但是面临处理动态行数的问题.有人可以提供解决方案吗?

I need to create an excel file for upload scenario in jmeter. The excel has 3 columns and number of rows is a dynamic value coming from parameter file. The row values cannot have same data for different excel. So I am using random string to create data. By hard coding number of rows I am able to create file with below code using apache poi but facing issues to handle dynamic number of rows. Can somebody please provide solution?

下面是创建5行的代码.

Below is the code which is working fine for creating 5 rows.

def path = FileServer.getFileServer().getBaseDir;
def separator = File.separator;
def sourceFileName = "CreateDynamicExcel";

HSSFWorkbook workbook = new HSSFWorkbook();

HSSFSheet sheet = workbook.createSheet("Billing");

Object[] dataTypes = [
["Column1Header","Column2Header","Column3Header"],
["${__RandomString(10,abcdefghij,)}","${__Random(100000000,199999999,)}","${__RandomString(10,abcdefghijklmnopqrst,)}"],
["${__RandomString(10,abcdefghij,)}","${__Random(100000000,199999999,)}","${__RandomString(10,abcdefghijklmnopqrst,)}"],
["${__RandomString(10,abcdefghij,)}","${__Random(100000000,199999999,)}","${__RandomString(10,abcdefghijklmnopqrst,)}"],
["${__RandomString(10,abcdefghij,)}","${__Random(100000000,199999999,)}","${__RandomString(10,abcdefghijklmnopqrst,)}"]];


int rowNum = 0;

for (Object[] datatype:datatypes)

HSSFRow = sheet.createRow(rowNum++);
int colNum = 0;
for(Object filed:datatype){
HSSFCell cell = row.createCell(colNumn+=);
if(filed.instanceof(String){
cell.setCellValue((String) filed);
}
if(filed.instanceof(Integer){
cell.setCellValue((Integer) filed);
}
}

try{

FileOutputStream out = new FileOutputStream(new File(path+separator+sourceFileName+".xls"));
workbook.write(out);
out.close();
}
catch(FileNotFoundException e){
e.printStacktrace();
}

推荐答案

我认为您不应该内联

I don't think you should be inlining JMeter Functions or Variables in Groovy scripts because:

  1. 它与Groovy冲突 GString模板引擎语法
  2. 只有第一个匹配项会被缓存并用于后续迭代

因此,您可以改用以下表达式:

So you can use the following expressions instead:

  • org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric(10)
  • org.apache.commons.lang3.RandomUtils.nextInt(100000000,199999999)

如果有任何问题,请查看 jmeter.log文件,如果有任何问题,您应该找到根本原因或至少有线索

In case of any problems - take a look at jmeter.log file, in case of any issues you should find the root cause or at least a clue there

这篇关于jmeter中的Excel处理可添加多个动态行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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