▶️ You can find a tutorial on how to use variables on our Youtube channel.
Variabilising a script makes maintenance easier, provides easier access to the data consumed and makes the test more dynamic. All these variable operations are managed in a separate tab dedicated to variable management, which is located at the bottom left of the main screen and is called the “Script’s variables” tab.
There are two types of variables :
- Purple variables 🟪 : They are declared by the user and can be modified (called independent variable, declared variable, assignment variable).
- Orange variables 🟧 : They come from the interface to be tested and the elements of the application under test, and are not modifiable (also called dependent variable, dynamic variable, recovery variable).
The set of variables in a test is therefore an assembly of variable dependency trees. Agilitest and ATS will automatically update variables that are dependent on other variables when they are modified.
This mechanism offers a great deal of flexibility and ease of processing for people who are not used to IT development.
How to create a variable?
There are several ways to create variables in Agilitest:
Modifiable script variable (purple variable)
Modifiable script variables (purple) are also known as independent variables, declared variables and assignment variables.
These variables are created in the "Script’s variables" tab.
Click on the menu and select "Create variable".
This will create a purple variable that you can modify. You can then give it a name and a value.
Once the variable has been created, all you have to do is value it (add a value), without having to press the “Enter” key on the keyboard or perform any other additional actions.
As soon as your variable has a value, it appears to the right of its name. This allows you to check the values of the variables in the current script at any time.
If the variable is not declared correctly and Agilitest cannot assign it a value, it displays an error message in addition to the variable name.
To define the value of the variable, you can enter a hard-coded variable of your choice.
You can also use the "Insert a special value" menu to the right of the input field,
This gives you access to all the categories of variables that can be used in Agilitest.
Non modifiable script variable (orange variable)
Non-modifiable script variables (orange) are also known as dependent variables, dynamic variables and recovery variables.
There are two ways to create a non modifiable variable:
- Property action
These variables are generated from elements of the tested applications, using the "Property" action in the actions menu at the top of the Agilitest editor.
This action takes as input an element of the user interface which is to be captured, as well as the name of the attribute of this element which is of interest to us.
To do that, click on “Property” in the actions menu
The property action will target an interface element
Click on the “Load” button from the Property action
It will load all the properties associated with this element.
Click on the property of interest to load it during the execution
These properties correspond to the element attributes found in the "Captured element parents" window when the element is captured.
ATS properties also appear in the list of properties, as do formatting elements (CSS).
When a property is selected, it is placed in a variable which takes the value of the selected property.
If you select the "text" property with the value "Hello world - Wikipedia" in the list of captured properties.
When the property action is executed, the value of the selected property will appear in the property variable.
2. Return value
Non-modifiable variables can also be retrieved from a script return value to be stored as an independent variable
Variabilising special values
These functions can be used to define all the modifiable variables you need, and can be concatenated to generate a more complex value.
Here are the main functions for accessing it:
- Environment variable: Returns the value of an execution parameter defined in the current execution. Example: $env(parameter)
- Script variable: Returns the value of a variable. Example: $var(variable)
- Script parameter: In a subscript, returns the value of a variable passed as a parameter by giving its index. Example: $param(index_param)
You can pull down the menu to access the "calculated values".
- Now: Returns a character string indicating the current time of the computer replaying the test (or of the continuous integration server). Example: $now: 17:38:11
- Today: Returns a character string indicating the current day of the computer replaying the test (or of the continuous integration server). Example: $today: 30/08/2023
- Unique identifier: Returns an identifier in Universal Unique Identifier (UUID) format. Example: $uuid: 110e8400-e29b-11d4-a716-446655440000
- Random characters: Returns a random character string indicating the desired number of characters and its case. Example :
$rndstring(10): Generates a character string of 10 random characters
$rndstring(15, low): Generates a string of 15 lower-case characters
$rndstring(8,upp): Generates a string of 8 uppercase characters
Environment variables are declared in the execution parameters of your project.
To access the execution parameters, click on "Executions management" in the project explorer.
On the main screen, select an execution, then add a new parameter and modify its value.
These variables must be declared as character strings and cannot use the modification functions that are available for other variables.
To use them in your scripts, use the $env(parameter_name) function.
Advanced use of variables
Agilitest lets you transform a variable in 5 different ways to make calculations easier.
- Character strings
- Regular expressions
By default, all variables are character strings.
A variable can be transformed on creation by clicking on the corresponding button.
When a character string is transformed, a page is displayed according to the type used to manage it.
If you click on “Regular Expr.” button
This will display entries corresponding to the character string of a regular expression
You can concatenate variables in string format with each other and with text.
If you take two variables:
- A date variable date: 8/9/2019
- A hourly variable: 11:34:33
If you create a variable $day, and give it the value $var(date)_$var (time)
Then its literal value will be 8/9/2019_11:34:33
Transformation into regular expressions
Regular expressions are used to divide strings of characters to generate variables corresponding to sub-groups of characters.
The regular expression management menu will ask you for a model which must correspond to your original value.
This model includes brackets that define the subgroups and are used to determine the value of the variable.
By selecting group 1, the variable will have the value that corresponds to the model defined in the first parenthesis.
Transformation into date
It is possible to perform date calculations to obtain a later or later date, in a day, a month, etc.
From the value entered, selectors can be used to add or subtract days, months or years.
The original format supported can be m/d/yy or yyy-mm-dd, i.e. an English format..
The date obtained can then be used in regex variables to retrieve the day, month or year.
Transformation into hourly
It works in the same way as transforming a variable into a date, in which case the 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.
Transformation into numeric
Variables transformed into numbers are used to manipulate integers or decimals in the nn.nnnnnnn. format.
The input format can be a decimal number in this format, or a decimal number with a comma as the separator.
Standard operators can be used to perform calculations:
- +: addition
- : substraction
- x : multiplication
- / : division
The most common mathematical functions are implemented: sin, cos, tan, power, ln, etc.
For very specific cases where you need to perform particular operations, you can call java code by passing certain values as parameters and then retrieving a variable on which you can place a control.
Use of "if" conditions
You can use the “if” condition in variables with numeric transformation.
For a formula made up of 3 groups:
if($var(var1) < $var(var2) ; 1 ; 0)
1st Group = $var(var1) < $var(var2)
2nd Group = 1
3rd Group = 0
If the formula is verified, the first value after the semicolon, will be displayed: i.e. the 2nd group with the value 1
If the formula is not verified, the 3rd group will be displayed: i.e. the value 0.
Agilitest and AI
To facilitate the design and maintenance of your tests, Agilitest offers AI integration to improve the day-to-day work of test designers.
The first time you open Agilitest, or following an update, a window will open asking you to accept or reject the integration of artificial intelligence into Agilitest.
It is important to specify that the integration is not intrusive and has no access to your personal or company data.
You can change the choice of AI use in Agilitest directly from the settings in the editor, top left:
Tick the box to enable or disable the integration of artificial intelligence.
ChatGPT : A tool for creating your variables
Increase the comfort of using Agilitest and the reliability of your scripts with regular expressions generated by ChatGPT in Agilitest.
When you create a variable, it is sometimes difficult to know which regular expressions to write or which date format to enter.
By using the ChatGPT function to create your variables, you can solve these problems and also describe the tester's needs in natural language so that you can carry out the only slightly technical operations in Agilitest.
To access this function, go to the variables menu and click on the "ChatGPT" button.
This will open a dialogue window with ChatGPT
This window adapts depending on whether you want to transform a phrase into a regular expression,
Or create a variable date.
In the regular expression case :
Once you have entered the value of your variable, click on the "ChatGPT" button.
Enter the data you wish to extract from the phrase entered as the value
ChatGPT will generate the regular expression you need to enter into Agilitest to extract the data, along with an explanation of the expression
This intuitive approach eliminates technical hurdles and allows you to focus on your test work, giving you a higher level of comfort. For example, ask ChatGPT to get :
- The machine’s name
- The build version
- The windows version
- The machine name after the second dash
- The date format
If in the sentence "Microsoft Windows 11 Professional, Machine name: DT-W-PIERREH, build version: 22621" you want to extract the Windows version and the Build version, then write your query in ChatGPT :
The regular expression proposed by ChatGPT will be automatically entered into the model input in Agilitest
Even if the integration of artificial intelligence is not intrusive, do not enter personal or company data in the AI search bar. The AI will not process information linked to your Agilitest licence, but it will process all the information you give it in a text input. Do not make it process your passwords, for example.
Return a variable in subscripts
To ensure that a variable created in a script also appears in subscripts, you will need to use the $var(script_path.script_name.variable_name) function to retrieve this value from any subscripts in your runtime.
If you have a "Phone" directory with a script called "Samsung" and a variable in this script called "Version", then you enter the function $var(Phone.Samsung.Version).
If the script is in the root directory, you don't need to specify the script path. So $var(script_name.variable_name) is enough.