Wednesday, 13 July 2016

Working with child objects - QTP

What is child object?

Child object is the method provided by the QTP to extract the collection of object define by you using dynamic descriptive programming .

When programmer define any of the object(like button, link), they define certain properties like html tag, innerHTML,outerHTML,value etc, we are using these properties in our dynamic DP and get the collection of similar objects.


here is the example:
In this example, I am trying ;to find out how many webtable is present in one of our most popular site.

systemutil.Run"iexplore"."http://newtours.demoaut.com/mercuryregister.php"
Set A=description.Create
A("micclass")="WebTable"
A("html tag")="TABLE"

'Setting the object collection
Set ObjDesc=browser("opentitle:=Register: Mercury Tours").page("title:=Register: Mercury Tours").ChildObjects(A)

'Count number of similar objects we found
TabCnt=ObjDesc.count
print TabCnt

'traverse every object

For i=0 to Tabcnt-1 step 1
ObjName=Objdesc(i).getroproperty("name")
msgbox ObjName
   ObjRwCnt=ObjDesc.rowcount
   ObjClmnCnt=Obdesc.columncount(ObjRwCnt)
   print ObrwCnt
   Print ObjClmnCnt
Next



Descriptive Programming

What is Descriptive Programming(DP)?
-Entering Objects Information directly into the test script is called descriptive programming.In DP, we will be "manually" specifying the properties and values by which the relevant object will be identified. This way QTP won’t search for the properties data in the Object Repository, but will take it from the DP statement.

-Object Spy is used to get the properties and their values to uniquely identify the objects in the application. If we know such
   properties and their unique values that can identify the required object without ambiguity, we need not use Object Spy.

What is the Need of DP?
During the automation, we always encountered with the objects whose properties are frequently changing(Dynamic in nature). To handle all these objects QTP provide a unique way of handling these kind of object which is DP.

Types of DP:
There are two types of DP Static DP and Dynamic DP

Static DP:
We provide the set of properties and values that describe the object directly in a VBScript statement.

Example-
'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com" 

'Wait till browser loads
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").Sync 
' Enter  Email id in Username Field
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=Email").Set  "vb-excel.blogspot.in/" 
'Enter password in Passowrd Field
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:= Passwd").Set  "qtp" 
'Cick on the Sign In Button
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebButton("name:=Sign in").Click

Dynamic DP:
We add a collection of properties and values to a Description object, and then enter the 
Description object name in the statement

Example-
Set  Dbrowser=description.Create
Dbrowser("micclass").value="Browser"
Dbrowser("title").value="Gmail: Email from Google" 
'Descriptive object to identify  Web page with a particular title
Set  Dpage=description.Create
Dpage("micclass").value="Page"
Dpage("title").value="Gmail: Email from Google" 
'Descriptive object to identify a  particular Web Button
Set  Dbutton=description.Create
Dbutton("micclass").value="WebButton"
Dbutton("name").value="Sign in" 
'Descriptive object to identify  Web Text Box
Set Dedit=description.Create
Dedit("micclass").value="WebEdit"
Dedit("name").value="Email" 
'wait till browser loads
Browser(Dbrowser).Page(Dpage).Sync 
' Enter  Email id in Username Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set  "vb-excel.blogspot.in/" 
Dedit("name").value="Passwd" 
'Enter password in Passowrd Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set  "qtp" 
'Cick on the Sign In Button
Browser(Dbrowser).Page(Dpage).WebButton(Dbutton).Click


Sunday, 10 July 2016

QTP - Working with webtables

During your journey to the automation of web based application, you have encountered with a situation in which you have to click on a object and when you spy that object, you found that the object is embedded in webtable.

So to click on the object, you have to traverse to the webtable and reach that object and perform the action.

Below are the example to ON the checkbox inside webtable.

Browser("Google").Page("Google").Sync
Browser("Google").Navigate "http://www.nucleation.in/function-check-uncheck-web-checkbox/"


Browser("QTP Function to Check").Page("QTP Function to Check").Sync
Set A= description.Create
A("micclass").value = "WebTable"
A("html tag").value = "TABLE"
A("name").value = "Passenger 1"
Set B = Browser("QTP Function to Check").Page("QTP Function to Check").ChildObjects(A)
MSGBOX b.COUNT
For I = 0 TO B.COUNT-1
'MSGBOX B(I).ROWCOUNT

For J= 1 TO B(I).ROWCOUNT
'MSGBOX B(I).COLUMNCOUNT(J)
For K = 1 TO  B(I).COLUMNCOUNT(J)
x=B(I).GETCELLDATA(J,K)
' MSGBOX x
If UCASE(x)="PASSENGER 2"  Then
msgbox j
msgbox k
set c = B(i).childitem (j,3,"WebCheckBox",0)
c.set "ON"


End If

Next



Next

Next