Working with Regular Expressions
In this tutorial, 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.
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.
2 Save the test as RegExpression.
Select File > Save As. Save the test as RegExpression.
3 Confirm that the Active Screen option is enabled.
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.
4 Select the text for which you will create the checkpoint.
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/2004). Right-click the highlighted string and select Insert Text Checkpoint. The Text Checkpoint Properties dialog box opens.
5 Enter the regular expression for the text you want to check.
In the Checked Text area, click the Constant Value Options button. The Constant Value Options dialog box opens.
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.
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.
2 Save the test as RegExpression.
Select File > Save As. Save the test as RegExpression.
3 Confirm that the Active Screen option is enabled.
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.
4 Select the text for which you will create the checkpoint.
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/2004). Right-click the highlighted string and select Insert Text Checkpoint. The Text Checkpoint Properties dialog box opens.
5 Enter the regular expression for the text you want to check.
In the Checked Text area, click the Constant Value Options button. The Constant Value Options dialog box opens.
In the Value box, replace the current 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 accept the other default settings and close the Constant Value Options dialog box. The Text Checkpoint Properties dialog box opens.
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 accept the other default settings and close the Constant Value Options dialog box. The Text Checkpoint Properties dialog box opens.
Click OK to 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.
6 Save the test.
Select File > Save or click the Save button.
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.
6 Save the test.
Select File > Save or click the Save button.


No comments:
Post a Comment