You’ve probably seen and used regular expressions before, even if you’re not aware of it. When you search for all your digital photos (*.jpg) or list all files starting with the letter “a” (a.*) you are using a pattern language known as regular expressions, or regex. You may also not be aware that you can also use regexes in your QA Wizard Pro scripts to perform tasks, such as validating field data or verifying results, and also to ignore dynamic data in properties used as search criteria.

Regular expressions can go from relatively simple, such as verifying that a string is numeric, to extremely complex, such as verifying an international phone number is valid and in the correct format. There are regex engines available in many different languages, such as Perl, Java, Tcl, etc.  The basic syntax is the same in each, but there are differences. QA Wizard Pro supports .NET regular expressions.

A regular expression is created as a string, so you need to escape any metacharacters or classes to indicate they have special meaning. For example, the character class “\d”, which translates to “match a digit from 0-9” will generate this error message: “The \d escape sequence is not defined”. To use this class you need to prefix the expression with the escape character, which happens to be the backslash, like this: “\\d”.

The EvaluateRegExpression function compares a string against a regular expression, returning True if there is a match and False otherwise, and allows your script to branch based on the results. For example, to verify that a string contains only digits you can use the regex  “^[+]?[0-9] *$” .  You can also express this using the character class for a digit, which is “\d”, as “^[+]?\\d*$”( The “\d” has been “escaped” here). The other characters in the regex specify additional matching criteria.

With a variable REGEX = “^[+]?[0-9] *$”  the following step will print “True” for EXPR = “123”, and “False” for EXPR=”abc123”:

println(EvaluateRegExpression(REGEX, EXPR))

Regular expressions can also be used to search for window or control properties that contain dynamic data. For example, a text editor application displays the currently open file in the window text (“MyEdit – <current file name>”). Each time a new file is opened, QA Wizard Pro compares the window text to the existing windows in the repository and creates a new entry if the text has changed. This will clutter up the repository with window entries that contain the exact same data and cause a maintenance nightmare. Instead, you can change the Action column for the Text property from “Equals” to use a regular expression to ignore the dynamic data in the window text, there by avoiding duplicate information. The regex is already available for simple patterns (“Starts with, “Ends with”, or “Contains”), or you can customize your own (“Matches regex”).

Regular expressions may appear to be a string of random gibberish at first, but they are extremely powerful…and popular. You can usually find the regular expression you need on the internet, or one that can be modified to suit your needs.

Share on Technorati . del.icio.us . Digg . Reddit . Slashdot . Facebook . StumbleUpon

Related posts:

  1. Executing DOS Commands from a QA Wizard Pro Script
  2. QA Wizard Pro 2009.1 released
  3. Dynamic SQL Queries
  4. Understanding Repository Variables
  5. Understanding Application Repositories
No Comments

Tags: , ,

No comments yet.

Leave a comment

WP_Big_City

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree

Page optimized by WP Minify WordPress Plugin