17 Jan 2013

How To Use Regular Expression Evaluator in QTP 11

How To Use Regular Expression Evaluator in QTP 11

QTP 11 has provided a new feature to test the regular expressions that  automation testers might use in their object repository. This utility, named ‘Regular Expression Evaluator’, helps the users validate their regular expressions before the actual script execution. This utility also provides a set of common regular expressions which the testers can use to come up with their desired regular expressions. Let’s see how this feature works.


                                           Regular Expression Evaluator


To check how this utility works, we’ll try to identify two dialog boxes using the same object from the object repository. The titles of the dialog boxes are ‘QuickTest Pro 10.00 Version’ and ‘QuickTest Pro 11.00 Version’. In order to use the same object to identify both the dialog boxes, we will create a regular expression for dialog box title using ‘Regular Expression Evaluation’ utility. The two dialog boxes are shown below -


                                        
                                     Dialog boxes with different Titles a) The first step is to add the initial dialog box in the object repository. Make sure that the ‘text’ property is being used to identify the object as shown below.



                 Repository with Dialog Box object

b) Select the text property and click on button to open the ‘Repository Parameter’ dialog box.
c) Select the ‘Regular expression’ check box and click on ‘arrow button’ to display the common regular expressions.


                                            QTP Repository Parameter

d) The last item in the regular expression list is the ‘Open Regular Expression Evaluator…’ option. Select this option. This will open ‘Regular Expression Evaluator’ utility window as shown below. The ‘Regular Expression’ and ‘Sample Text’ fields will contain the value ‘QuickTest Pro 10.00 Version’.



                      Regular Expression Evaluator Window

The regular expression needs to be written in the ‘Regular Expression’ field. If the regular expression is created correctly, it will highlight the entire text written in the ‘Sample Text’ field when the user clicks on Highlight button.

e) We need to generalize the version number (10.00 & 11.00) in the title of the dialog box so that the same title can recognize both the dialog boxes. If we replace the zero in ’10‘ and one in ’11‘ with a generic expression, QTP will be able to identify the title for both the dialog boxes. To do this, select the ’0′ from ’10′ and click on the ‘right arrow’ button appearing before the Highlight button.



                                    Regular Expression List

f) Since we want to use  the generic text that represents numbers, we will select ‘d Any digit’ from the regular expression list. Once the option is selected, the 0 from ’10′ will be replaced by ‘d’ in the regular expression field. Click on Highlight button to check that the regular expression highlights the entire sample text.


                         Highlighted Sample Text

g) Since the sample text is highlighted, this means that the regular expression works correctly for the first dialog box. Let us check that the same regular expression will work for the other dialog box also. Enter ‘QuickTest Pro 11.00 Version’ in the Sample Text field below the original text. Again click on Highlight button. It will highlight both the texts which means that the same generic expression works for both the dialog boxes.



                   Generic Expression with 2 Matches

To make sure that the regular expression is indeed working, close the ‘Regular Expression Evaluator’ window and highlight the object for both the dialog boxes from the object repository.

No comments:

Post a Comment