SCENARIO:
I have a JMeter script (e.g, jmeterScript.jmx) that needs to be triggered via Jenkins Job (auto-scheduled).
This script has a JSR223 PreProcessor, through which it needs to access a CSV file (e.g., testData.csv) located in a remote GitHub repository.
Both, the script and the CSV file are stored in the remote GitHub repository whose folder structure is as shown in the diagram below: enter image description here
I'm trying to exit out of the folder-4 (4 steps back) to the base folder (i.e., Base-folder) and then get into the folder-b to access testData.csv.
I'm trying to achieve this by writing below syntax in the script:
"File file = new File(${__P(data,"../../../../folder-a/folder-b/testData.csv") });"
ISSUE:
However, the script is unable to locate the file and is throwing the exception as defined in the code.
"ERROR: file not found"
NOTE: I have a exact folder structure in my local git repository and if I use similar path to define on a Random CSV Data Set Config, it works.
Only, seem to not work on a PreProcessor scripts.
I'm a bit rusty with my coding skills and what I've written in the script to access the CSV file is as below:
import java.text.*;
import java.io.*;
import java.util.*;
try {
File file = new File(${__P(data,"../../../../folder-a/folder-b/testData.csv") });
if (!file.exists()) {
throw new Exception ("ERROR: file not found");
}
BufferedReader bufRdr = new BufferedReader(new FileReader(file));
String line = null;
while(((line = bufRdr.readLine()) != null) && (count < limit))
{
stl.add(line);
count++;
}
Any help is greatly appreciated.
Regards!
Change this line:
to this one:
The reasons are in:
You shouldn't inline JMeter Functions or Variables into Groovy scripts
If you don't use FileServer.getBaseDir() as the prefix JMeter will start looking for the CSV file starting from its "bin" folder
Not sure what you're trying to achieve but reading the file in Groovy is as simple as:
if you want its contents as the array of lines:
More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?