我想根据我在上述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
}
答案 0 :(得分:0)
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")
内联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'
更多信息: