abstracta / jmeter-java-dsl

Simple JMeter performance tests API
https://abstracta.github.io/jmeter-java-dsl/
Apache License 2.0
477 stars 59 forks source link

Issue with migrating JSR223-pre-processors with Java code (lambdas) to jsrPreProcessor with string scripts when running DSL script with Blazemeter #197

Closed cspriya closed 1 year ago

cspriya commented 1 year ago

Discussed in https://github.com/abstracta/jmeter-java-dsl/discussions/196

Originally posted by **cspriya** June 22, 2023 Hi, I am new the Java Jmeter DSL and I am facing issue when I am migrating below script which puts newly generated Authorization in ${Authorization} header placeholder of HTTP sampler to jsrPreProcessor with string scripts since LAMDA expression does not work with Blazemeter execution `.children( jsr223PreProcessor( s -> s.vars.put( "Authorization", getAuthorizationHeader())))` I am not sure how I can convert the above code snippet to jsrPreProcessor String script. I tried with the reference [provide-request-parameters-programmatically-per-request](https://abstracta.github.io/jmeter-java-dsl/guide/#provide-request-parameters-programmatically-per-request) did something like below. `[.children( jsr223PreProcessor("vars.put('Authorization', " + getClass().getName() + ".getAuthorizationHeader(vars))") )]` Getting below error in Blazemeter logs as Authorization value is not setting with above code in Blazemeter 2023-06-22 10:43:48,941 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: com for class: Script1 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:92) ~[?:1.8.0_362] 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:5.4.3] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:549) [ApacheJMeter_core.jar:5.4.3] at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) [ApacheJMeter_core.jar:5.4.3] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) [ApacheJMeter_core.jar:5.4.3] at java.lang.Thread.run(Thread.java:750) [?:1.8.0_362] Please help me with migrating code from java lamda to run the same test in Blazemeter tool also. Thanks Please help @rabelenda
rabelenda commented 1 year ago

I am closing this issue because there is also an associated Discussion :).