Reputation:
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
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:
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
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