Saturday, April 11, 2009

QTP Descriptive Programming Questions

Can Descriptive Programming be used with Smart Identification?

Smart Identification works with the help of Object Repository. In case of Descriptive Programming we bypass the Object Repository. So the Smart Identification mechanism is not used with Descriptive Programming or Programmatic Description.

How to use regular expressions with descriptive programming?

Regular expressions can be used with descriptive programming. Let us take a small example. This below example clicks on File ->Open, menu of either a new blank Notepad or WordPad which ever is open. You can write the below example in a new test in QTP and make sure either a new Notepad or a WordPad window is open and run the test. It uses regular expression in the second line where value of regexpwndtitle in case of Notepad is Notepad and in case of WordPad is WordPad. So I have used regular expression for this where first four dots (.) correspond to any four characters and after these four characters there can be capital or lower case p and then ad.

Set myobj = Description.Create()
myobj("regexpwndtitle").Value = "....[Pp]ad"

Window(myobj).WinMenu("menuobjtype:= 2").Select ("<item 1="">;<item 2="">")

Or

Set myobj = Description.Create()
myobj("regexpwndtitle").Value = "....[Pp]ad"

Window(myobj).WinMenu("menuobjtype:=2").Select "File;Open... Ctrl+O"

In this above code there can be issues if there is no proper spacing between File;Open… and Ctrl+O

Is there a way to use special characters in descriptive programming?

Let’s understand this with a very simple example:

Open a new blank notepad and type

<title>Welcome A*</title>And save it with .html extension as I saved it as sac.html under c:\
After it is saved just double click it to open it with Internet Explorer.



Now in a new test in QTP type:

Browser("text:=Welcome A* - Microsoft Internet Explorer").Refresh

Make sure that “Welcome A*” Internet Explorer window is open. Run the test.
It will show an error.



Now rewrite the above line with a backslash “\” in front of *

Browser("text:=Welcome A\* - Microsoft Internet Explorer").Refresh

It will work fine.

You can try another example:

a=Browser("text:=Welcome A\* - Microsoft Internet Explorer").Exist
Msgbox a


Is it possible to use descriptive programming inside a checkpoint?

No it is not possible to use descriptive programming with the checkpoint object as in the below line of code:

Browser("Browser").Page("Page").check checkPoint("text:=sometext")


Also see:

Parameterize Descriptive Programming
Object Repository VS Descriptive Programming
Descriptive Programming in QTP
Object Repositories in QTP