Sunday, January 1, 2012

Working with Regular Expressions

 You will create a text checkpoint on a date text string that changes according to the selected flight date. You can define the date as a regular expression so that the checkpoint checks that the captured text string matches the expected format, rather than checking the exact text.

To do this, you will create a text checkpoint with a regular expression that will match any single character within a defined range.

  1. Start QuickTest and open the Recording test.
  2. If QuickTest is not already open, choose Start > Programs > QuickTest Professional > QuickTest Professional.

    • If the Welcome window opens, click Open Existing.

    • If QuickTest opens without displaying the Welcome window, choose
      File > Open or click the Open button .
    • In the Open Test dialog box, locate and select the Recording test, then click Open.

  3. Save the test as RegExpression.
  4. Choose File > Save As. Save the test as RegExpression.

  5. Confirm that the Active Screen option is enabled.
  6. If you do not see the Active Screen at the bottom of the QuickTest window, click the Active Screen button or choose View > Active Screen.

  7. Select the text for which you will create the checkpoint.
  8. In the Keyword View, expand Welcome: Mercury: Tours and click the Select a Flight: Mercury page. The page is displayed in the Active Screen.
    In the Active Screen, scroll up and highlight the date for the outbound flight, New York to San Francisco (12/29/2007). Right-click the highlighted string and select Insert Text Checkpoint. The Text Checkpoint Properties dialog box opens.

  9. Enter the regular expression for the text you want to check.
  10. In the Checked Text area, click the Constant Value Options button . The Constant Value Options dialog box opens.

    In the Value box, replace the displayed date with [0-1][0-9]/[0-3][0-9]/200[0-9]. This instructs QuickTest to check that each character in the selected text matches the number-range format defined by the regular expression. The expression checks for the following format: MM/DD/200Y.
    Select the Regular expression check box. A message box prompts you to insert the backslash character before each special character. Click No.
    Note: Clicking Yes would cause QuickTest to treat the special characters ( [ ), ( - ) and ( ] ) as literal characters and not as a regular expression.
    Click OK to close the Constant Value Options dialog box.

  11. Rename the checkpoint.
  12. In the Name box, enter CheckExpectedText as the new checkpoint name.
    Click OK to accept the other default settings and close the Text Checkpoint Properties dialog box.
    QuickTest adds the text checkpoint to your test. It is displayed as a check operation on the Select a Flight: Mercury page in the Keyword View.

  13. Save the test.
  14. Choose File > Save or click the Save button .

No comments:

Post a Comment