1

In JMeter I am passing multiple JSON inputs as body, Variable name is defined as JSON_FILE and coming from CSV Data Config

${__FileToString(${__eval(${JSON_FILE})}.json,,)}

CSV Data

designO1015643320
.
.
designO1077673985
designO1088516727

Running load test from Jmeter UI works fine, but running as mvn project is giving error about FileNotFoundException even though .csv file and .json files are in same folder as .jmx file

Error from .jmx.log:

WARN - jmeter.functions.FileToString: Could not read file: designO1015643320.json File 'designO1015643320.json' does not exist java.io.FileNotFoundException: File 'designO1015643320.json' does not exist

Response in .jtl:

httpSample t="4" lt="0" ts="1508530091457" s="false" lb="CreateDesign_PUT" rc="Non HTTP response code: org.apache.jorphan.util.JMeterStopThreadException" rm="Non HTTP response message: End of sequence" tn="Design_APIs 1-1" dt="text" by="1822" ng="1" na="1"/>

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
Chetu
  • 21
  • 1
  • 5
  • 1
    since you don't specify path to the file, it's looking for it in current directory. When you running locally and using Maven, current directory is most likely different, hence it can't find that file. You have to pass path somehow, or make it universal for both cases (e.g. absolute, or available on PATH) – timbre timbre Oct 20 '17 at 22:05

2 Answers2

0

JMeter GUI default relative path is the bin folder

Relative paths are resolved relative to the current working directory (which defaults to the bin/ directory).

Maven search in different default path for files src/test/jmeter directory

See guide:

in the src/test/jmeter directory. When running the project, the JMeter Maven plugin searches for tests to run in this directory.

And you can find this path dynamically

Community
  • 1
  • 1
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0

I heard Groovy is a new black so I would recommend replacing your __FileToString() function with __groovy() function, the Groovy equivalent of dynamically getting the file path relative to Maven's plugin current working directory would be something like:

${__groovy(new File(org.apache.jmeter.services.FileServer.getFileServer().getBaseDir() + System.getProperty('file.separator') + vars.get('JSON_FILE') + '.json').text,)}

See JavaDoc on FileServer class for more details.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133