Run JavaScript in Jmeter or Load External JavaScript in Jmeter: In this tutorial will see how to run JavaScript in Jmeter or loading or running the JavaScript loading from external sources and you can use evaluated values and make use of it in your script.

Why do we need to use JavaScript in Jmeter?

In some scenarios like payment steps or some form submits in the application will use some front end encryption to encrypt the data sending from the browser. while creating a performance script we should send the correlated and parameter data in the same way the browser is sending. In such cases, we need to encrypt the post data use JMeter before sending it to server

How will we run JavaScript or external JavaScript in Jmeter?

To run JavaScript in Jmeter we have JSR223 Sampler where we can execute code of groovy, Java, JavaScript, Beanshell, etc.

  • JSR223 is available as Individual Sampler, Post Processor and Pre Processor for a Sampler

How to run sample JavaScript Code in Jmeter?

  • Add JSR223 Sampler to your ThreadGroup
  • Then write below code to JSR223 Sampler


  • Add Debug Sampler to see the executed results
  • After executing the script below will be the output


How to Load the external Javascript file in Jmeter?

Jmeter will support the Rhino Framework JavaScript execution. In rhino to load JavaScript file, we need to use load function to get the file or code

  • Below code will help you to load the external crypto.js for crypto encryption
  • After Executing the Code below will be the output


  • After Executing the code will is the output


Note: Document and Window objects will not work in Jmeter. Because we are not running our scripts in the browser.


Also Read: How to Run JMeter Samplers Defined Percentage

Also Read: Beanshell Assertion in Jmeter


Run JavaScript in Jmeter or Load External JavaScript in Jmeter

Leave a Reply

Your email address will not be published. Required fields are marked *