1
votes

I want to do a Assertion failure in JSR223 Sampler based on the values i detected in 2 Post processors above. I tried importing AssertionResult in JSR223 Sampler but it is unable to invoke the method.

Getting the following error in log:

javax.script.ScriptException: Sourced file: inline evaluation of: SampleResult.setIgnore(); import org.apache.jmeter.threads.JMeterContext.TestLog . . . '' : Cannot reach instance method: setFailure( boolean ) from static context: org.apache.jmeter.assertions.AssertionResult : at Line: 24 : in file: inline evaluation of:SampleResult.setIgnore(); import org.apache.jmeter.threads.JMeterContext.TestLog . . . '' : AssertionResult .setFailure ( true )

Is this a right way to call this method?


JSR223 Sampler

SampleResult.setIgnore();
import org.apache.jmeter.threads.JMeterContext.TestLogicalAction;
import org.apache.jmeter.assertions.AssertionResult;

//Final Response Assertion
String s1 = "N";
String s2 = "N";

if( ${__isVarDefined(s_check)} == true )
{
s1 = vars.get("s_check");
}
if( ${__isVarDefined(s_check_1)} == true )
{
s2 = vars.get("s_check_1");
}

if( (s1 == "false" && s2 == "false") || (s1 == "false" && s2 == "N") || (s1 == "N" && s2 == "false") )
{
AssertionResult.setFailure(true); //NOT WORKING
AssertionResult.setFailureMessage("accountID page is not loaded"); //NOT WORKING
ctx.setTestLogicalAction(TestLogicalAction.START_NEXT_ITERATION_OF_THREAD); //WORKING
}
1

1 Answers

0
votes
  1. You don't have AsserionResult shorthand in the JSR223 Sampler, either move your code to JSR223 Assertion and change first line to prev.setIgnore(true) or change these lines:

    AssertionResult.setFailure(true)
    AssertionResult.setFailureMessage("accountID page is not loaded")
    

    to these ones:

    SampleResult.setSuccessful(false)
    SampleResult.setResponseMessage("accountID page is not loaded")
    
  2. Inlining JMeter Functions or Variables in Groovy scripts is not recommended, you should also change this lines:

    String s1 = "N";
    if( ${__isVarDefined(s_check)} == true )
    {
    s1 = vars.get("s_check");
    }
    

    to

    s1 = vars.get('s_check') ?: 'N'
    

More information: