【问题标题】:Assertion failure in JSR223 SamplerJSR223 采样器中的断言失败
【发布时间】:2020-08-05 03:22:00
【问题描述】:

我想根据我在上面的 2 个后处理器中检测到的值在 JSR223 采样器中执行断言失败。我尝试在 JSR223 Sampler 中导入 AssertionResult 但无法调用该方法。

在日志中得到以下错误:

javax.script.ScriptException:源文件:内联评估: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();导入 org.apache.jmeter.threads.JMeterContext.TestLog 。 . . '' : AssertionResult .setFailure (true)

这是调用此方法的正确方法吗?


JSR223 采样器

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
}

【问题讨论】:

    标签: jmeter assertion jsr223


    【解决方案1】:
    1. 您在 JSR223 采样器中没有 AsserionResult 速记,请将您的代码移动到 JSR223 Assertion 并将第一行更改为 prev.setIgnore(true) 或更改以下行:

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

      给这些人:

      SampleResult.setSuccessful(false)
      SampleResult.setResponseMessage("accountID page is not loaded")
      
    2. 内联JMeter Functions or Variables in Groovy scripts is not recommended,你也应该改变这行:

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

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

    更多信息:

    【讨论】:

    • 谢谢 Dmitri T。我会处理的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多