Descriptive Programming OR Regular Expression ? - Part 1


Hey, wondering what the title of this thread means ? Whats the relation between Descriptive Programming and Regular Expressions ? OK...we will come into all that. Of course, we are going to have an example, as always, to explain any concept. The example we are going to take here is an application that comes shipped with Quick Test. Its a windows based Flight Resevation application. I thought of taking this example as I could neatly explain descriptive programming and regular expression at the same time.
For those who do not have this application, dont worry, the screen shots below would be sufficient to understand the concept. Alright, so lets get into it. I opened the flight application and logged in. I have started recording only from this point forward.


First I go to File -> Open Order and selected Order 10 and clicked OK.


I then enter a FAX number and click the Send button.


OK..lets stop recording as we just need this much. Lets look at how our script looks like.

So everything looks good. If we try running this script its all fine. Now, lets perform this test on order 9 instead of order 10 so we need to modify line 4, and modify the value of 10 to 9 and then run the test. What just happened !!


OK...so whats the deal. Here is what happened. When we recorded this script, we recorded on order 10, as a result the properties of the Dialog window for Order 10 is what got stored in our object repository. Understand that its not the value "Fax Order No. 10" in Dialog("Fax Order No. 10") that is the problem. Its the properties of the Dialog window which caused the problem for which we need to see the object repository.

"Fax Order No. 10" (the value you see against Name: on the top) in Dialog("Fax Order No. 10") is just a logical name to the object and we could give any value to the logical name. Hope that is clear. If yes, then lets proceed. The object recognition problem happened because the "text" property of the dialog in the object repository did not match the application because now our text property has changed to "Fax Order No. 9". If you use the object spy on the new dialog, you would notice this. So much for the theory, now how do we resolve this issue !! We obvously want to run our tests as we may want to test this on multiple orders.
There are two ways to do this. Descriptive programming and using Regular Expressions or I would also call it "Property parametrization".
First lets look into Descriptive Programming and what it means. Below is a snippet from the Quick Test Help documentation.
"Descriptive Programming instructs QuickTest to perform operations on objects without referring to the object repository or to the object's name. To do this, you provide QuickTest with a list of properties and values that QuickTest can use to identify the object or objects on which you want to perform an operation."
In the case above, the object Dialog("Fax Order No. 10") is the object which changed which we want to work dynamically i.e. on any order. To make our code work on order 9, this is what we will do. We know that its the "text" property of the dialog which changed. So lets modify line 7 above to
Window("Flight Reservation").Dialog("text:=Fax Order No. 9").WinObject("Fax Number:").Click

Now lets rerun the modified test and see what happened. We got an error again.

And this is because
"When using programmatic descriptions from a specific point within a test object hierarchy, you must continue to use programmatic descriptions from that point onward within the same statement. If you specify a test object by its object repository name after other objects in the hierarchy have been specified using programmatic descriptions, QuickTest cannot identify the object." ( as taken from QTP Help documentation)
What this means is that, we used descriptive programming to help identify the Dialog object but we have to continue using descriptive programming from that point onwards i.e. from the Dialog object and all the child objects from that point within that statement. In short, we have to use the same technique to identify the object WinObject and even for the WinButton in Line 10. Before that lets see what properties QTP used to identify the WinObject.

and the WinButton
So we will make use of the "regexpwndclass" property for WinObject and we will use just the "text" property for the WinButton. Our modified code would look like this.

So here, you must understand that from Line 7 onwards, QTP will refer to the object repository only to look for the Window("Flight Reservation") object but from Dialog onwards, it will just search dynamically within the application (without referring to the object repository) to see the objects with the matching properties as specified by us.

Run the test and everything is going to be perfect !!
The second part of regular expressions is covered in Part 2.
Hope this example helped you in understanding this concept. Suggestions are always welcome.



I dont want to have any sort of copyright or copyleft in this site but if you are reusing this code in any other site, I would appreciate you to provide this page as a link so that others get a more descriptive explanation of this concept. Your suggestion and comments are always welcome. Cheers !!!
As always,
Your friend in need,

George, Reju

Read Users' Comments (2)

2 Response to "Descriptive Programming OR Regular Expression ? - Part 1"

  1. Anonymous Says:
    October 27, 2009 at 2:07 AM

    Simply and Neatly explained this DP and RegEx.
    Thanks for your effort.
    Keep on posting.

    By Anbu

  2. REJU GEORGE says:
    October 27, 2009 at 6:21 AM

    Thats the aim Anbu ... To make it simple yet to explain the concept clearly !! Stay tuned in for more topics.

    - George, Reju -

Post a Comment

Visitors

Website Counter