Code assets

Scriptless Web lets you run JavaScript code while the test is running in the browser's context. This article explains how to create and use a code snippet. For more information, see the Inject code tutorial.

To create a code snippet:

  1. In the Assets view, in the left pane, click Code Assets.

  2. On the right, click Add Code.

  3. In the Create a code asset dialog box, provide the following:

    • The asset's name

    • (Optional) A description of up to 100 characters

    • Your JavaScript code

      The dialog box includes sample code to help you get started.

  4. Click CREATE.

To use a code asset in your test:

  1. On the canvas, in Advanced mode, add a new step and select System > Run code.

  2. In the Add Flow Element dialog box, from the Code to run (JavaScript) list, select the code asset you created.

  3. If you want to validate the result, do the following:

    1. Select the Check result check box.

    2. In the Command Result field, enter a string value.

      Important: If the code asset returns a value of a different type, the result check will fail because it expects a value of type string. In this case, consider modifying the code asset to convert the returned value to string.

      For example, the following code returns a value of type boolean.

      Copy
      let variable1 = true;
      function variable2() {
      return variable1;
      }
      return variable2();

      Adding the following line to the code asset will convert the boolean value to a string so that the result check will succeed.

      Copy
      return variable2().toString();
  4. If you want to use the result as a context variable later:

    1.  Select the Push value to context check box. 

    2. Select a value from theTransformationlist. For more information, see context variables.

  5. Click ADD.

To edit a code snippet:

  1. Hover over a code and click Edit .

  2. In the Update a code asset dialog box, provide the following:

    • The asset's name

    • (Optional) A description of up to 100 characters

    • Your JavaScript code

      The dialog box includes sample code to help you get started.

  3. Click UPDATE.

To delete a code snippet:

  • Hover over a code snippet and click Delete .