toolmania1
toolmania1

Reputation: 259

In JMeter, "Save Responses to a File", how can I increment the file name while attaching a custom suffix to the end of the file names

In JMeter, when using "Save Responses to a File" to store http responses, how can I increment the file name while attaching a custom suffix to the end of the file names? Here was my scenario

  1. Recorded http traffic of a file conversion and download from a web site using the Recording Controller and HTTP(S) Test Script Recorder.
  2. I then moved this recorded traffic from the Recording Controller up to my main Thread Group. This allowed me to rerun what I had recorded.
  3. Then, I add a "Save Responses to a file" to the HTTP Request sampler for the "download" action that I had recorded from the web site.

However, I had trouble with the filename incrementing at the end of the file like this:

testFile.txt1
testFile.txt2
testFile.txt3

I wanted this:

testFile1.txt
testFile2.txt
testFile3.txt

Also, if I did not uncheck "Don't add suffix", then "octet-stream" was my file type, which is not what I wanted:

testFile1.octet-stream
testFile2.octet-stream
testFile3.octet-stream

So, how can I properly increment the file name with the correct file extension?

Upvotes: 2

Views: 5906

Answers (2)

Dmitri T
Dmitri T

Reputation: 168082

I'd suggest using __counter() function which can be either virtual-user-specific or global as follows:

testFile${__counter(FALSE,)}.txt - for GLOBAL counter testFile${__counter(TRUE,)}.txt - for SEPARATE counter per Virtual User

Upvotes: 4

toolmania1
toolmania1

Reputation: 259

I solved this by doing the following:

  1. Right clicked on the HTTP Request I wanted to add the counter and chose Add -> Config Element -> Counter
  2. Set "1" for "Start" and 1 for "Increment".
  3. Named the Counter with the "Reference Name" of "counter"
  4. In the "Save Responses to a file" mentioned above for the "download" traffic, I put "filename${counter}.xxx" for "Filename prefix:" where xxx is the file extension
  5. Still in the "Save Responses to a file", I also checked the boxes for both "Don't add number to prefix" and "Don't add suffix"
    • I forgot to mention that, for my "Thread Group", I had set "Number of Threads(users)" to "5" and "Loop Count" to 3. This would give me 15 users.

So, keeping that in mind, my files were named all correctly from:

testFile1.txt testFile2.txt . . . testFile15.txt

Hope this helps someone as I struggled with this for a little bit :-).

Upvotes: 2

Related Questions