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

  1. To play back against ClassicsA, edit the startApp command at the top of the script and change the B to an A.
  2. Click Run Functional Test Script on the Functional Test toolbar.
    During playback, HCL OneTest UI 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.
  3. 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.
  4. In the object map, open the application by clicking Applications > Run. Select ClassicsJavaA and then click OK.
  5. Pick any CD and click Place Order in ClassicsCD to open the Member Logon window.
  6. Add the new object to the map by clicking Test Object > Insert Object(s).
  7. Use the Object Finder to select the password check box in the Member Logon window in the application.
  8. Click Next, and then click Finish.
  9. In the top pane of the object map, drag the old check box object to the new check box object to unify the objects.
  10. 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

  1. In the top pane, right-click the checkRemember value and then 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.

  2. Double-click the name value again so that you can edit the field.
  3. Delete the word check and then edit the remainder to read: [rR]emember.
  4. 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".

  5. Right-click the Remember Password value and then select Convert Value to Regular Expression to convert it.
  6. Double-click the value and edit it to read: Remember.*Password. You are removing the space and adding the period (.) and asterisk (*) characters.
  7. 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.

  8. Click Next, and then click Finish.
  9. Click File > Save in the object map to save the changes, and then close the object map.
  10. Close ClassicsCD.
  11. 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 objectjavax.swing.JLabel is different. The properties verification point is expected to fail because the text Orders for Trent Culpito was never changed to a regular expression. The object recognition warning on ClassicsA is no longer in the log.
  12. Close the log.
  13. 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 HCL OneTest UI Help.