使用JMeter __FileToString函数,获取java.io.FileNotFoundException

时间:2016-11-17 09:41:36

标签: jmeter

我正在使用JMeter __FileToString函数来读取请求正文中的JSON文件,如下所示。

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

但是我在运行测试时遇到了错误。有人能指出我在Windows中如何使用JMeter fileToString函数的正确示例。

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)

2 个答案:

答案 0 :(得分:3)

如果CSV_Challenges_Dataset是文件名,那么您可以按如下方式直接访问它:

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

如果CSV_Challenges_Dataset是实际文件名,请不要将其包含在eval方法中。

如果CSV_Challenges_Dataset是变量,那么您要么未在JMeter测试计划中定义(设置值)。来自日志很明显,您没有定义值CSV_Challenges_Dataset

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

如果已定义,CSV_Challenges_Dataset应该已被实际值替换。

添加Debug sampler和View Results Tree,以了解运行时CSV_Challenges_Dataset的值。

答案 1 :(得分:0)

最有可能的原因是您的${CSV_Challenges_Dataset}变量未设置。在此函数之前的某处添加Debug Sampler并仔细检查变量值是否已设置并解析为文件名。您可以使用View Results Tree侦听器查看JMeter变量名称和值。有关深入了解JMeter测试脚本失败的详细信息,请参阅How to Debug your Apache JMeter Script文章。

以防万一,您不需要将${CSV_Challenges_Dataset}变量包装到__eval()函数中,__ FileToString()函数足够智能来解析变量。