While working with web based applications, sometimes element attributes may be dynamic with variable values for the attributes. At the same time, these values may be adhering to a specific pattern or format. In such cases, you would modify these attribute values to use a "pattern" and mark the value of the attribute as "regex".
Regular expressions allow removing unstable portions of attribute values by making the Selector rely on a stable pattern rather than hard coded literal with dynamic values.
This is extremely helpful when you prefer an attribute to be used for element identification, but it has some dynamic or unstable portion in it. Consider the example below.
In this example, the value of id seems perfectly functional for the Book Now button, except for the random characters in the end.
If you chose to use id attribute for element identification, just remove the unwanted random characters in the end and mark the value as a "Regex".
Regular Expression Syntax
accelQ follows standard Javascript regular expression syntax. You can find extensive information and help about regular expressions in the public domain on the web. Here is one of those useful articles.
https://www.rexegg.com/regex-quickstart.html
Examples for Regular Expressions
Note: Be sure to mark the checkbox for Regex when using regular expressions. This checkbox is displayed only when you are editing an attribute value after selecting the checkbox to the left of the attribute name.
Description |
Example |
Regex |
text with leading/trailing blank spaces | " Select " |
"Select" (just remove spaces and mark as "regex") |
Multiple consecutive spaces | "Select Hotel" | "Select[ ]+Hotel" |
Text with unwanted/random numerics | "Select Hotel 1873" | "Select Hotel [0-9]+" |
Text with unwanted alphanumeric text | "Select Hotel a3X0kj8U" | "Select Hotel.*" |
Text with multiple variable components | "18 of 32 flights from $320" | "[0-9]+ of [0-9]+ flights from \$[0-9]+" |
Generic Phone number | "972-333-1322" | "[0-9]{3}\-[0-9]{3}\-[0-9]{4}" |
Generic email address | "dilbert@accelq.com" | "[a-z]+@[a-z]+\.[a-z]+" |
Starts with "HL" | "HL#2cxcansdkxsd" | "^HL.*" |
Ends with "UX" | "safjk3mds8sxUX" | ".*UX$" |
Other usages for Regular expressions in accelQ
Apart from element attribute value, regular expression syntax is used in verification commands in action logic development. You may encounter this in various text verification commands as well as in the API test wizard for validating the API responses.
No matter what the use case is, same syntax is applicable and the concepts in this article apply.
Comments
0 comments
Article is closed for comments.