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)

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

  1. Anonymous Says:
    May 17, 2013 at 7:56 AM

    Hi George,

    Thanks for the wonderful explanation. Please let me know if we can use regular expression if the name of the winobject keeps differing on every instance. If it can be done, can you let know how?

    Thanks in Advance

  2. Christopher says:
    December 31, 2019 at 3:23 AM

    Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
    Hp Fax Test

Post a Comment

Visitors

Website Counter