Prasad Revanaki
Prasad Revanaki

Reputation: 783

Using JMeter __FileToString function, getting java.io.FileNotFoundException

I am using JMeter __FileToString function to read JSON file in the request body as below.

${__FileToString(C:\\Users\\prasad\\Office\\SSP\\16.48\\sprint3\\${__eval(${CSV_Challenges_Dataset})}.txt,,)}

but I am getting below error when I run test. Can someone point me to right example on how to use JMeter fileToString function in windows.

2016/11/17 15:01:22 INFO  - jmeter.engine.StandardJMeterEngine: Running the test! 
2016/11/17 15:01:22 INFO  - jmeter.samplers.SampleEvent: List of sample_variables: [] 
2016/11/17 15:01:22 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*) 
2016/11/17 15:01:22 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : VerifyDecryptor 1L records 
2016/11/17 15:01:22 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group VerifyDecryptor 1L records. 
2016/11/17 15:01:22 INFO  - jmeter.engine.StandardJMeterEngine: Thread will continue on error 
2016/11/17 15:01:22 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 1 ramp-up 1 perThread 1000.0 delayedStart=false 
2016/11/17 15:01:22 INFO  - jmeter.threads.ThreadGroup: Started thread group number 1 
2016/11/17 15:01:22 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 2 : Thread Group 
2016/11/17 15:01:22 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group Thread Group. 
2016/11/17 15:01:22 INFO  - jmeter.engine.StandardJMeterEngine: Thread will continue on error 
2016/11/17 15:01:22 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 2 threads 1 ramp-up 1 perThread 1000.0 delayedStart=false 
2016/11/17 15:01:22 INFO  - jmeter.threads.ThreadGroup: Started thread group number 2 
2016/11/17 15:01:22 INFO  - jmeter.engine.StandardJMeterEngine: All thread groups have been started 
2016/11/17 15:01:22 INFO  - jmeter.threads.JMeterThread: Thread started: Thread Group 2-1 
2016/11/17 15:01:22 INFO  - jmeter.threads.JMeterThread: Thread is done: Thread Group 2-1 
2016/11/17 15:01:22 INFO  - jmeter.threads.JMeterThread: Thread finished: Thread Group 2-1 
2016/11/17 15:01:22 INFO  - jmeter.threads.JMeterThread: Thread started: VerifyDecryptor 1L records 1-1 
2016/11/17 15:01:22 WARN  - jmeter.functions.FileToString: Could not read file: C:\Users\prasad\Office\SSP\16.48\sprint3\${CSV_Challenges_Dataset}.txt File 'C:\Users\prasad\Office\SSP\16.48\sprint3\${CSV_Challenges_Dataset}.txt' does not exist java.io.FileNotFoundException: File 'C:\Users\prasad\Office\SSP\16.48\sprint3\${CSV_Challenges_Dataset}.txt' does not exist
at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:299)
at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:1711)
at org.apache.commons.io.FileUtils.readFileToString(FileUtils.java:1734)
at org.apache.jmeter.functions.FileToString.execute(FileToString.java:102)
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:142)
at org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:117)
at org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:101)
at org.apache.jmeter.testelement.AbstractTestElement.getPropertyAsString(AbstractTestElement.java:271)
at org.apache.jmeter.config.Argument.getValue(Argument.java:146)
at org.apache.jmeter.protocol.http.util.HTTPArgument.getEncodedValue(HTTPArgument.java:236)
at org.apache.jmeter.protocol.http.util.HTTPArgument.getEncodedValue(HTTPArgument.java:217)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sendPostData(HTTPHC4Impl.java:1294)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.handleMethod(HTTPHC4Impl.java:557)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:375)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1146)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1135)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:465)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:410)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:241)
at java.lang.Thread.run(Unknown Source)

Upvotes: 6

Views: 10120

Answers (2)

Naveen Kumar R B
Naveen Kumar R B

Reputation: 6398

If CSV_Challenges_Dataset is a filename, In that case, you can directly access it as follows:

${__FileToString(C:\\Users\\prasad\\Office\\SSP\\16.48\\sprint3\\CSV_Challenges_Dataset.txt,,)}

Don't include it in eval method if CSV_Challenges_Dataset is the actual file name.

If CSV_Challenges_Dataset is a variable, then you either you have NOT defined (Set the value) it in JMeter Test Plan. From logs It is clear that you do not define the value CSV_Challenges_Dataset.

 Could not read file: C:\Users\prasad\Office\SSP\16.48\sprint3\${CSV_Challenges_Dataset}.txt File

If defined, CSV_Challenges_Dataset should have been replaced by the actual value.

Add Debug sampler and View Results Tree, to know the value of CSV_Challenges_Dataset during run-time.

Upvotes: 4

Dmitri T
Dmitri T

Reputation: 168082

Most probably this is due to your ${CSV_Challenges_Dataset} variable is not set. Add Debug Sampler somewhere before this function and double check that the variable value is set and it resolves to file name. You can view JMeter Variables names and values using View Results Tree listener. See How to Debug your Apache JMeter Script article for details on getting to the bottom of your JMeter test script failures.


Just in case, you don't need to wrap your ${CSV_Challenges_Dataset} variable into __eval() function, __FileToString() function is smart enough to resolve the variable.

Upvotes: 1

Related Questions