【问题标题】:Error while doing Data-Driven Testing in JMeter using data in Excel使用 Excel 中的数据在 JMeter 中进行数据驱动测试时出错
【发布时间】:2019-01-09 04:42:31
【问题描述】:

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

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

用于 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:import org.apache.poi.xssf.usermodel.XSSFWorkbook;进口 org.apache.poi.xssf.us 。 . . '' : INTEGER .parseInt ( vars .get ( "counter" ) ) 内联评估:``import 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 在文件中:内联评估:``import 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 采样器的代码。提前谢谢你。

【问题讨论】:

  • 什么是INTEGER?你的意思是Integer? Java 类名区分大小写。
  • 我已经更正了。感谢您指出了这一点。但我仍然有错误,似乎循环一直在循环,没有结束。下面是 BeanShell String requestToApi = SampleResult.getSamplerData(); 的代码String responseFromApi = SampleResult.getResponseDataAsString(); vars.getObject("row").createCell(1).setCellValue(responseFromApi);字符串 stopWhile = null; int i = Integer.parseInt(vars.get("counter")); if (i >= vars.getObject("book").getSheetAt(0).getLastRowNum()){ stopWhile = "OK"; vars.put("stopWhile",stopWhile); }
  • 请不要在 cmets 中提供此类信息。而是编辑您的问题。在您的问题中,错误清楚地说明了Attempt to resolve method: parseInt() on undefined variable or class name: INTEGER

标签: excel apache jmeter apache-poi


【解决方案1】:
  1. 你必须改变这一行:

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

    到这个

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

    查看整数类 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 参考很有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 2017-08-05
    • 2010-11-18
    相关资源
    最近更新 更多