Search code examples
filejmetergenerate

Jmeter testing: How to generate many unique files?


I have question:How to generate many unique files ? In my testing: upload many files to gofast,but File content is not repeating. Thank you !

enter image description here


Solution

  • I don't think it's about JMeter, personally I would go for pre-generating test files using operating system built-in mechanisms like shell scripting and referencing them using Directory Listing Config because I want the test to be repeatable

    However if you're looking for a JMeter-specific solution you can use JSR223 PreProcessor and Groovy language for creating the file with some content

    Example simple code:

    def file = new File('foo.txt') 
    file << 'bar'
    vars.put('myFile', file.getAbsolutePath())
    

    The code:

    • creates an empty file foo.txt in "bin" folder of your JMeter installation
    • writes "bar" message to it
    • stores the full path to the file into myFile JMeter Variable

    So you should be able to refer to it as ${myFile} instead of hard-coding the file path.

    P.S. There is a better way of taking screenshots