Monday, March 12, 2007

Adjusting the Script with Regular Expressions

Your test is almost finished. Before running the test you should look through it to see if there are any elements that may cause a conflict in a data-driven test. The DataDriver wizard finds all fixed values in selected checkpoints and recorded statements, but it does not check for things such as object labels that also may vary based on external input.
In the flight application, the name of the Fax Order window changes to reflect the fax order number. If you run the test as it is, the test will fail on the second iteration, because the Flight Application will open a window labeled, "Fax Order No. 1", but the script tells it to make the window labeled, "Fax Order No. 4" active. WinRunner will be unable to find this window.
To solve this problem, you can use a regular expression. A regular expression is a string that specifies a complex search phrase in order to enable WinRunner to identify objects with varying names or titles.
In this exercise you will use a regular expression in the physical description of the Fax Order window so that WinRunner can ignore variations in the window’s label.
1 Locate the Fax Order window in the flight1a.gui GUI map file.
Choose Tools > GUI Map Editor. Choose View > GUI Files. Select the Fax Order No. 4 window icon.
2 Modify the window label with a regular expression.
Select Modify. The Modify window opens. In the Physical Description label line, add an "!" immediately following the opening quotes to indicate that this is a regular expression. Delete the period, space and the number "4" at the end of the line and replace this text with ".*" to indicate that the text following this phrase can vary.
3 Close the Modify dialog box.
Click OK to close the Modify window
4 Save the GUI map (only if you are working in the Global GUI Map File mode) and close the GUI Map Editor.
If you are working in the Global GUI Map File mode, Choose File > Save to save your changes and choose File > Exit to close the GUI Map Editor.
If you are working in the GUI Map File per Test mode, choose File > Exit to exit the GUI Map Editor.