Creating a Javascript Library

What is a NeoLoad Javascript Library?

A Javascript Library is simply a global javascript block that can defined shared functions and variables for use in various places in NeoLoad user path scripts.

Some examples of places where you can use Javascript library shared functions are:

  • Custom Javascript action blocks
  • Javascript data variables
  • fields where ${…} expansion notation can be used, such as:
    • HTTP Request URL Path
    • HTTP Headers
    • Request body (HTTP and other types)
    • Other custom action property values
    • Server hostname

You can have more than one Javascript library, for instance one for value encoding/decoding specific to your application under test and another for general cryptographic functions.

Getting Started

The first thing you should do is check to see if the type of Javascript library you think you want to create already exist in our Integrations. If so, you should try that out and if changes need to be made, work with the Moderators of that project to factor in changes or new work you’d like to add.

If it doesn’t already exist, congratulations, you are the first one to get started in on the work! In that case, it would be beneficial to read up as much as possible on how to author a Javascript library first.

Technical Prerequisites

To write custom Javascript libraries, you need:

  • NeoLoad Desktop Designer (GUI) installed
  • A NeoLoad project loaded up
  • Experience with writing Javascript/ECMAscript

How to Access Your Project’s Javascript Libraries

In NeoLoad, click the top menu ‘Edit’ and ‘JS Libraries’ menu item. This displays the list of libraries in your project. By default there usually is a ‘NeoLoad Default Library’ which you may or may not chose to keep, but it’s good for reference.

To create a new library, click the yellow script-looking icon at the bottom of this list. The name you give it does not have to include a .js at the end, as NeoLoad will simply create a [your name].js file in the scripts subdirectory. If you chose an existing script (maybe from another project), it will COPY that .js file into your current project.

How the NeoLoad Engine Uses Your Javascript Libraries

You do not need to ‘import’ your libraries anywhere in NeoLoad as all contexts where functions may be called already have loaded all libraries globally.

If you have external JAVA Jar libraries that you want to call from Javascript, you can do so by copying the external .jar file(s) in the project ‘extlib’ subfolder and referencing classes and objects using the full classpath name. See this documentation for more detail on Javascript <– –> Java marshaling.

NOTE: NeoLoad is not a NodeJS engine so if you’re simply copying and pasting NodeJS examples, it will almost certainly not work. NeoLoad implements JSR-305 so if you feel the need to run some other interpreter, you will have to do so by writing those scripts (stored under custom-resources) outside NeoLoad, then running an external process (such as Node, installed where you intend to run the User Path) and executing those scripts externally.

Testing Your Javascript Library

Typically, you would exercise your shared functions by using it in the context of a user path, action, etc. Good practice is to also write “unit test functions” along with your library where there is a single ‘super test’ function that calls all of these unit test functions. Then you can have a ‘JS Unit Tests’ user path that is only for local/design-time and sanity checks.

To test your functions in the context of actual User Paths you use as part of load tests, you would want to verify this using the Check User Path feature in NeoLoad then carefully scrutinize the logs and outcomes of your custom functions as used by various parts of your workflow.

Once You’re Ready to Publish

Once you’re done, firstly, congratulations! That is a milestone you should be proud of. The next step is to get it published to this site.

If you found the same or similar project and are contributing to an existing Git repo, refer to that projects Contribution Guidelines and work with the project Moderators to get the right access. You can always fork an existing Neotys-Connect repo, make your changes in your copy, then issue a pull request back to the original repo as well.

If this is a new project and you have pushed your changes to a Git repo you own under your own Github account, all you would need to do is Transfer Ownership to the ‘Neotys-Connect’ organization.

Once received, the Connect Core Team will review it and either provide you feedback or accept it and make you a Moderator of your repo once hosted in Neotys-Connect.

Also feel free to reach out to our Connect Core Team afterwards.

Non-DIY Method (send us your project)

If the above seems too daunting for you, that’s okay too. It’s better for your contribution to see the light of day than to be stuck somewhere it doesn’t do anyone else good. Feel free to send your contributions to our Connect Core Team .

Examples

For projects created after version 7.1, unless otherwise deleted, you should see a ‘NeoLoad Default Library’ which lives under your project as ‘scripts/neoload-1.0.js’.

Out of the box examples are provided in every [new] NeoLoad project and include:

  • __urlDecode
  • __escapeHTML
  • __unescapeHTML
  • __randomString
  • __getVirtualUserID
  • __getUserPathName
  • __UUID
  • __digest
  • __toHexString
  • __toUTF8Array
  • (and others…)
🔝