Lesson 10: Use regular expressions
The last thing you will do using the object map is convert a property value to a regular expression. In this case, the regular expression provides more flexibility in the object recognition.
About this task
We just saw how the script passes completely on ClassicsB. That was the goal because the changes made to the application in ClassicsB are correct. So the script is now in the state you want it to be in going forward. Now when you play the script back against ClassicsA, it fails because of the changes made earlier. You might want to allow more than one variant of an object to pass. You might have a dynamic object or have several versions of your application with slightly different versions of an object, in which both are correct. You can use a regular expression to allow more than one version of a property value, such as text, to accommodate this scenario.
Open the object map and unify the objects
Procedure
- To play back against ClassicsA, edit the startApp command at the top of the script and change the B to an A.
-
Click Run Functional Test Script on the Functional Test
toolbar.
During playback, Rational® Functional Tester pauses a little on the password check box object, but eventually it finishes. The script now gives a warning. Notice in the log that it's the same object, the rememberPassword test object.
- Close the log and then open the object map from the password check box object as you did in Lesson 8, by double-clicking rememberPassword in the Script Explorer.
- In the object map, open the application by clicking ClassicsJavaA and then click OK. . Select
- Pick any CD and click Place Order in ClassicsCD to open the Member Logon window.
- Add the new object to the map by clicking .
- Use the Object Finder to select the password check box in the Member Logon window in the application.
- Click Next, and then click Finish.
- In the top pane of the object map, drag the old check box object to the new check box object to unify the objects.
-
Widen the Unify Test Objects wizard by dragging one of the sides outward to make the
fields longer, if necessary.
You will use two different regular expressions: one on the name property and one on the text property.
The unified object is shown in the Unified Test Object Properties grid (top pane); the name property has a value of
checkRemember
.
Convert a property value to a regular expression
Procedure
-
In the top pane, right-click the
checkRemember
value and then click Convert Value to Regular Expression.Rational® Functional Tester designates the value as a regular expression by the "xy" icon in front of the value text.
- Double-click the name value again so that you can edit the field.
-
Delete the word
check
and then edit the remainder to read:[rR]emember
. -
Click outside the cell.
This pattern allows the word "remember" with either an uppercase "R" or lowercase "r" to pass. This is important because the comparisons are case-sensitive, and only an exact match will pass. The value of the text property is "Remember Password".
- Right-click the Remember Password value and then select Convert Value to Regular Expression to convert it.
-
Double-click the value and edit it to read:
Remember.*Password
. You are removing the space and adding the period (.) and asterisk (*) characters. -
Click another cell.
The "." allows any character to appear in that position. In one version of the application, there is a space between the two words in this property, and in the other version there is no space. This pattern covers both cases.
- Click Next, and then click Finish.
- Click in the object map to save the changes, and then close the object map.
- Close ClassicsCD.
-
Play back the script again on ClassicsA. The image verification point and the
properties verification point fails.
The image verification point fails because the height and the weight of the object
javax.swing.JLabel
is different. The properties verification point is expected to fail because the textOrders for Trent Culpito
was never changed to a regular expression. The object recognition warning on ClassicsA is no longer in the log. - Close the log.
-
Change the startApp command to play back ClassicsB, and then run the script.
The object recognition also passes on ClassicsB Regular expressions offer more flexible recognition for an object that has different properties in different versions of an application, and both are recognized during playback. For more information about regular expressions, see the Rational® Functional Tester Help.