Jmeter: Excel Upload, hard coded parameters passing in next request

柔情痞子 提交于 2019-12-02 18:11:15

问题


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.


回答1:


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())
    }
    

  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.
    

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



来源:https://stackoverflow.com/questions/53009824/jmeter-excel-upload-hard-coded-parameters-passing-in-next-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!