Krishna Logo
qa training in canada now
Divied
Call: Anusha @ 1 (877) 864-8462

 

Latest News
Home Navigation Divied
OTHERS Navigation Divied QUICK TEST PROFESSIONAL Navigation Divied How to use regular expressions
How To Use Regular Expressions
How to use regular expressions

Problem Description: How to use regular expressions


Solution: Using regular expressions

A regular expression is a string that specifies a complex search phrase. In most cases the string is preceded by an exclamation point (!). By using special characters such as a period (.), asterisk (*), caret (^), and brackets ([ ]), you define the conditions of the search.

Note:
In descriptions or arguments of functions where a string is expected, such as the match function, the exclamation point is not required.

Regular expression syntax
Regular expressions must begin with an exclamation point (!), when defined in a physical description. It is not used with GUI checkpoint properties, a text checkpoint, or a match, obj_find_text, or win_find_text statement. All characters in a regular expression are searched for literally, except for a period (.), asterisk (*), caret (^), and brackets ([ ]). When one of these special characters is preceded by a backslash (), WinRunner searches for the literal character.

For information on how to use the regular expression characters, please refer to Problem ID 15102 - What options are available for use in regular expressions.

A regular expression should be used when a property of a GUI object can change each time you replay your script.

Example:
In the application, you create an order. A few screens later, the order number is appended to the window's title. During replay, a new order will be created generating a different order number. Using the old order number when referring to the window will cause the script to fail since WinRunner cannot find the window. You can use the regular expression to instruct WinRunner to ignore the varying part of the window title.

Regular expressions can be used in the following cases:

  • Within the physical description of a window or object in the GUI Map
  • Within a GUI checkpoint, when verifying the contents of an edit field or static text object.
  • Within TSL functions that search for text, such as win_find_text and obj_find_text.

Using a regular expression in an object or window's physical description
You can use a regular expression in the physical description of an object in the GUI map, so that WinRunner can ignore variations in the value of a property, such as label. Regular expressions are typically used with the properties that reference the object's label or title, though they are not restricted to those properties. Any attribute that refers to a text property and not a physical property (x, y, width, height, etc.) is a candidate for regular expression use.

Note:
Being a candidate for regular expression use does not mean that WinRunner will be able to find the object or window once you include the regular expression. You may have to use trial and error to determine if the problematic attribute will accept a regular expression. If a regular expression cannot be used for the varying property, use GUI Map Configuration to instruct WinRunner to use a different set of properties when learning the object. For more information on GUI Map Configuration, please refer to Problem ID 1330 - How to use basic GUI Map Configuration.

The attached document demonstrates how to use a regular expression with the label property of a window.

Using a regular expression in a GUI checkpoint.
You can use a regular expression in a GUI checkpoint, when evaluating the contents of an edit object or a static text object with a varying name. You define the regular expression by creating a GUI checkpoint on the object in which you specify the checks.

Note:
Some objects, such as edit fields, have regular expression property checks build in as options by default. If the object you are checking does not have a default regular expression property check, you can create a custom property check for use. For more information, refer to the Customizing GUI Checks section in the WinRunner Customization Guide. You can also refer to Problem ID 469 - How to add regular expressions for HTML links in a GUI check as an example on how to create a custom property check functions.

1. Go to Create -> GUI Checkpoint -> For Object/Window.
2. Double click on the object (very fast).
3. When the Check GUI window appears, select the RegularExpression property check.

Note:
If you are created your own custom regular expression property check, select the appropriate property check.

4. With the property check highlighted, click the specify arguments button. This is the second button in the group at the right side of the window.
5. In the Check Arguments dialog, enter the regular expression and click .

Note:
When a regular expression is used to perform a check in a GUI checkpoint, it should not be preceded by an exclamation point.

6. Select any additional property checks as desired.
7. Click to close the dialog and insert a checkpoint statement into your script.

Using a regular expression when searching for text
You can use a regular expression to locate a varying text string with the win_find_text and obj_find_text functions.

Example:
obj_find_text("Edit", "Order No.*", coord_array);

or

win_find_text("Edit", "Order No.*", coord_array);

For additional information on using regular expressions, please refer to the Using Regular Expressions chapter in the WinRunner User's Guide. The following articles also provide additional information:

 


Shadow Bottom
 
 
© 2005 -