问题
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:
- Add tika-app.jar to JMeter Classpath
- Restart JMeter to pick the .jar up
- Add JSR223 PreProcessor as a child of the request you want to parameterize
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()) }
- Remove all recorded hard-coded parameters from the HTTP Request
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