Share this page

# JavaScript Web HTTP scripts

You can record Web HTTP/HTML Vuser scripts in JavaScript. You can also regenerate a C language script to convert it to JavaScript.

In this topic:

## About JavaScript Web HTTP scripts

To record and convert to JavaScript, VuGen uses Chrome's V8 JavaScript engine. The engine supports the ECMAScript 2022 language specification.

JavaScript Vuser scripts support asynchronous behavior and functionality. For details, see Create an asynchronous Vuser script.

JavaScript Vuser scripts support Virtual User Tables (VTS). For more information see Parameterize scripts.

To run a script faster, you can disable JavaScript debugging at Runtime Settings > Preference > JavaScript.

## Record your Vuser script in JavaScript

When you create a Web HTTP/HTML Vuser script, you are notified that you can choose to generate the script in JavaScript. To disable the message, see General tab

To record your script in JavaScript:

1. Click Record > Recording Options. Select Script in the General menu on the left.

2. Select JavaScript in the Scripting Language dropdown list.

3. Click OK.

After recording the script, the default C files are replaced by JS files.

Note: Once you have recorded your script the Language option in the Recording Options dialog box is disabled and cannot be changed. You can change the language of a script after it is recorded only by regenerating it.

## Convert a C script to JavaScript

You convert a C script to JavaScript by regenerating a recorded script. You cannot convert a script that you coded.

Caution: VuGen's code regeneration overwrites all manual changes that you made to a recorded script; it only regenerates the recorded functions.

To regenerate C scripts into JavaScript:

1. Click or Record > Regenerate Script. A warning appears that any changes to the code are overwritten.
2. Click Options. The Regenerate Options dialog box appears.
3. In the Script section, select the target language to convert the script to.
4. Click OK in the Regenerate Options dialog box. Click OK to approve regenerating the code.

## JavaScript function libraries

The native JavaScript library includes string functions, database connectivity functions and XML functions among others. Native library functions are available from four global objects:

- web: Web/HTTP Protocol API.
- lr: Native API.
- vtc: VTC multiple connections API.
- lrvtc: VTC single connections API.

### Custom Libraries

In addition to the standard functions, you can create JavaScript function libraries, or use JavaScript Language libraries such as underscore, lodash, and moment.

Before you can invoke custom functions, add your custom library into the Extra files section. Your custom library must have a 'js' extension.

To activate auto-completion on your library, right click on the js file name and select Add to Parsing List.

Note: If you regenerate your script in another language, any additional files, such as a user-defined .js file, are removed from the parsing list.

### External Libraries

In addition, the lr.require and lr.loadLibrary functions enable you to import JavaScript files at runtime. Third-party libraries are supported for libraries that are not MS-Windows or document-object based. Therefore, asynchronous functions and libraries, such as promise libraries, are not supported.

lr.loadLibrary is used to “include” a single file into the script. The code is evaluated and its definitions are added to the global scope of the runtime context. For example: `lr. loadLibrary (‘external.js’);`. lr.loadLibrary can be used for browser based libraries.

lr.require loads a CommonJS file or NPM module into a string, then wraps it with a function and evaluates it. Additional required files are loaded recursively along the “require” link.

Example: var lodash = lr.require("..\\node_modules\\lodash");

var sum = lodash.sum([1,2,3,4]);

## See also

- Using the VuGen JavaScript engine
- Debug scripts
- The JavaScript section of the Function Reference

https://admhelp.microfocus.com VuGen,Professional Performance Engineering,Performance Engineering for Developers 8942
Tips to improve your search results... OpenText™ Virtual User Generator Help Center OpenText™ VuGen Help 26.1-26.3 All View Local Help Center View Online Help Center Version: