开发者问题收集

JSR223 预处理器代码应仅适用于 HTTP 采样器

2022-05-18
304

我有一份 JSR223 预处理器 代码,如下所示:

String method = sampler.getMethod(); 

JMeter 测试计划如下:

      - JSR223 Pre Processor
      - HTTP Sampler
      - JSR223 Sampler / Any other sampler apart from HTTP

由于 JSR223 预处理器 将应用于层次结构中的所有采样器,因此除了 HTTP 采样器 之外,它会为所有采样器提供以下错误。

2022-05-18 17:32:43,668 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.apache.jmeter.protocol.java.sampler.JSR223Sampler.getMethod() is applicable for argument types: () values: [] at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-jsr223-3.0.7.jar:3.0.7] at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.7.jar:3.0.7] at javax.script.CompiledScript.eval(CompiledScript.java:89) ~[java.scripting:?] at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[ApacheJMeter_core.jar:5.4.3] at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:45) [ApacheJMeter_components.jar:5.4.3] at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:965) [ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:549) [ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) [ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) [ApacheJMeter_core.jar:?] at java.lang.Thread.run(Thread.java:834) [?:?] Caused by: groovy.lang.MissingMethodException: No signature of method: org.apache.jmeter.protocol.java.sampler.JSR223Sampler.getMethod() is applicable for argument types: () values: [] at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70) ~[groovy-3.0.7.jar:3.0.7] at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46) ~[groovy-3.0.7.jar:3.0.7] at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-3.0.7.jar:3.0.7] at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase$getMethod.call(Unknown Source) ~[?:?] at Script1366.run(Script1366.groovy:1) ~[?:?] at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) ~[groovy-jsr223-3.0.7.jar:3.0.7] ... 9 more

我希望我的 JSR223 代码仅为 HTTP 采样器 运行

2个回答

检查之前是否使用 HTTP Sampler:

if (sampler instanceof org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) { 
   String method = sampler.getMethod(); 
}

JMeter

if (testElement instanceof HTTPSamplerBase) {
Ori Marko
2022-05-18

如何将 JSR223 预处理器移至 HTTP 请求采样器的子级?

在此处输入图像描述

在这种情况下,其范围将仅限于父采样器,并且不会在每个采样器之前执行。

更多信息:

Dmitri T
2022-05-18