Script
This is a node that runs JavaScript scripts. It is going to help you solve the following tasks:
create complex tests to check the results of one or several nodes;
generate test data;
change other nodes' variables;
perform operations to bring the tested system to a specific state (set_up, tear_down);
debug and access all nodes' states.
Editing a Script
You can use the toolbar above the output window to manage the console behavior:
Running a Script
Click the RUN
button to execute the script. The execution continues to the last line of the code and finishes when all asynchronous tasks are done (e.g.setTimeout
). The execution is successful if:
there are no syntax errors in the code;
the exceptions raised had been handled;
the execution took no more than 30 seconds (otherwise the execution will be terminated).
Since the call to the script is wrapped in a function, you need to use the return;
command to avoid errors while terminating the script.
To get an error after script termination raise an exception withthrow new Error('Something went wrong');
Libraries
The script is executed in the Node.js virtual environment. Some Node.js modules and all standard JavaScript features supported by V8 are available.
The ECMAScript 6 standard is supported as well.
Available Node.js modules
fs - a module for interacting with the file system
Available third party libraries
lodash - a library that provides lots of utility functions
moment.js - a library for managing dates
CryptoJS - a collection of cryptographic algorithms
random-js - a mathematically correct random number generator library
faker.js - a library that lets you generate random data for different entities properties
chai.js - a library that provides a convenient API for making assertions
request - a library that provides a simplified HTTP client
Execution Context
Objects and functions of the script's global scope are listed below.
Accessing third party modules
Every module stated above is automatically added to the execution context and is available in the global scope.
lodash
moment.js
CryptoJS
random-js
faker.js
chai.js
request
console.*
There are different console output methods, such as log, info, warn, error, debug, exception.
Their signatures are equal to the signatures of their standard versions. In the console every method type is highlighted in different color. Each colored line contains the particular row and column where the output method is called. Events of the exception type are displayed along with the stack trace.
Navigating your project
There is an object used to access the project and the current Script node. It is called tm
and it is available in the global scope.
tm
currentNode: nodeAPI
- the current Script node APIproject: nodeAPI
- the project node APIenv: envAPI
- the API for accessing the environment variablescookies: cookie[]
- a list of cookies used in the project
nodeAPI
parent: nodeAPI
- returns a parent node API and null for the project nodename: string
- the given node nametype: string
- the given node typepath: string
- the path to the given node starting with the project rootchildren: nodeAPI[]
- a list of child nodes APIsfindChild(name: string): nodeAPI
- searches for the child node using its name and returns null if the node doesn't existnext: nodeAPI
- the API of the next node in the group. If the given node is the last one, null is returnedprev: nodeAPI
- the API of the previous node in the group. If the given node is the first one, null is returnednextNodes: nodeAPI[]
- a list of all next nodes in the group. If the given node is the last one, an empty list is returnedprevNodes: nodeAPI[]
- a list of all previous nodes in the group. If the given node is the first one, an empty list is returnedvars: object
- the object that stores all static variables of the given nodedynamicVars: object
- the object that stores all dynamic variables of the given nodesetDynamicVar(name: string, value: any): void
- sets the name dynamic variable with a certain value for the given node
requestNodeAPI
The interface of a RequestStep
node is more advanced.
request: object
- the object that stores the node's request configurationresponse: object
- the object that stores the results of the last request
envAPI
active: string
- the active environment titlevars: object
- the object that stores the current environment variables
Code examples
Recursive traversal of the node's children
Searching a node by its name
File Representation
Last updated