Categories

Regular expressions

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

We allow their usage in several places in Agilitest:

Component recognition

In Capture mode, when you have selected a component by pressing the CTRL key, you can then click on the attribute of interest to select its value.

How do I match a UUID?

In the case presented above, we have only one cd_frame_id_ attribute whose value will eventually change over time since it is a UUID.

We can allow Agilitest to recognize it simply by clicking on the "Regular Expression" checkbox and entering the following regular expression in the property value: [0-9a-fA-F]{32}This regular expression indicates that we are going to look for a 32-character string, consisting only of hexadecimal characters.

Entering a regular expression

Afterwards, a statistics request allows to recognize the element in a unique way in the page:

The uuid is recognized

Thanks to the regular expression, the value of the uuid can be modified, but as long as it remains a 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.

Checking up

It is possible to use regular expressions in the action of checking object properties or variable values.

In the case below, we use the same regular expression as before to check that the format of the cd_frame_id_ property is indeed that of a uuid. Obviously, we use another way of identification to find the element (here id = examples-iframe).

Checking the format of a uuid

Manipulations of variables

Finally, it is possible to use regular expressions to perform operations on variables, with the objective of recovering certain sub-parts of them. We use the notion of capturing parenthesis, associated with a group number: the complete regular expression is decomposed into sub-expressions surrounded by parenthesis, it is then possible to retrieve the part of the variable we are interested in by its group number corresponding to the number of the parenthesis in the global regular expression. In the example below, we have retrieved a complete text that includes a price we wish to check.

Recovery of the raw text containing a price to be checked

Using the following regular expression:

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

We can retrieve successively:

  • The price in euros corresponding to group 1
  • The cents after the comma corresponding to group 2
  • The additional text corresponding to group 3

Recovery of pennies

Finally, what is the use of regular expressions?

You will have understood: the use of regular expressions will allow you to surgically target the different elements of your tests: components, variables, values and add a lot of robustness during their execution. For people who are not familiar with them, after the first errors and the surprise of the discovery, this technology is actually quite simple to use and allows you to do a lot of things without writing a single line of code.

Still require support?
Contact support