Uploading same document by renaming with Jmeter

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.

  1. Create a Thread Group within a Test Plan. (You can name Thread Group as you wish)Screen Shot 2016-04-07 at 10.41.14
  2. 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.Screen Shot 2016-04-07 at 10.54.36
  3. 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.Screen Shot 2016-04-07 at 11.25.36   Screen Shot 2016-04-07 at 11.25.56
  4. Add the HTTP Request in the file data mention the loop_counter1 infront of the name of the document as shown below.Screen Shot 2016-04-07 at 12.11.48.pngMake 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.Screen Shot 2016-04-07 at 12.16.22.png
  5. Now Create the Script as shown below.Screen Shot 2016-04-07 at 12.31.19import java.text.*;
    import java.io.*;
    import java.util.*;
    //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);
  6. Now you will be able to upload same document with different with the amount you need.
  7. 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.Screen Shot 2016-04-07 at 13.14.29.png

One thought on “Uploading same document by renaming with Jmeter

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s