LoadRunner – Runtime Settings – Preferences – JavaScript

The last sub-option in the ‘Preferences’ tab of Runtime Settings is ‘JavaScript’ which is very useful when you are using JavaScript in your LoadRunner script. This option creates a JavaScript runtime engine. The built-in JavaScript Engine enables you to insert snippets of JavaScript code into the C code. You can insert JavaScript code into a Web – HTTP/HTML Vuser script to manipulate text strings that are included in the request and response messages that are sent between the client and server. Manipulating strings is often used for correlation and parameterization purposes. Typical string manipulations include converting decimal to hexadecimal, encoding and decoding Base64, URL encoding and decoding, and accessing object values inside JSON-formatted data. Inserting JavaScript code into a Vuser script may also be useful when client-side logic is implemented in JavaScript. Inserting snippets of the original client-side JavaScript code into the Vuser script removes the requirement of having to rewrite the JavaScript logic into C code to be included in the Vuser script.

There are two functions available for JavaScript in a VuGen:
i. web_js_run: It runs the specified JavaScript code
ii. web_js_reset: It clears the JavaScript context

You use the web_js_run function to include JavaScript code in a Vuser script. Using the web_js_run function, you can either insert the required JavaScipt code into the Vuser script, or you can reference a file that contains the required JavaScript code.

LoadRunner - Runtime Settings - Preferences - JavaScript
Figure 01: LoadRunner – Runtime Settings – Preferences – JavaScript

1. Enable running JavaScript code: Mark this option, and enable Web JavaScript functions (web_js_run() and web_js_reset()) which are described above.

2. JavaScript Engine runtime size: It specifies the size of the allocated JavaScript Engine Runtime memory, in kilobytes. This value may need to be increased when running a large number of Vusers. The value range is 0 to 300000.

3. JavaScript Engine stack size per-thread: It specifies the size of each Vuser thread in the JavaScript Engine memory, in kilobytes. This value may need to be increased for large objects or deep stack calls. The value range is 0 to 10000.

Notes:

  1. JavaScript Engine enables you to insert JavaScript into Web – HTTP/HTML Vuser scripts only. It can not be used for all the protocols.
  2. While using web_js_run and web_js_reset functions in the script, make sure that VuGen’s JavaScript Engine is enabled.
  3. Javascript limits you to add up to 9,000 operands in one function. For example, if you are combining strings, “str1″+”str2″+”str3″+…”str9000”, you can only add up to 9,000 strings.
  4. If the Simulate a new user on each iteration > Clear cache on each iteration runtime setting is selected, web_js_reset is called automatically at the start of each iteration.
  5. If Simulate a new user on each iteration > Clear cache on each iteration is not set, avoid excessive memory consumption by inserting web_js_reset calls in your Vuser script at points where you no longer need the saved context.

Leave a Comment