Categories

Regular expressions

▶️ You can find our tutorial on regular expressions on our Youtube channel.

Regular expressions are very useful for performing operations on data, extracting subsets or recognizing patterns.

Using regular expressions will enable you to surgically target the various elements of your tests: components, variables, values, as well as add a great deal of robustness to their execution.

For those unfamiliar with them, once you get past the initial errors and the surprise of discovery, this technology is actually quite simple to use and allows you to do a lot without writing a single line of code.

Agilitest has also integrated AI within its software, if you agree to integrate it, enabling you to create regular expressions for yourself and according to your requests.

💡 Tips

Regular expressions you need to know:.

* = Random character that repeat itself zero or many times

a? = Has a zero or an a

a+ = Has one or multiple a

(?s) = Insensitive to line break and space character formatting (single line)

(?i) = Case insensitive

[abc] = A simple character in between a,b or c

[a-z]{3} = 3 letters between the a to z interval

\d = Decimal number

[A-z0-9]{2,5} = Any alphanumeric character repeating between two and five times

^[A] = Starts with A

$[A] = Ends with A

Component recognition

When you are in capture mode, accessible from the Agilitest editor, it is possible to pass components in regular expressions.

You can open the capture tool by clicking on the corresponding button in the channel management menu.

capture button

Then, select the component you wish to capture by pressing the CTRL key on your keyboard,

Captured element

It's when you select the attribute that you'll be able to change the values in regular expressions..

Once the attribute has been selected, click on it to open a text entry window.

text entry

Cross the “Regular expression” case for the value to be automatically changed

regular expression button

Thanks to the regular expression, the UUID value can be modified, but as long as it remains an UUID Agilitest will recognize it.

This trick makes it possible to recognize elements whose attribute values are highly volatile, but which retain a constant structure over time: an identical prefix or suffix, an incremented number, etc.

Verification

Regular expressions can be used to verify component properties or variable values. This action allows you to check whether the rule written in the regular expression corresponds to the value of the variable.

Example:

If your value is to have only numbers and letters, then the regular expression must match this rule and show only numbers and letters.

In the case below, the regular expression is used to check that the format of the cd_frame_id_ property is indeed that of an UUID.

regular expression in verification

Variables manipulation

Finally, regular expressions can be used to perform operations on variables, in order to retrieve certain sub-parts of them.

The complete regular expression is broken down into sub-expressions surrounded by parentheses.

It is then possible to retrieve the part of the variable of interest by its group number, which corresponds to the number of parentheses in the global regular expression.

Example:

In the example below, we've retrieved a complete text that includes a price we'd like to check.

regex in variable

By using the following regular expression:

(\d*),(\d*)\ €(.*)

You can successively recover:

  • The price in Euro corresponding to Group 1
  • Cents after the coma corresponding to Group 2
  • The additional text corresponding to Group 3
regex groups in variable

ChatGPT : A useful tool to help

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.

chatgpt button

This will open a dialogue window with ChatGPT

chatgpt box

This window adapts depending on whether you want to transform a phrase into a regular expression,

regex button

Or create a variable date.

date variable

Taking regular expressions as an example:

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

chatgpt button

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

data in chatgpt

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

chatgpt chat box

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

chatgpt's regex in Agilitest

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

Still require support?
Contact support