0

I have recorded a Jmeter script where an excel with 4 records has been uploaded and in the next request the 4 values in the excel are passed as different parameters. But when I wil change the excel/no. of values changed to 100. How the request will take the new values of excel.

As there will be more than 100 records and the record count is not known, so parameterization and correlation is not possible.

Please help.

PP1
  • 9
  • 5

1 Answers1

0

If you have Excel (xlsx) file under name of test.xlsx in "bin" folder of your JMeter installation you can dynamically populate request parameters using the following approach:

  1. Add tika-app.jar to JMeter Classpath
  2. Restart JMeter to pick the .jar up
  3. Add JSR223 PreProcessor as a child of the request you want to parameterize
  4. Put the following code into "Script" area:

    def workbook = new org.apache.poi.xssf.usermodel.XSSFWorkbook(new File("test.xlsx"))
    def sheet = workbook.getSheetAt(0)
    0.upto(sheet.getLastRowNum()) {
      def row = sheet.getRow(it)
      def cell = row.getCell(0)
      sampler.addArgument('parameter' + it, cell.getStringCellValue())
    }
    

    JMeter data from excel

  5. Remove all recorded hard-coded parameters from the HTTP Request
  6. That should be it, when you run your test the above Groovy script will add the following parameters:

    parameter1=record1
    parameter2=record2
    etc.
    

    JMeter data driven excel parameters

Check out How to Implement Data Driven Testing in your JMeter Test article for more detailed explanation if needed.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks Dmitri.. I am getting error while putting this code:ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor javax.script.ScriptException: javax.script.ScriptException: org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the specified file input stream from file: 'Z\apache-jmeter-3.3\apache-jmeter-3.3\bin\Full Award Spreadsheet Sample2.xls' at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:158) ~[groovy-all-2.4.12.jar:2.4.12] at javax.script.AbstractScriptEngine.eval(Unknown Source) ~[?:1.8.0_181] – PP1 Oct 26 '18 at 14:32