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.
To start at the beginning of the tutorial, see the HCL OneTest™ UI Tutorial.
We just saw how the script passes completely on ClassicsB now. That was our goal because the changes made to the application in ClassicsB are correct. So the script is now in the state we want it to be in going forward. Now when you play it back against ClassicsA, the script fails because of the changes made earlier. You might want to allow more than one variant of an object to pass. You may 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
-
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 HCL OneTest™
UI toolbar.
During playback, HCL OneTest™ UI pauses briefly on the check box object, but eventually it finishes. The script now gives a warning. Notice in the log that the warning is for the same object, the password check box.
- 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 Applications > Run.
- Select ClassicsJavaA and then click OK.
- Pick any CD and click Place Order in ClassicsCD to open the Member Logon dialog box.
- Add the new object into the map by clicking Test Object > Insert Object(s).
- Use the Object Finder to select the password check box in the Member Logon dialog box in the application.
- Click Next, and then 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
- In the top pane, right-click the checkRemember value
and click Convert Value to Regular Expression.
HCL OneTest™ UI 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 edit the remainder to read:[rR]emember
- Click outside of that 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 select Convert Value to Regular Expression to convert it.
- Then double-click it 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 there is no space. This pattern covers both cases.
- Click Next, and then Finish in the wizard.
- Click in the object map to save the changes, and close the object map.
- Close ClassicsCD.
Now here comes the fun part!
- Play back the script again on ClassicsA. If necessary, click anywhere
inside the HCL OneTest™
UI window to activate the product toolbar,
then click the Run Functional Test Script button.
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 no longer appears in the log.
- Close the log.
- Change the StartApp command to play back ClassicsB, and 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 the object map, see Test Object Map.
For more information about regular expressions, see Replacing an Exact-Match Property With a Pattern.
Tutorial summary
This HCL OneTest™ UI tutorial has shown you how to set up HCL OneTest™ UI for testing, recording and playing back scripts, creating verification points and using the Verification Point Comparator to update object properties or data, and several ways to use the object map to your advantage. There are many other features and use cases of HCL OneTest™ UI, such as the ClearCase® integration and cross-platform playback. Look through the table of contents in the HCL OneTest™ UI User Guide for more information about using HCL OneTest™ UI.