Besides script variables, in TestComplete, you can also use project, project suite and network suite variables that are created visually. These variables are used for exchanging data between test items and projects during the test run. For instance, you can use project suite variables to exchange data between test projects that make up the test suite; or you can use project variables to pass data from one test item to another. This cannot be done with global script variables, since they only exist during the test script run. When the execution of a test item is over, that is, when the automated test script is done executing, the script variables are deleted.
In earlier versions of TestComplete, you could create and use non-script variables that store integer, string, float, Boolean and date/time values or object references. TestComplete 7 introduces a new type of non-script variables called - Table variables. Using these variables you can easily create, change and use two-dimensional arrays in your automated tests.
An array is a programming term for a collection of elements that are accessed by their indexes. Programmers use arrays to store relative values like a list of numbers or strings. Arrays can be single-dimensional and multi-dimensional. A single-dimensional array is like a list of values that you can access using the appropriate index. An example of an array is a list of combo box items. A two-dimensional array is organized much like a table. To access the elements of an array, you need two indexes.
In earlier versions of TestComplete you could only create arrays from automated test scripts, not visually. To populate the array, you had to write script code that assigned the desired values to each array element. TestComplete 7 makes this a lot easier: now you can create Table variables that store two-dimensional arrays. The best thing about this is that you can create them visually and set the values of the array elements once using a special dialog, which you invoke from the Variables page of the project, project suite, network suite or keyword test editors. Here is a sample image of the dialog:
The arrays can include any number of rows. The cells (or array elements) can store values of any type: integer, string, date, float, boolean and others.
To make addressing array elements easier, you assign names to the table’s columns. You can then address the desired column by its index or name (see below). Using the names makes your automated tests clearer and easier to understand.
With Table variables you can create really flexible and powerful automated tests and are a convenient tool for creating and modifying data collections:
- You can easily organize data of different types for your automated tests. For instance, you can use them as data storages for data-driven testing. In earlier versions you had to use Excel or CVS files as data storage and write script code that obtained values from these files.
- You can exchange lists of different values between test projects or test items. In earlier versions, it was too hard and sometimes impossible to implement this functionality.
Note however, that you cannot use Table variables to store data between test runs. The reasons are that array elements may store object references and the objects are removed after the test session is over. So, the references become invalid. If the Table variables stored their values between test runs, they would contain invalid data and this would cause errors in further test runs.
You work with Table variables from keyword tests and automated test scripts the same way that you work with variables of other types. For instance, you can use these variables to pass values to parameters of keyword test operations:
To specify the desired element of the array, TestComplete provides a special page in the Operation Parameters wizard. On this page you can set the column and row that contains the desired value:
As you can see, the table rows are addressed by their indexes. Columns can be specified either by indexes or by names that you assigned to them in the variable editor.
To access the Table variables from automated test scripts, you use the Variables property of the Project, ProjectSuite, NetworkSuite or KeywordTest objects (the same property that you use to access variables of other types):
Here Product is the column name and the number in parenthesis that follows it is the row index.
Working with Table variables is easy and we believe that by using them you can create more flexible and powerful automated tests and create them even easier than before. Download TestComplete and try the new Table variables feature today.