IBM Support

Use an ECMAScript function library in RIT

Question & Answer


Question

How do you create and re-use a library of ECMAScript functions in IBM Rational Integration Tester (RIT)?

Cause

Software Testers and Software Engineers may create ECMAScript functions to assist with testing. It is good practice to keep such functions in a single location.

Answer

A text file may contain some general purpose ECMAScript functions. Here is an example file contents.

function greeting() {
    return "Hello World";
}


For our example this is saved as "Library.js" within the root folder of a RIT project. A single file may contain multiple functions and other ECMAScript definitions.
Now within our Function Action (or Assert Action) in RIT we can load and execute the greeting() function with these commands:

eval( textFileContent( tags["PROJECT/ROOT"] + "/Library.js" ) );
greeting();

Our Function Action will now return "Hello World".

Because the scope of the definitions ends with the Function Action or Assert Action this process must be repeated with each relevant RIT action.


Line Numbers

More recent builds of RIT present a line number when they a syntax error is found in ECMAScript code.

Many text editors can show line numbers and also support syntax highlighting for JavaScript, for example Notepad++ for Windows or GEdit for Linux, Mac OS X or Windows.


Performance Considerations

Where a test contains a loop or many actions making use of the same library it may be more efficient to load the contents of the file into a tag (e.g. %%library%%) so the code would become:

eval( tags["library"] );
greeting();

Where a library contains ECMAScript definitions which are time consuming to construct it may be preferable to break the library into multiple pieces so that only those pieces which are necessary at a given time are processed by the eval() command.


An alternative strategy

Custom Functions can be written in Java, packaged and loaded as detailed in the product manual. Once loaded into RIT these become available within ECMAScript and other locations (without any need for a load instruction).

[{"Product":{"code":"SSBLQQ","label":"IBM Rational Test Workbench"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Rational Integration Tester","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF022","label":"OS X"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"8.0;8.5","Edition":"All Editions","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
11 July 2019

UID

swg21654377