Thursday, January 13, 2011: Descriptive Programming in QTP
Thursday, January 13, 2011: Descriptive Programming in QTP
It doesnt require recording the page and so no need worry about object repository. You can optimize your code. Before starting descriptive programming you need to know about object properties and their values, using object spy you can see each objects properties.
Lets learn descriptive programming in qtp in a very simple and practical way. I have given 3 different examples which uses different method for automation in QTP. Using object repository method: Example 1 Following QTP script is the simple example of record and play method. SystemUtil.Run "http://google.com/","","","" Browser("Google").Page("Google").WebEdit("q").Set"quicklearnqtp" Browser("Google").Page("Google").WebEdit("q").Submit Browser("Google").Close Now, you want to write above script in descriptive programming. For that you need to get all object properties using object spy tool. E.g Browser is the parent object and its property is Name=Google and Page is the child object whose property is Title=Google. Now understand following example which is the combination of record & play and descriptive programming method. You can say hybrid programming. Hybrid programming: Example 2
SystemUtil.Run "http://google.com/","","","" Browser("name:=Google.*").Page("title:=Google").WebEdit("q").Set"quicklearnqt p" Browser("name:=Google.*").Page("title:=Google").WebEdit("q").Submit Browser("name:=Google.*").Close Note: Dont copy and paste and try to run above examples because it requires object repository to execute. Now at this point you may be very well aware of hybrid programming (combination of descriptive programming and using object repository method). Following is the example of pure descriptive programming in QTP which you can copy and paste to QTP (Tested with QTP 10 and IE 8) and can execute it. Descriptive programming in QTP: Example 3 'Variable declaration Dim GoogleBrowser Dim GooglePage Set GoogleBrowser=Browser("name:=Google.*") Set GooglePage=GoogleBrowser.Page("title:=Google.*") 'URL URL="http://www.google.com" SystemUtil.run "iexplore",URL 'Write 'quicklearnqtp' in search box GooglePage.WebEdit("name:=q","type:=text","html tag:=INPUT").Set "quicklearnqtp" 'Click on Google Search GooglePage.WebButton("name:=Google Search","index:=0","type:=submit","html tag:=INPUT").Click 'Close browser GoogleBrowser.CloseAllTabs I hope you gained a lot on descriptive programming technique from this post.I will provide more real time examples and details on descriptive programming in QTP in my next post. Let me know your inputs on descriptive programming in QTP and share your feedback.
Descriptive Programming to open order in flight application window("text:=Flight Reservation").winmenu("menuobjtype:=2").Select "File;Open Order..." window("text:=Flight Reservation").Dialog("text:=Open Order").Click Window("text:=Flight Reservation").Dialog("text:=Open Order").WinCheckBox("text:=&Order No.").Set "ON" Window("text:=Flight Reservation").Dialog("text:=Open Order").WinEdit("window id:=1016").Set "4" Window("text:=Flight Reservation").Dialog("text:=Open Order").WinButton("text:=OK").Click