How to Use Variables
While you define you automation configuration, you want to use variables in your code snippets. For more information about how to create the configuration, see .
While you define you automation configuration, you want to use variables in your code snippets. For more information about how to create the configuration, see Define Your Automation Configuration.
You can assign various values to variables.
- Static literal value
- Predefined variable — for example results; block, flow, and path attributes; indexes
- Data Painter function — for example first names, last names, city names, times, dates
You can perform the following operations:
- Go to theHometab and clickAutomation, and click theVariablestab.
- Select aLayer.
- ClickAdd Variableand specify default values.
- Close and reopen the flow.The new variables are available in the flow.
Note:If you remove a variable from the Automation Configuration, it is not removed from the flow.
Insert Variables into Code Snippets
Go to the
Hometab and click
Automation, and click the
Objects & Actionstab. For more information, see Define Your Automation Configuration.
- Edit the predefined test objects and test actions, or create custom objects and actions.
- Entercode snippetsfor all actions in your flows.
- ClickPreview Snippet(green checkmark icon) to preview the code with its variables resolved.
Define Variable Values
After you define variables, you assign them either a literal value or a Data Painter function.
- Right-click a block and clockEdit item.
- Click theTest Datatab.
- Add variables to this block by doing one or more of the following steps:
- ClickAdd Variable,New variable
- ClickAdd Variable,Existing variable
- ClickAdd Default Variable
- Define the value by clicking one of the following buttons:
- Edit native valueEnter a literal string or numeric value.
- Edit resolvable value in Data PainterConstruct data expressions by using functions that extract names from seed lists, insert characters or strings, replace characters or strings, round off or pad numbers and strings. For more information about generating test data, see Managing Test Data.
Map Automation Parameters from Block Attributes
You can map automation parameters from general block attributes, such as text in block or output descriptions. This mapping lets you extract variable values from human-readable descriptions in process or decision blocks, and automatically insert the detected values into automation scripts.
First, enable automatic block attribute mapping for the flow:
- Go to theHometab and clickAutomation. Click theLayerstab.
- Enable theAdvancedoptionAutomatically map actions from a Block Attribute.
- Select the block attributes from which you want to map variable values for automation, for example,Block Description.
- (for Process blocks) You can select Block Name, Block Description, Notes, and Data Notes.
- (for Decision blocks) You can select Data Notes and Output Description.
- ClickSave & Close.
For each mapping, configure the following automation:
- Go to theHometab and clickAutomation. Click theObjects & Actionstab.
- AddObject TypesandAction Types: Create actions that contain variable references, and associate them with code snippets that use the same variables.Example action:Into "~textField~" type "~Text~"Example code snippet:element(by.model('~textField~')).sendKeys('~Text~');
- ClickSave & Close.
Provide the variable values in the attribute fields of blocks:
- Return to the flow. Edit block properties or add a block.
- Add variable values to attribute fields, in our example, to theBlock Description.Example value:Into "First Name" type "John"
- ClickSave & Close.
- Go to theAutomationtab.You see that the automated actions have been added.
- Export the automation scripts.The code snippets now contain the variable values as defined in the attribute field.Example exported script:element(by.model('First Name')).sendKeys('John');
Multi-Line Attribute Mapping Example
In this example, we create automation scripts for a login dialog. We use the eggPlant SenseTalk scripting language. The example assumes that you have enabled the option to map actions for the
Block Descriptionfield automatically.
- Go to theHometab and clickAutomation, and click theObjects & Actionstab.
- Add the following first action:Enter "~text~" into "~textField~"
- Pair the first action with the following code snippet:Click(Text:"~textField~")TypeText("~text~")This code places the cursor into the required field and types the required text.
- Add the following second action:Click "~element~"
- Pair the second action with the following code snippet:Click(Text:"~element~")
- Add a process block named "Login" to the flow.
- Add the following pattern with the variable values to theBlock Descriptionfield:Enter "administrator" into "UserId" and then enter "pass" into "Password" and then click "LoginButton"
- Save your changes.
- Go to theAutomationtab of the block.You see that several lines of automated actions have been added to the script:
Click(Text:"UserId") TypeText("administrator") Click(Text:"Password") TypeText("pass") Click(Text:"LoginButton")
Preview Code Snippets with Resolved Variables
When you look at code snippets in the configuration, you see the unresolved versions of these code snippets. Keywords, such as variables, are substituted with context-specific values.
- Code snippets in a flow are fully resolved only on the path level. You see fully resolved code in the following windows:
- Path Explorer,Stored Paths,Automationtab
- Path Explorer,Stored Paths,Export,Automation Scriptswindow
- You can also preview code snippets in the block properties, under theAutomationtab.
- Review unresolved snippets in the table.
- Review partially resolved snippets by clicking "Preview Snippet"The snippet preview ispartially resolved, because a block cannot know what path it is in, and it may be in none or multiple paths. Any keywords that depend on attributes of a path are not resolved.
Bulk-Import and Export Variables
Instead of entering variables manually, you can import variables from a spreadsheet.
Follow these steps:
- Create a three-column spreadsheet with the headers "Name", "Description", and "Default Value", and fill it accordingly.
- Go to theHometab and clickAutomation,Variables.
- Select a layer.
- ClickImportand browse to the spreadsheet.One sheet of custom variables is imported.
From the same dialog, you can also export a copy of your variables, review and edit the spreadsheet, and reimport them.