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

Run-JavaScript-in-Jmeter-or-Load-External-JavaScript-in-Jmeter

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

Run-JavaScript-in-Jmeter-Load-External-JavaScript

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

Run-JavaScript-in-Jmeter

  • After Executing the code will is the output

Load-External-JavaScript-in-Jmeter

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

Thanks,

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

One thought on “Run JavaScript in Jmeter or Load External JavaScript in Jmeter

  • February 16, 2020 at 4:24 am
    Permalink

    Great content! Super high-quality! Keep it up! :)

    Reply

Leave a Reply

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