user866364
user866364

Reputation:

JMeter - Add random files to upload

I've a lot of files that i would like to upload to test my service but i need to pick up random files and send it. Is possible get random files and delete the file when request is completed?

Thank's in advance.

Upvotes: 1

Views: 3095

Answers (1)

Dmitri T
Dmitri T

Reputation: 168052

JMeter doesn't provide any test element to create random files and delete them, so you'll have to write the relevant code.

For example:

  1. Add a Beanshell PreProcessor and Beanshell Post Processor as children of the requests which performs file upload
  2. Put the following code into Beanshell PreProcessor "Script" area

    import org.apache.commons.io.FileUtils;
    File myFile = new File("myFile.txt");
    FileUtils.writeStringToFile(myFile, "JMeter rocks!");
    

    The code above creates "myFile.txt" file in JMeter's current working directory and writes "JMeter rocks!" line to it

  3. In order to delete the file after request you can add the following code into the Beanshell PostProcessor

    import org.apache.commons.io.FileUtils;
    FileUtils.deleteQuietly(new File("myFile.txt")); 
    

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

Upvotes: 1

Related Questions