0
votes

I am attempting to read xmls stored in one column of an Excel spreadsheet and fire them to a server using HTTP Sampler and then store the response xml in the same Excel. This is the structure of my test plan in JMeter: enter image description here

However I have encountered and error. I am not able to pinpoint the exact place where the error is taking place but I have obtained the error message from the Results Tree are as follows:

for the JSR223 Sampler

Response message: javax.script.ScriptException: Sourced file: inline evaluation of: 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; import org.apache.poi.xssf.us . . . '' : INTEGER .parseInt ( vars .get ( "counter" ) ) in inline evaluation of: ``import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.us . . . '' at line number 6

The error in the HTTP Request Sampler's Response Data tab reads as:

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

BeanShell Assertion error is :

Assertion error: true Assertion failure: false Assertion failure message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval In file: inline evaluation of: ``import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.us . . . '' Encountered ":" at line 6, column 65.

This is the code that I had used in the JSSR223 Sampler in the While Controller:

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);

Please assist. Also, feel free to ask for more information as I have left out the code for the other JSR223 Samplers in this post for brevity. Thank you in advance.

1
What is INTEGER? Do you mean Integer? Java class names are case sensitive.Axel Richter
I have corrected that. Thanks for pointing that out. But I still have errors and it seems like the loop keeps looping without and end. Below is the code for BeanShell String requestToApi = SampleResult.getSamplerData(); String responseFromApi = SampleResult.getResponseDataAsString(); vars.getObject("row").createCell(1).setCellValue(responseFromApi); String stopWhile = null; int i = Integer.parseInt(vars.get("counter")); if (i >= vars.getObject("book").getSheetAt(0).getLastRowNum()){ stopWhile = "OK"; vars.put("stopWhile",stopWhile); }user2749166
Please do not providing such infornations in comments. Instead edit your question. In your question the error clearly states Attempt to resolve method: parseInt() on undefined variable or class name: INTEGER.Axel Richter

1 Answers

1
votes
  1. You must change this line:

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

    to this one

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

    check out Integer class 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. You might find How to Implement Data Driven Testing in your JMeter Test reference useful.