I have a requirement where I need to run a JS file to get a token. The JS file has references to variables like "window", "setTimeout" functions which are available when the browser loads.
But I need to load this load this Jmeter, and extract the token. Problem is JSR233 says it has no reference to "window" or "setTimeout" functions (which otherwise was available in the browser).
And when I run it, I get the below error. Is there any way that we can get a handle to these functions in Jmeter.
021-06-24 13:11:08,246 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: ReferenceError: "setTimeout" is not defined in /Users/pprabhak/performance/apache-jmeter-5.4.1/bin/BehaviorAnalytics-2.2.0.min.js at line number 12 javax.script.ScriptException: ReferenceError: "setTimeout" is not defined in /Users/pprabhak/performance/apache-jmeter-5.4.1/bin/BehaviorAnalytics-2.2.0.min.js at line number 12 at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:477) ~[jdk.scripting.nashorn:?] at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:433) ~[jdk.scripting.nashorn:?] at jdk.nashorn.api.scripting.NashornScriptEngine$3.eval(NashornScriptEngine.java:521) ~[jdk.scripting.nashorn:?] 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.1] at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:72) [ApacheJMeter_java.jar:5.4.1] at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:638) [ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558) [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: jdk.nashorn.internal.runtime.ECMAException: ReferenceError: "setTimeout" is not defined at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.objects.Global.noSuchProperty(Global.java:1616) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.scripts.Script$Recompilation$21736$268435452$BehaviorAnalytics_2_2_0_min$cu10$restOf.VAAP$:split-2(/Users/pprabhak/performance/apache-jmeter-5.4.1/bin/BehaviorAnalytics-2.2.0.min.js:12) ~[?:?] at jdk.nashorn.internal.scripts.Script$Recompilation$17386$73052$BehaviorAnalytics_2_2_0_min.VAAP(/Users/pprabhak/performance/apache-jmeter-5.4.1/bin/BehaviorAnalytics-2.2.0.min.js:1) ~[?:?] at jdk.nashorn.internal.scripts.Script$Recompilation$17388$BehaviorAnalytics_2_2_0_min$cu1$restOf.:program(/Users/pprabhak/performance/apache-jmeter-5.4.1/bin/BehaviorAnalytics-2.2.0.min.js:1) ~[?:?] at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:655) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.runtime.Context.evaluateSource(Context.java:1438) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.runtime.Context.load(Context.java:962) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.objects.Global.load(Global.java:1720) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.scripts.Script$Recompilation$17383$^eval_/0x0000000800b68040.:program(:3) ~[?:?] at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:655) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513) ~[jdk.scripting.nashorn:?] at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527) ~[jdk.scripting.nashorn:?] at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:428) ~[jdk.scripting.nashorn:?] ... 9 more 2021-06-24 13:11:08,249 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
window
are exposed by browser – Rahul Jadhav