JSR223 预处理器代码应该 运行 仅用于 HTTP 采样器

JSR223 Pre Processor code should run for only HTTP Sampler

我有一个 JSR223 预处理器 代码如下:

String method = sampler.getMethod(); 

JMeter 测试计划如下:

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

由于 JSR223 PreProcessor 将应用于层次结构中的所有采样器,因此除了 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 Sampler

运行

检查之前是否有 HTTP 采样器:

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

JMeter

中的类似代码
if (testElement instanceof HTTPSamplerBase) {

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

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

更多信息: