Much like every site on the internet, we use cookies to help analyze traffic and improve our website. As outlined in our privacy policy, any information is only used internally and is not shared with outside organizations.
Learn More

Variables

Variables Tool Window

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.
Process Variables
User-defined Variables created specifically for the current Process.

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, 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:

Input Argument With Explicit Text

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:

Input Argument With Variable

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 Process Variables

Creating Variables specifically for your 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 Process Variable instead.

Creating a Process Variable

To create a new Process Variable, you will first need to make sure your Process 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 the initial Value and a Description to better understand the purpose of your Variable. If you do not provide an initial value, you will need to assign a value at run-time (see below).

When naming your variable, the name must start with a letter (i.e. 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.
The suggested naming convention for variable names is to begin each word with an upper-case letter followed by lower-case letters. Examples: FirstName, SocialSecurityNumber, Url, InvoiceNumber, EvenLongNamesCanBeEasilyReadThisWay. This convention is referred to as "PascalCase" or "UpperCamelCase".

Modifying a Process Variable

To modify any Process 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 Value and Description.

Assigning a Value at Run-Time

A Process 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 to assign any value to your variable.

Deleting a Process 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.

Make sure your Variable is not in use before you delete it. Your Process will fail to playback properly if it attempts to access a Variable that does not exist.

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.

If you work on a team, consider storing your environment variable files on a shared network drive so everyone can use the same data and you have a single source to update if values change.

Open the AutoBloks Options Dialog

  1. Select File on the Ribbon Command Bar.
  2. Select Options from the Ribbon Backstage Menu. The AutoBloks Options dialog will now be displayed.
  3. Select the Data tab.

Options Dialog Run 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:

  1. System Variables
  2. Environment Variables (by the order each file is defined)
  3. Session Variables
  4. Process Variables

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.

The Variables tool window displays each group of variables in order of scope from highest to lowest (i.e. System Variables at the top, Process Variables at the bottom).