You can watch our tutorial or you can go through our documentation about using variables :
Our approach: to produce software that allows people unfamiliar with development to perform automated software tests, we have thought a lot about the idea of variables and how to implement them in Agilitest.
We decided to implement them so that they do not impact the progress of the actions performed by the tester. This is why there is no calculation action, update action, nor transformation of variables action in Agilitest. All of these operations are managed in a separate tab dedicated to variables management.
This behavior makes it possible to reserve the edited part of the script for the actions on the components of the tested applications and for the checks that are made, and facilitates the understanding of the tests.
To simplify operations and avoid errors, we defined two variable origins:
-the orange color variables that come from the UI and elements of the tested application, and which are non-editable.
-the purple color variables that are declared by the user or created from orange non-editable variables, they can be edited and modified
These two kind of variables can be used to declare new purple variables.
The set of variables of a test is thus an assembly of trees of dependencies of variables, Agilitest and ATS will automatically update the variables dependent on other variables when they are modified.
Thus, the user must only worry about recovering values on the elements of the pages or screens tested and create dependent variables, and he knows that, anyway, the values of the set of dependent variables that he has declared will always be up-to-date with the current context of the test performed.
This mechanism allows a lot of flexibility and ease of processing for people who are not used to computer development.
How to create a variable?
There are several ways to create variables in Agilitest:
Environment variables are declared in the executions of your project, in the "Execution Parameters" tab.
Just select an execution, then you can add a new parameter and change its value.
NB: These variables are necessarily declared as strings of characters and can not use functions of modifications which are accessible for the other variables.
To use them in your scripts, use the function $env(parameter_name), for example in the case above, $env (browser) will display "chrome"
Editable script variable
These variables are created in the tab "Current's script variables" by clicking on the menu and selecting "Create a variable".
You will create a purple, editable color variable. You can then give it a name and a value.
As soon as your variable has a value, it will appear to the right of its name. This allows at any time to check the values of the variables of the current script.
If the variable is not declared correctly and Agilitest can not assign a value to it, it displays an error message besides the name of the variable.
To set the value of the variable, you can use the "Insert special value" menu to the right of the input field, which gives you access to all categories of variables that can be used in Agilitest.
These functions are accessible to define all the editable variables you will need, they can be concatenated to generate a more complex value.
Here are the main functions to access it:
- $env(parameter) : Returns the value of an execution parameter defined in the current execution.
- $var(variable) : Returns the value of a variable
- $param(index_param) : In a subscript, returns the value of a variable passed as a parameter by giving its index.
- Random String: Returns a random string indicating the desired number of characters and its case. the function is used like this:
- $rndstring(10) : generates a string of 10 random characters
- $rndstring(15, low) : generates a string of 15 characters in lower case
- $rndstring(8,upp) : generates an uppercase string of 8 characters
- Unique Id : Returns an identifier in the format Universal Unique Identifier, it is used like this:
- $uuid : generates a UUID, example: 110e8400-e29b-11d4-a716-446655440000
- Now : Returns a string indicating the current time of the computer that replays the test (or the continuous integration server), it is used like this:
- $now : server time, for example: 17:38:11
- Today : Returns a string indicating the current day of the station that replays the test (or the continuous integration server), it is used like this:
- $today : server day, for exemple : 08/30/2019
- Project identifier : Returns a string that identifies the project containing the file ats, it is used like this:
- $pgav : com.functional.Test(0.0.1)
Non-editable script variables
These variables are generated from elements from the tested applications, using the "Property" action.
This action takes as input a UI element that will have to be captured, as well as the name of the attribute of this element that interests us.
These variables are orange and can not be changed.
Advanced use of variables
Agilitest allows you to transform a variable in 5 different ways to facilitate the calculations.
- Regular expressions
Strings of caracters
By default, all variables are strings.
The type of a variable can be modified at creation by clicking on the corresponding button.
The transformation of a character string makes a page appear according to the type that will allow to manage it. If you click on the "Cancel" button, your variable becomes a string again.
We will take two variables that will serve as an example.
date : 8/9/2019
time : 11:34:33
You can concatenate variables in string format with each other and with text.
For example, if you create a variable $day, and you give it the value $var (date)_$var (time), its literal value will be 8/9/2019_11: 34: 33
Regular expressions transformation
Regular expressions are used to split strings to generate variables that correspond to subgroups of characters
The regular expressions management menu asks you for a model that must match to your original value.
This template has parentheses that define the subgroups and are used to determine what the value of the variable will be. Selecting group 1 will give the variable the value that corresponds to the model defined in the first parenthesis.
It is possible to perform date calculations to obtain a later or later date, in a day, a month etc.
From the entered value, selectors allow you to add or subtract days, months, years
The original format supported can be m/d/yy or yyyy-mm-dd
The date obtained can then be used in regex variables to retrieve the day, month or year.
It works the same as date transformation, in this case selectors allow you to add or remove hours, minutes or seconds at a given time.
The format of the input variable is hh:mm:ss
Variables transformed into numeric are used to handle integers or decimals in the format nn.nnnnnn
The input format can be a decimal number respecting this format, but also a decimal number whose separator will be a comma.
It is possible to use standard operators to do calculations:
- + : addition
- - : substraction
- * : multiplication
- / : division
The most common mathematical functions are implemented : sin, cos, tan, power, ln, etc.
For very specific cases where you would have special operations to perform, you can call java code by passing some values in parameter and then recovering a variable on which you can put a control.