Variables

Overview
Variables are placeholders for other information that you can use in your Activity Calls instead of explicitly defining values.
There are four types of variables:
- System Variables
- Read-only Variables related to the current system (e.g. Date/Time, File System).
- Environment Variables
- Read-only Variables defined in one or more external files commonly used to store environmental data.
- Session Variables
- Read-only Variables related to the currently executing automation session.
- User-Defined Variables
- User-defined Variables created specifically for the current Scenario, Process, or User Activity.
Browsing Variables
AutoBloks provides many Variables for commonly-used information. When you launch AutoBloks, the Variables tool window can be used to browse the available Variables.
The Variables tool window lists the name of each Variable as well as the current value (if available) so that you have a better understanding of the data being represented. Select any Variable in the tool window and a description will also be displayed in the Variable Properties section at the bottom of the tool window.
Using Variables
Variables are primarily used as Input and Output Arguments for Activity Calls and Process Calls, but can also be used for Element Identification. AutoBloks uses a special Expression Syntax to allow Variables to be used in place of or in combination with standard text values.
For example, the following screen shows an input argument of an Activity Call where the Url argument is explicitly defined as http://wwww.patterson-consulting.net
:
Instead of hard-coding that value, a Process Variable called Url was created instead, and the value of that Variable was assigned to http://www.patterson-consulting.net
. The previously hard-coded entry can now be replaced with the Variable using the expression {Url}
as shown below:
Working with Variable expressions is easy with many ways to pick the right variable!
- From the Variables tool window, you can use the Copy command on any Variable to place the variable expression on the clipboard
- You can drag-and-drop any Variable from the Variables tool window to any text box control to insert the variable expression
- Start typing and an auto-complete list of potential Variable name matches will be presented for you to select from (where supported)
- Click the drop-down arrow to the right of supported controls to be presented with a menu of Variables from which to choose.
Refer to the Expressions topic for details on more complex Variable usage, including the ability to use multiple variables for a single field and how to directly use the characters {
and }
without them being treated as expressions.
User-Defined Scenario and Process Variables
Creating Variables specifically for a Scenario or Process can help you reduce data duplication and improve future maintenance. If you ever find yourself entering the same value more than once, consider replacing it with a Variable instead.
Creating a User-Defined Variable
To create a new user-defined variable, you will first need to make sure your Scenario, Process, or User Activity is open and is the selected document. You then click the New Variable button on the toolbar at the top of the Variables tool window.
Using the Variable Properties section at the bottom of the Variables tool window, give your Variable an appropriate Name. Optionally, you can also provide a Default Value and a Description to better understand the purpose of your Variable. If you do not provide a default value, you will need to assign a value at run-time or allow a value to be passed as a parameter (see below).
A-Z
or a-z
) or underscore (_
) character. After the first character, the name can continue to include letters, underscores, but also digits (i.e. 0-9
). The curly brace characters {
or }
you see throughout the application at the beginning and end of your Variable name are special characters used when working with expressions and are automatically displayed as part of the variable name in the Variables tool window. FirstName
, SocialSecurityNumber
, Url
, InvoiceNumber
, EvenLongNamesCanBeEasilyReadThisWay
. This convention is referred to as "PascalCase" or "UpperCamelCase". Modifying a User-Defined Variable
To modify any User-Defined Variable, select the Variable in the Variables tool window and the editable information will be displayed in the Variable Properties section at the bottom of the tool window. There you can rename the Variable or edit the Default Value and Description.
Assigning a Value at Run-Time
A User-Defined Variable is frequently used to store information during run-time. There is a special Activity named Set variable that can be called from your Process or User Activity to assign any value to your variable.
Deleting a User-Defined Variable
If you no longer need a previously defined Variable, you can delete it. Select the Variable in the Variables tool window then click the Delete Variable button on the toolbar at the top of the Variables tool window.
Promote Variable to Parameter
A Process call be called from a Scenario and a User Activity can be called from a Process or other User Activities. Often, you will need to pass data to these items and sometimes receive data back. One or more of the variables defined in the called item can be prompted to an Input or Output parameter to allow this data to pass.
- Expand the Parameter Details section at the bottom of the Variable Properties section.
- To allow values to be passed to the Process or User Activity, check the Allow values to be passed as Input Parameter to expose the variable as an Input Parameter.
- Optionally check Require value to be populated to indicate that the value is a required parameter.
- To allow values to be output back from the Process or User Activity, check the Expose final value as Output Parameter.
Environment Variables
Creating a User-Defined Process Variable for common or widely used data (like user names or system URL's) can be repetitive and result in a lot of maintenance if those values need to be updated. Environment Variables are repositories of one or more user-defined variables that can be loaded by AutoBloks to be accessible by any Process. If the value ever needs to be modified, it can be modified in one location without having to update all the Processes that use it.
File Format
Environment Variables are defined in an XML-formatted file (refer to W3Schools Tutorial if you need assistance with XML). The following is the minimum necessary to define a single environment variable in a file:
<Environment>
<Variable>
<Name>NameOfVariableHere</Name>
<Value>ValueOfVariableHere</Value>
</Variable>
</Environment>
Look Familiar?
If this format looks familiar, we intentionally used the same file format used by Micro Focus Unified Functional Testing (UFT) to allow data to be shared with the popular tool.While the above shows the minimum definition necessary for a variable, additional values can optionally be provided for more detail and organization:
- Description
- A short description or summary of the purpose of the variable. This information will be displayed in the Variable Properties section of the tool window and can help you and others understand the purpose of the variable.
- Category
- A category can be used to group related variables under a common category. You can specify a single category (e.g.
Credentials
) or you can create a hierarchy of categories by separating each category with a backslash character (e.g.Credentials\Billing
).
The following is a more complete example of environment variables defined in a file:
<Environment>
<Variable>
<Name>SystemUrl</Name>
<Value>http://localhost:8080/something</Value>
<Category>System</Category>
<Description>The URL of the application under test.</Desktop>
</Variable>
<Variable>
<Name>BillingAdminUserName</Name>
<Value>admin001</Value>
<Category>Credentials\Billing</Category>
<Description>The user name of the billing account with admin rights.</Desktop>
</Variable>
<Variable>
<Name>BillingCustomerUserName</Name>
<Value>user001</Value>
<Category>Credentials\Billing</Category>
<Description>The user name of a test account simulating a customer of the billing system.</Desktop>
</Variable>
</Environment>
Managing Environment Files
Once you have defined environment files within files, you will need to instruct AutoBloks to load those files.
Open the AutoBloks Options Dialog
- Select File on the Ribbon Command Bar.
- Select Options from the Ribbon Backstage Menu. The AutoBloks Options dialog will now be displayed.
- Select the Data tab.
The following commands are available on the AutoBloks Options dialog:
- Add
- Adds a new environment repository by prompting you to select one or more files containing environment variables.
- Remove
- Removes the select repository file.
- Reload
- Reloads the repository in the contents of the file have changed since the file was added or the application was launched.
- Up/Down
- Moves the selected repository up or down in scope. The higher in the list, the higher the scope. If the same variable is defined in multiple files, the variable that is lowest in scope (i.e. lowest in the list) will be used.
Understanding Variable Scope
Variables can be defined through multiple sources. Since variables are referred to by name, what happens if more than one variable is defined with the same name? When this happens, variable defined in the lowest scope will be used. The following outline variable scope from highest to lowest:
- System Variables
- Environment Variables (by the order each file is defined)
- Session Variables
- User-Defined Variables for the current Scenario, Process, or User Activity
For example, there is a built-in System Variable called CurrentDate
. If you also defined an Environment Variable with the name CurrentDate
, the value used by AutoBloks during playback will correspond to the value defined by the Environment Variable since it is lower in scope than a System Variable.
- Create a corresponding user-defined variable in the Process or User Activity being called.
- Promote the variable as an Input Parameter.
- When calling the item, populate the Input Parameter with the desired User-Defined Variable.