jmeter JSR223预处理器代码应仅为HTTP采样器运行

wvyml7n5  于 2022-11-09  发布在  其他
关注(0)|答案(2)|浏览(206)

I have aJSR223 Preprocessorcode given below:

String method = sampler.getMethod();

JMeter Test Plan given below:

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

AsJSR223 PreProcessorwill apply to all the Samplers in the hierarchy, it gives below error for all the Samplers apart fromHTTP Sampler.
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
I want myJSR223code to run only forHTTP Sampler

sr4lhrrt

sr4lhrrt1#

检查HTTP采样器是否早于:

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

JMeter中的类似代码

if (testElement instanceof HTTPSamplerBase) {
mmvthczy

mmvthczy2#

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

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

相关问题