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
-
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
-
-
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.
Copyreturn (function(args){
let elementString = args[0];
let capitalCaseNumber = elementString.toUpperCase();
return capitalCaseNumber;
})(arguments); -
Run your test.
-
Set a breakpoint where you want to add a new step.
-
Click Add step > System > Run code.
-
In the Add Flow Element dialog box, do the following:
-
From the Code to run (JavaScript) list, select the code asset you created in Step 2.
-
Under Arguments, click Add Arguments.
-
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.
-
Select the Push result to context checkbox.
-
In the Name of Variable field, enter a nameCapText.
-
Click ADD.
-