Reputation: 1086
I want to upload audio file for multiple thread from Http Request in JMeter. I have a folder which contains a number of audio file. I want that it take audio file from folder randomly. How can i do it?
Upvotes: 0
Views: 1249
Reputation: 15400
You can go with Dmitri answer.
Another approach:
If possible, you can change the audio files names like this - audio1.mp3
, audio2.mp3..etc
In the HTTP request file path
field, update the file name as (assuming you have 100 files),
c:\path\to\audio${__Random(1,100)}.mp3
${__Random(1,100)}
--> Generates a random number between 1 and 100
Upvotes: 2
Reputation: 168157
You can use Beanshell PreProcessor to dynamically get random file path from the specified folder.
To do so:
Put the following code into the PreProcessor's "Script" area:
File folder = new File("/path/to/your/folder/with/audiofiles");
File[] audioFiles = folder.listFiles();
Random rnd = new Random();
vars.put("CURRENT_FILE", audioFiles[rnd.nextInt(audioFiles.length)].getAbsolutePath());
${CURRENT_FILE}
where requiredSee How to use BeanShell: JMeter's favorite built-in component guide for more information on Beanshell scripting in Apache JMeter.
Upvotes: 1