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 .
ard28
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:
 
 
 
Declare Variables
  1. Go to the 
    Home
     tab and click 
    Automation
    , and click the 
    Variables 
    tab.
  2. Select a 
    Layer
    .
  3. Click 
    Add Variable
     and specify default values.
  4. Click 
    Save
     and 
    Close
    .
  5. 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 
Home
 tab and click 
Automation
, and click the 
Objects & Actions
 tab. For more information, see Define Your Automation Configuration.
  1. Edit the predefined test objects and test actions, or create custom objects and actions.
  2. Enter 
    code snippets
     for all actions in your flows. 
  3. Click 
    Insert 
    at the bottom of the code snippet editor to insert variables into code snippets.
  4. Click 
    Preview Snippet
     (green checkmark icon) to preview the code with its variables resolved.
  5. Click 
    Save
     and 
    Close
    .
Define Variable Values
After you define variables, you assign them either a literal value or a Data Painter function.
  1. Right-click a block and clock 
    Edit item
    .
  2. Click the 
    Test Data 
    tab.
  3. Add variables to this block by doing one or more of the following steps:
    • Click 
      Add Variable
      ,
       New variable
       
    • Click 
      Add Variable
      ,
       Existing variable
       
    • Click 
      Add Default Variable
       
  4. Define the value by clicking one of the following buttons:
    • Edit native value
      Enter a literal string or numeric value.
    • Edit resolvable value in Data Painter
      Construct 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.
  5. Click 
    Save
    .
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:
  1. Go to the 
    Home
     tab and click 
    Automation
    . Click the 
    Layers
     tab.
  2. Enable the 
    Advanced
     option 
    Automatically map actions from a Block Attribute
    .
  3. 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.
  4. Click 
    Save & Close
    .
For each mapping, configure the following automation:
  1. Go to the 
    Home
     tab and click 
    Automation
    . Click the 
    Objects & Actions
     tab.
  2. Add 
    Object Types
     and 
    Action 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~');
     
  3. Click 
    Save & Close
    .
Provide the variable values in the attribute fields of blocks:
  1. Return to the flow. Edit block properties or add a block.
  2. Add variable values to attribute fields, in our example, to the 
    Block Description
    .
    Example value:
     
    Into "First Name" type "John"
     
  3. Click 
    Save & Close
    .
  4. Go to the 
    Automation
     tab.
    You see that the automated actions have been added.
  5. 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 Description
 field automatically.
  1. Go to the 
    Home
     tab and click 
    Automation
    , and click the 
    Objects & Actions
     tab.
  2. Add the following first action:
     Enter "~text~" into "~textField~"
     
     
     
  3. 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.
  4. Add the following second action:
     Click "~element~"
     
  5. Pair the second action with the following code snippet:
     Click(Text:"~element~")
     
  6. Add a process block named "Login" to the flow.
  7. Add the following pattern with the variable values to the 
    Block Description
     field:
    Enter "administrator" into "UserId" and then enter "pass" into "Password" and then click "LoginButton"
     
  8. Save your changes.
  9. Go to the 
    Automation
     tab 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
      ,
       Automation 
      tab
    •  
      Path Explorer
      ,
       Stored Paths
      ,
       Export
      ,
       Automation Scripts
       window
       
  • You can also preview code snippets in the block properties, under the 
    Automation
     tab.
    • Review unresolved snippets in the table.
    • Review partially resolved snippets by clicking "
      Preview Snippet
      "
       
      (the green tick button on the lower right of the window).
      The snippet preview is 
      partially 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:
 
  1. Create a three-column spreadsheet with the headers "Name", "Description", and "Default Value", and fill it accordingly.
  2. Go to the 
    Home
     tab and click 
    Automation
    Variables
    .
  3. Select a layer.
  4. Click 
    Import
     and 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.