在JMeter中使用Excel中的数据进行数据驱动的测试时出错,

时间:2019-01-09 04:42:32

标签: excel apache jmeter apache-poi

我正在尝试读取存储在Excel电子表格的一列中的xml,并使用HTTP Sampler将它们发射到服务器,然后将响应xml存储在同一Excel中。 这是我在JMeter中测试计划的结构: enter image description here

但是我遇到了错误。 我无法查明发生错误的确切位置,但是我从结果树中获得了错误消息,如下所示:

对于JSR223采样器

  

响应消息:javax.script.ScriptException:源文件:内联   评估:import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.us . . . '' : Typed variable declaration : Attempt to resolve method: parseInt() on undefined variable or class name: INTEGER : at Line: 6 : in file: inline evaluation of:进口   org.apache.poi.xssf.usermodel.XSSFWorkbook;进口   org.apache.poi.xssf.us。 。 。 '':INTEGER .parseInt(vars .get(   内联评估中的“ counter”)))   org.apache.poi.xssf.usermodel.XSSFWorkbook;进口   org.apache.poi.xssf.us。 。 。 ”在第6行

HTTP请求采样器的“响应数据”选项卡中的错误显示为:

Exception occured: Parsing xml error, xml string is:${RQI}

BeanShell断言错误是:

  

断言错误:true断言失败:false断言失败   消息:org.apache.jorphan.util.JMeterException:调用bsh时出错   方法:eval在文件中:内联评估:``导入   org.apache.poi.xssf.usermodel.XSSFWorkbook;进口   org.apache.poi.xssf.us。 。 。 ”在第6行第65列遇到了“:”。

这是我在While控制器中的JSSR223采样器中使用的代码:

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFRow;
import java.io.*;

int i = INTEGER.parseInt(vars.get("counter"));
XSSFRow row = vars.getObject("book").getSheetAt(0).getRow(i);

vars.putObject("row", row);
for (int j = 1; j <= vars.getObject("book").getSheetAt(0).getRow(0).getLastCellNum(); j++) {
    if (row.getCell(j) == null) {
        row.createCell(j).setCellValue("");
    }
}

String payload = row.getCell(1).toString();
 vars.put("RQI",payload);
//String password = row.getCell(2).toString();
// vars.put("password",password);
//String expectedResult = row.getCell(5).toString();
// vars.put("expectedResult",expectedResult);

请协助。另外,为简洁起见,在本文中我省去了其他JSR223采样器的代码,请随时询问更多信息。预先谢谢你。

1 个答案:

答案 0 :(得分:1)

  1. 您必须更改此行:

    INTEGER.parseInt(vars.get("counter"));
    

    对此

    Integer.parseInt(vars.get("counter"));
    

    签出Integer类JavaDoc-Integer.parseInt()

  2. You should be using JSR223 Test Elements instead of Beanshell test elements and you should be using Groovy language in the JSR223 Test Elements

  3. 您可能会发现How to Implement Data Driven Testing in your JMeter Test参考有用。