Search code examples
filevariablesjmeterjsr223

How to put the content of a file in a global variable in JMeter?


I want to save the content of a file in a variable one time and use it in JSR223 pre-processor script. How can I do this?


Solution

    1. Add User Defined Variables to your Test Plan and define the variable name of your choice, i.e. myFile. As the value use __FileToString() function and provide the path of the file which you want to load:

      enter image description here

    2. Once done you can refer the file content from any of the JSR223 Test Elements using vars shorthand for JMeterVariables class instance as:

      String myFile = vars.get('myFile')
      

      enter image description here