Regular expressions in QTP – Tutorials & Examples

What are Regular expressions in QTP?

Regular expression enables Quick Test to identify objects and text strings with varying values, Regular expressions are used when defining the properties of an object, the methods of an argument, when parameterizing a step, and when creating checkpoints with varying values.

A regular expression is a string that specifies a complex search phrase, by using special characters such as caret(^),period(.) and brackets([]),asterisk(*) define the conditions of the search

Working with Regular expressions:

First create a text checkpoint on a date text string that changes according to the selected flight date, 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, create a text checkpoint with regular expression that will match any single character within a defined range.

Regular Expressions in QTP – Examples:

Start Quick Test and open Flight Application and start recording the test

Enter the date in the Date of Flight field in the flight Reservation application and create checkpoint

Insert->Checkpoint->Text Checkpoint

Now point to the Date of Flight field in the application, the text checkpoint properties window will be opened.

Regular expressions in QTP-Properties

Enter the regular expression for the text that wants to be checked.

In the checked text area, click the Edit constant value options button, the constant value options dialog box opens.

Regular expressions in QTP-Define Constants

In the value box, change the current date with [0-1] [0-9] /[0-3][0-9]/[0-1][0-9], this instructs Quick test 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/YY.

Select the regular expression checkbox, A message box prompts to insert the backslash character before each special character, click No.

Note: Clicking yes would cause Quick Test to treat the special Characters (“[“.’(‘-‘) and ‘)’]’)as literal characters and not as a regular expression

Click OK button to accept the other default settings and close the constant value options dialog box, the text checkpoint properties dialog box opens.

Regular expressions in QTP-Constant Expressions

Click OK button to close Text checkpoint properties dialog box

Quick Test adds the text checkpoints to the test

Window(“Flight Reservation”).ActiveX(“MaskEdBox”).Check CheckPoint(“MaskEdBox_2”)

It is displayed as a new step in the test tree and stop recording

Save the script (Filename regexpress)

Run the regexpress Test.

Press F5 to run or choose Automation->Run, The run dialog box opens, select New run results folder and accept the default results folder name, click ok, when the test run is completed, the test results window opens.

Check the checkpoint results, in the results tree, expand (+) Test regexpress summary ->REgExpression interation1 (Row 1)->action1 Summary->Flight Reservation-Date of Flight: Select Checkpoint:”[0-1][01-9]/[0-3][0-9]/[0-1][0-“.

Summary
Article Name
Regular expressions in QTP - Tutorials & Examples
Description
Regular expressions in QTP enables Quick Test to identify objects and text strings with varying values,they are used when defining a property of an object.
Author
Publisher Name
Raghavendra
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *