0
votes

I am new to JMeter and am struggling to implement a Beanshell PreProcessor. I have this example code taken from a post on this site -

File querycsv = new File("xlocalTestData.csv");

if (!querycsv.exists()){
    SampleResult.setSuccessful(false);
    SampleResult.setRespnseMessage("Failed to find CSV file");
    SampleResult.setData("Unable to locate CSV file under path: " + querycsv.getPath(),"UTF-8");
    IsSuccess = false;
    SampleResult.setStopTestNow(true);

Digging around on the internet I found this import statement -

import org.apache.jmeter.samplers.SampleResult;

But I am getting this error when passing a corrupt file name to test for a fail if the csv file is missing -

2014/03/03 13:11:11 INFO  - jmeter.engine.StandardJMeterEngine: Running the test! 
2014/03/03 13:11:11 INFO  - jmeter.samplers.SampleEvent: List of sample_variables: [] 
2014/03/03 13:11:11 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*) 
2014/03/03 13:11:11 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : Report Service Group 1 
2014/03/03 13:11:11 INFO  - jmeter.engine.StandardJMeterEngine: Starting 5 threads for group Report Service Group 1. 
2014/03/03 13:11:11 INFO  - jmeter.engine.StandardJMeterEngine: Thread will start next loop on error 
2014/03/03 13:11:11 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 5 ramp-up 5 perThread 1000.0 delayedStart=true 
2014/03/03 13:11:11 INFO  - jmeter.threads.ThreadGroup: Started thread group number 1 
2014/03/03 13:11:11 INFO  - jmeter.engine.StandardJMeterEngine: All thread groups have been started 
2014/03/03 13:11:11 INFO  - jmeter.threads.JMeterThread: Thread started: Report Service Group 1 1-1 
2014/03/03 13:11:11 INFO  - jmeter.services.FileServer: Stored: /home/brad/JMeter/ReportService/localTestData.csv Alias: /home/brad/JMeter/ReportService/localTestData.csv@1567545803 
2014/03/03 13:11:11 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:11 WARN  - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:11 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:11 WARN  - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:11 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:11 WARN  - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:11 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:11 WARN  - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:12 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:12 WARN  - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:12 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:12 WARN  - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval    Sourced file: inline evaluation of: ``import org.apache.jmeter.samplers.SampleResult;  File querycsv = new File("xloca . . . '' : Cannot reach instance method: setSuccessful( boolean ) from static context: org.apache.jmeter.samplers.SampleResult 
2014/03/03 13:11:12 INFO  - jmeter.threads.JMeterThread: Thread started: Report Service Group 1 1-2 

Not being a Java programmer I am guessing that I don't have my include path set up? Is anyone able to point me toward a resolution?

I am running this on a Centos 6 desktop running Apache JMeter (2.11 r1554548)

Any help appreciated

Thanks

Brad

1
you have a typo. .setRespnseMessage( should be setResponseMessage(David Torrey

1 Answers

1
votes

You need to use Beanshell Sampler, not Beanshell Pre Processor.

SampleResult is a pre-defined variable which is available for Beanshell Sampler only, neither pre nor post processors don't have access to it.

See How to use BeanShell guide for more details.