How to Pass different Files as payload for different loop count

41 views
Skip to first unread message

Bijaya Ray

unread,
May 8, 2024, 6:59:50 AMMay 8
to JMeter Forum
Hi Team,

I want to send multiple XML files as Payload for IBM MQ Testing in JMETER5.6.2.

I have tried below options to get different files to run.

A. Using CVS Data set Config
1. Added JSR Sampler and passed the variable name like below
String filenameContents=new File(FilePath/file${num}.xml)
2.Created a CSV file with parameter value as 1,2,3... and variable name as num.
3.Created multiple XML files as file1.xml,file2.xml ...
Issue
This works well with multiple threads, each request taking different files. But not with single thread multiple loop count where each time taking 1st file only

B. Using Directory Listing Data source
1. Added JSR Sampler and passed the variable name like below
String filenameContents=new File(${filename})
2.Added Directory Listing Data source, browsed full path of file folder location,given Destination Variable name as filename.
3.Created multiple XMl files as file1.xml,file2.xml ...
Issue
In Test Directory Listing, all the files are showing properly, but Jmeter is throwing error as
MultipleCompilationErrorException : Start up failed : Unexpected character '\"

where it is expecting forward Slash '/'  for 
String filenameContents=new File(${filename})
JMeter expects filename with folder as filename = C:/Example/file1.xml
But gets as filename = C:\Example\file1.xml

Even tried with by providing ${__P(InstanceID)} fecthing only 1st files same with loop counter also.

Please help me in getting fetching multiple files for multiple iterations.

Thanks in advance

Bijaya

DT

unread,
May 8, 2024, 7:03:54 AMMay 8
to JMeter Forum
Don't inline JMeter Functions or Variables in Groovy scripts, it may resolve into something causing compilation failure. Another side effect is that only first occurrence will be cached and used on subsequent iterations.

Replace this line:

String filenameContents=new File(${filename})

with this one:

String filenameContents=new File(vars.get('filename'))

and it should resolve your issue

More information:

Bijaya Ray

unread,
May 8, 2024, 10:28:50 PMMay 8
to JMeter Forum
Thanks Team. It worked.
Reply all
Reply to author
Forward
0 new messages