JavaScript Extensions
JavaScript Extensions allow administrators to write custom client-side code in JavaScript that can execute any logic as a part of the suite creation, update, removal, and so on. These scripts can give additional functionality to the user input parameters defined in the tests or for a blueprint resource, for example you can use Using JavaScript Extensibility to configure dependencies between test parameters.
You can use the JavaScript Extensions to control the different sets of user input parameters in a Blueprint or Test (modules) by adding JavaScript code in the Manage dashboard, in the Custom JavaScript Modules extensions page. Modifying the code for the JavaScript extension modules triggers an event when the user performs a particular action in the Create Suite Template/Edit Suite Template/Run Suite page. The code can either validate the user inputs, or make changes to them.
For example:
When you modify the code in the following module | Changes will be made to the inputs when the user performs the following tasks |
Blueprint input – all parameters |
|
Blueprint input - published parameters |
|
Test input - all parameters |
|
Test input - published parameters |
|
Using JavaScript Extensibility to configure dependencies between test parameters
As an administrator can configure the possible parameters displayed to the user in a test, and define dependencies between the variable fields. For example, in the code samples presented in the Custom JavaScript Modules extensions page, in the Test input - all parameters module, the possible values for the log_level parameter field are only available after selecting the values in the test_type parameter field. Since the script defines a set of possible log level values for each test type, the code updates the log_level field's possible values according to the selected value for the test_type.
To configure possible values for a test parameter:
-
Create a test with a test_type string input.
-
Create a suite template with a single job and add the test to the job.
The test_type parameter displays in the suite.
-
In your script, for this parameter, add the following code, which assigns possible values to the variables:
data.getParameterByName(t, 'test_type').possibleValues = ["-select-","type 1","type 2"];
To configure dependencies between test parameters:
-
In the Custom JavaScript Modules extensions page, from the Select module dropdown list, select Test input – all parameters.
-
In the Test input – all parameters module, enter a code based on the following example. Make sure to include the required parameters:
if (test_type.value == 'type 1')
log_level.possibleValues = ["-select-", "1A", "1B", "1C", "1D"];
else if (test_type.value == 'type 2')
log_level.possibleValues = ["-select-", "2A", "2B"];
You can find a complete sample of the code in the code sample panes at the bottom of the JavaScript Extension module pages.
Related Topics
- Creating Tests
- Adding Automation Suites