Showing posts with label Object Repository. Show all posts
Showing posts with label Object Repository. Show all posts

Descriptive Programming OR Regular Expression ? - Part 2

This is the second part to the post "Descriptive Programming OR Regular Expression ?". I recommend you to read the first part before you proceed, so please click here.
In the earlier part, we discussed how to use descriptive programming to make QTP to skip looking at an object in the object repository. Instead, we understood that descriptive programming helps QTP to identify an object in the application dynamically without searching in the object repository. In this part we will see another technique to look at objects when we are not sure of a particular behaviour of an object which would keep changing for every iteration or every time you work on the application. Some examples are new order numbers which are created newly every time or checking for the current date and time which would always change. Lets look at the example we saw in Part 1, where we want QTP to continue with the testing even when the order number changes. Here is where regular expressions are of great help. One of the sites which I often refer to for regular expressions is the regular-expressions.info site.
The way we are going to accomplish our task can be done through two ways.
1. Use regular expressions in our descriptive programming OR
2. Set a particular property value to a regular expression so that it would match the patterns that the particular property can have.

Lets try the first option. Now, we know that the only property which changes in our case is the "text" property of the Dialog object. So lets change the property to a regular expression. We know that the value "Fax Order No." is always constant but its the order number that keeps on changing. So we need to set a pattern such that the property text value should accept anything like Fax Order No.1, Fax Order No.2 or even Fax Order No.100. In a regular expression, to match any number, the pattern would look like [0-9]+. This means that any occurrences of any digits would match this pattern. So lets see how our script is going to look like...
The script in Part 1 would only have worked for Order no. 9 with the modified script but now, we have modified such that lines 7 and 8 of this script would work on any order number. However this script is very small but if we had a very large script, can you anticipate what the problem could be ? Yes, we would have to sit and modify each of the child objects that come after Dialog because we have to use descriptive programming for all the child objects as well. So here is where we are going to use one of the mostly used and effective techniques in QTP. We are going to make the regular expression change in the object repository itself and our program is going to look much neater.
We made the regular expression modification in the object repository and notice that I made one more change. Since this object is now going to be a more generic object, I modified the logical name of this object from Fax Order No. 10 to just Fax Order No. Now lets see how our code is going to look like
Now we dont need to take care of the child objects here because we are no longer using descriptive programming here. This has made our code also look very neat and this is one of the best ways to implement dynamic handling of objects in this particular case. I know this is quite overwhelming in the beginning but descriptive programming and regular expressions are some of the very important features that we make use of in QTP.

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)

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)

Visitors

Website Counter