Most of the frameworks developed in QTP for large scale application will use Descriptive programming. There are many situations where some objects in application under test changes dynamically but not the whole part but just a part of it. Recording all these objects in Object Repository (OR) will be time consuming and not an effective way of coding. Hence the best is using Regular Expression.
Well using regular expression in descriptive programming is as simple as using it in Object Repository of QTP
The coding looks like this.
Line by Line explanation
First we will declare a variable which will hold the Window name, which will not change all over the application.
Next we are creating a Description object for “ObjectDesc
” and assigning properties for the object.
Note we have set a “RegularExpression
” for the property of object in “innertext
“. It means we are going to use regular expression in inner text of the object.
As you could see in line 9 of the screen shot, the inner texts value will be in Regular expression with Window name enclosed with (.*).
Thus if the window name is “Login Window – ABC
” or “New Login Window – Karthik
” the window will still be recognized, since the expression are placed in both side of the DynamicwindowName variable.