Most of the time when we do performance testing we would require heavy data uploaded in the the system. When creating the data we would face issues where we might not be able to upload documents with duplicate names. How do we cater to this need.
The solution is quite simple. Rename the document every time you try to upload the document in that way the same document can be uploaded with different names.
- Create a Thread Group within a Test Plan. (You can name Thread Group as you wish)
- Add a Loop Controller within the Thread Plan, and mention total amount of documents you would like to upload in the system with in the Loop Count as shown below.
- Add two Counters one would have your the minimum value as the Start and the maximum value as Maximum. The other would have have the maximum value plus one as Maximum and minimum value as the Start. Mention the preferred Number Format and Increment. Reference Names for Counter1 and Counter2 should be given, as these names will be used for renaming.
- Add the HTTP Request in the file data mention the loop_counter1 infront of the name of the document as shown below.Make sure that you have the initial or the minimum number mentioned in the name of the document in the Directory. Here the initial number we use 123000 as the Number Format is 123000.
- Now Create the Script as shown below.import java.text.*;
//Take the fileLocation from the user defined variable
fileLocation = vars.get(“fileLocation”);
//Take the counter 1 value to indexNum
indexNum = vars.get(“loop_counter”);
//Take the counter 1 value to indexNum1
indexNum1 = vars.get(“loop_counter1”);
//The string portrays the current location of the document (with current name)
mainFile = indexNum + “Download.ppt”;
//The string portrays the location of the document which is renamed.
fileName = indexNum1 + “Download.ppt”;
//Get current document location
File file = new File( fileLocation + mainFile);
//Create location for renamed location
File file2 = new File( fileLocation + fileName);
//Rename document with the new location
boolean success = file.renameTo(file2);
- Now you will be able to upload same document with different with the amount you need.
- Finally if you would like to rename the thread to the initial name you can run a BeanShell Sampler in the tear down Thread Group do the same scripting and rename the document.