CloudShell Version: 2023.3 GA
Guide Version: 1.0
View / Download All Help Versions

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
  • Creates a new suite (Create Suite Template) page (in the Job Scheduling dashboard) with blueprint inputs published in the blueprint
  • Edits a suite in the Edit Suite Template page with blueprint inputs published in blueprint

  • Opens the Run Suite page - All Inputs tab with blueprint inputs published in the blueprint

  • Opens the Run Custom page (by clicking the Customize button in the Run Suite page) with blueprint inputs published in the blueprint

  • Reserves a blueprint

Blueprint input - published parameters
  • Opens the Run Suite page with blueprint inputs published in the blueprint and in the suite.
Test input - all parameters
  • Creates a new suite (Create Suite Template) page
  • Edits a suite in the Edit Suite Template page
  • Opens the Run Suite page – All Inputs tab
  • Opens the Run Custom page (by clicking the Customize button in the Run Suite page)
Test input - published parameters
  • Opens the Run Suite page
  • Opens the Run Suite page – Customize tab

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 inthe 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:

  1. Create a test with a test_type string input.
  2. Create a suite template with a single job and add the test to the job.
  3. The test_type parameter displays in the suite.

  4. 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

  1. In the Custom JavaScript Modules extensions page, from the Select module dropdown list, select Test input – all parameters.
  2. 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"];
  3. 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