Manipulate a variable at runtime

With JavaScript, a variable from an external data file that was uploaded to Scriptless Web can be manipulated like regular data. Read the following example to learn how to manipulate a variable when executing JavaScript code during a test run.

If you need help with custom JavaScript code, contact your Perfecto Professional Services representative.

Prerequisites

This example assumes that you know how to:

Example steps

  1. Create an external data .csv file that looks like the one in the following image, where:

    • Line 1 is the name of the variable

    • Line 2 is the variable value

  2. Create a code asset with the required lines. In this example, the script manipulates the variable created in the previous step by capitalizing the text.

    Copy
    return (function(args){
        let elementString = args[0];
        let capitalCaseNumber = elementString.toUpperCase();
        return capitalCaseNumber;
    })(arguments);
  3. Run your test.

  4. Set a breakpoint where you want to add a new step.

  5. Click Add step > System > Run code.

  6. In the Add Flow Element dialog box, do the following:

    1. From the Code to run (JavaScript) list, select the code asset you created in Step 2.

    2. Under Arguments, click Add Arguments.

    3. In the Keys to send field, enter {{<variable-name>}}. This is the name of the variable you created in the external data file in Step 1.

    4. Select the Push result to context checkbox.

    5. In the Name of Variable field, enter a nameCapText.

    6. Click ADD.