Class StringFromFile

java.lang.Object
org.apache.jmeter.functions.AbstractFunction
org.apache.jmeter.functions.StringFromFile
All Implemented Interfaces:
org.apache.jmeter.functions.Function, org.apache.jmeter.testelement.TestStateListener

@AutoService(org.apache.jmeter.functions.Function.class) public class StringFromFile extends org.apache.jmeter.functions.AbstractFunction implements org.apache.jmeter.testelement.TestStateListener

StringFromFile Function to read a String from a text file.

Parameters:
  • file name
  • variable name (optional - defaults to StringFromFile_)
  • sequence start
  • sequence end
Returns:
  • the next line from the file
  • or **ERR** if an error occurs
  • value is also saved in the variable for later re-use.

Ensure that different variable names are used for each call to the function

Notes:
  • JMeter instantiates a single copy of each function for every reference in the test plan
  • Function instances are shared between threads.
  • Each StringFromFile instance reads the file independently. The output variable can be used to save the value for later use in the same thread.
  • The file name is resolved at file (re-)open time; the file is initially opened on first execution (which could be any thread)
  • the output variable name is resolved every time the function is invoked
Because function instances are shared, it does not make sense to use the thread number as part of the file name.
Since:
1.9
  • Constructor Details

    • StringFromFile

      public StringFromFile()
  • Method Details

    • execute

      public String execute(org.apache.jmeter.samplers.SampleResult previousResult, org.apache.jmeter.samplers.Sampler currentSampler) throws org.apache.jmeter.functions.InvalidVariableException
      Specified by:
      execute in interface org.apache.jmeter.functions.Function
      Specified by:
      execute in class org.apache.jmeter.functions.AbstractFunction
      Throws:
      org.apache.jmeter.functions.InvalidVariableException
    • setParameters

      public void setParameters(Collection<org.apache.jmeter.engine.util.CompoundVariable> parameters) throws org.apache.jmeter.functions.InvalidVariableException
      Specified by:
      setParameters in interface org.apache.jmeter.functions.Function
      Specified by:
      setParameters in class org.apache.jmeter.functions.AbstractFunction
      Throws:
      org.apache.jmeter.functions.InvalidVariableException
    • getReferenceKey

      public String getReferenceKey()
      Specified by:
      getReferenceKey in interface org.apache.jmeter.functions.Function
      Specified by:
      getReferenceKey in class org.apache.jmeter.functions.AbstractFunction
    • getArgumentDesc

      public List<String> getArgumentDesc()
      Specified by:
      getArgumentDesc in interface org.apache.jmeter.functions.Function
    • testStarted

      public void testStarted()
      Specified by:
      testStarted in interface org.apache.jmeter.testelement.TestStateListener
    • testStarted

      public void testStarted(String host)
      Specified by:
      testStarted in interface org.apache.jmeter.testelement.TestStateListener
    • testEnded

      public void testEnded()
      Specified by:
      testEnded in interface org.apache.jmeter.testelement.TestStateListener
    • testEnded

      public void testEnded(String host)
      Specified by:
      testEnded in interface org.apache.jmeter.testelement.TestStateListener