Ankur
Ankur

Reputation: 1086

How to upload Random audio file in JMeter

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

Answers (2)

vins
vins

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

Dmitri T
Dmitri T

Reputation: 168157

You can use Beanshell PreProcessor to dynamically get random file path from the specified folder.

To do so:

  1. Add Beanshell PreProcessor as a child of the request which performs upload
  2. 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());
    
  3. Refer random file location as ${CURRENT_FILE} where required

See How to use BeanShell: JMeter's favorite built-in component guide for more information on Beanshell scripting in Apache JMeter.

Upvotes: 1

Related Questions