Categories

Using Variables - AI

▶️ 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.

script's variables

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".

create variable button

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.

error message

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,

insert special value

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:

  1. 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

property action

The property action will target an interface element

Click on the “Load” button from the Property action

load button

It will load all the properties associated with this element.

Click on the property of interest to load it during the execution

captured properties

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.

property variable

Example :

If you select the "text" property with the value "Hello world - Wikipedia" in the list of captured properties.

text property

When the property action is executed, the value of the selected property will appear in the property variable.

text property action

             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

special value menu

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".

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 variable

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.

execution variables

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
  • Date
  • Hourly
  • Numeric

Character strings

By default, all variables are character strings.

A variable can be transformed on creation by clicking on the corresponding button.

5 types of calculation

When a character string is transformed, a page is displayed according to the type used to manage it.

Example:

If you click on “Regular Expr.” button

regular expr button

This will display entries corresponding to the character string of a regular expression

a regular expression

You can concatenate variables in string format with each other and with text.

Example :

If you take two variables:

  • A date variable date: 8/9/2019
  • A hourly variable: 11:34:33
hourly variable

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.

regular expression

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.

date variable

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.

hourly variable

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.

numeric variable

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.

Example:

example with value and variables

Evaluate : interpret Java and Javascript code

An “evaluate” button allows you to interpret Java and Javascript code.

This feature can be used on both non-editable variables by retrieving the correct property, and editable variables.

When you choose to evaluate a variable, you can choose between 2 languages: Java and Javascript.

You can enter Java or Javascript code as a value.

Interpreting Java and Javascript code can be done with simple code retrieval, but also with complex test results.

It is possible to set conditions in Java and Javascript. This can be done with conditional tests, and the results of these conditional tests can be retrieved.

For these code evaluations, Java or Javascript notation must be used.

Examples :

Simple Java code:

simple java code

Simple Javascript code:

simple javascript code

Interpreting conditionals Javascript functions:

if($var(var1) > 14){"ok";}else{"ko";}

With the variable $var1 which can equal to text or numeric.

If you're not sure what code to enter, you can ask Agilitest's built-in AI.

You can also express your request using voice input.

To do this, press and hold the microphone and express your needs clearly and precisely.

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.

AI helper

🔸 Warning

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:

settings button

Tick the box to enable or disable the integration of artificial intelligence.

AI helper settings

To access this function, go to the variables menu and click on the "AI" button.

This will open a dialogue window with AI

dialogue window

This window adapts depending on whether you want to transform a phrase into a regular expression or a date variable

In the regular expression case :

Once you have entered the value of your variable, click on the "AI" button.

Enter the data you wish to extract from the phrase entered as the value

natural language

The AI will generate the regular expression you need to enter into Agilitest to extract the data, along with an explanation of the expression

chatgpt response

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 the AI to get :

  • The machine’s name
  • The build version
  • The windows version
  • The machine name after the second dash
  • The date format
  • etc…

Example :

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 the AI:

query entered in chatgpt

The regular expression proposed by the AI will be automatically entered into the model input in Agilitest

input from AI

🔸 Warning

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.

Example:

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).

🔸 Warning

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.


Still require support?
Contact support