I have an encrypt.js script that is used to encrypt and decrypt the password entered by user. It is embedded in the application webpage.

I try to load the same script in jmeter using this code

load ('/apache-jmeter-5.6.3/scripts/encrypt.js');

upon running it, I got this error.

2024-02-27 09:55:47,729 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.load() is applicable for argument types: (String) values: [/apache-jmeter-5.6.3/scripts/encrypt.js]

In the language, I used groovy since there is no javascript in the dropdown list. How can I successfully import the javascript in jmeter?

jmeter jsr223 sampler

Trying to load and encryption js provided by the dev to successfully login into the application

1

There are 1 best solutions below

6
Ivan G On BEST ANSWER

If you're trying to use Global.load() function from Mozilla Rhino to load an external JavaScript file - you won't be able to do this using Groovy language. You will need to switch to javascript

For example if your "encrypt.js" file has the following function:

function myFunction(name) {
  return 'Hello, ' + name + '!'
}

you can load it and call it in JMeter as follows:

enter image description here

However be aware that using JavaScript is:

  1. Not recommended in general because Nashorn engine has been removed from JDK15 and you will have troubles with running your test on newer Java versions
  2. Is kind of a performance anti-pattern, since JMeter 3.1 you should be using Groovy language for scripting especially for cryptographic operations so I would rather suggest implementing your encryption logic in Groovy rather than trying to call JavaScript from Java. See Apache Groovy: What Is Groovy Used For? and Encryption and decryption with Groovy for more details.