Monday, 3 March 2014

QTP Web Examples

1.     WebTable  Syntax's 1.1  Working with WebTable Examples 2.     Working with WebSites 2.1. Once we get the Test Result from QTP. I ... thumbnail 1 summary


1.    WebTable Syntax's
1.1  Working with WebTable Examples

2.    Working with WebSites

2.1. Once we get the Test Result from QTP. I have to convert into excel file format.
2.2. How to execute the functions with select statement using the Design time DataTable.

2.3. Find the Inbox Unread mails count

2.4. Click the Particular Mail in the Mails List

3.    Working with Browser

!**********************************************************!
1.   WebTables Syntax's:

HTML normally has many webtable and we can extract a lot of information using webtable methods in QTP. In this post we will discuss various methods by which we can used for webtable object.


Example 1: Validate if a webtable exist

boolExist = Browser(…).page(…).webtable(…).exist


Example 2 : To Find number of rows and columns in a web table

intRowCnt=Browser("Google").Page("title:=.*").WebTable(“name:= TTable").RowCount
For r=1 to intRowCnt
‘’ This will loop through each row and tell count of column in each row.
intColCnt=Browser("Google").Page("title:=.*").WebTable(“name:=TTable").ColumnCount(r)
MsgBox intColCnt
Next

Example 3: How to get data in a particular cell in the data table
strData= Browser("Google").Page("title:=.*").WebTable(“name:=TTable").GetCellData(r,c)
Where r = row number and c = column number


Example 4: Using childObject method to find objects of a particular type within a webtable

Public Function func_findObjectinaWebTable(strObjType)

Set objDesc=Description.Create
objDesc("micclass").value=strobjType
set objChild=Browser("Google").Page("title:=.*").WebTable(“name:=TTa").ChildObjects(objDesc)
func_findObjectinaWebTable = objChild.count

End Function

Example 5: Using HTML DOM to get count of objects in a webtable
Public Function func_findObjectinaWebTable(strTagName)
set objChild= Browser("Google").Page("title:=.*").WebTable(“name:=TestTable").object.getElementsbyTagName(strTagName)

func_findObjectinaWebTable = objChild.length

End Function


Example 6: Using ChildItemCount and childItem in webtable to extract information

Public Function func_findObjectinaWebTable(strObjType,introw,intCol)

ob0jChildCnt=Browser("Google").Page("title:=.*").WebTable(“name:=TestTable,"index:=0").ChildItemCount(introw,intcol,strobjType)
If objChildCnt >0
Childitem will return object oftype defined in arguments for childitem
Set ChldItm = Browser("Google").Page("title:=.*").WebTable(“name:=TestTable,"index:=0").ChildItem(introw,intcol,strobjType,0)
If (strobjType = "Link" or strobjType ="WebEdit") Then
ChldItm.Click
ElseIf(stobjType = "WebCheckBox") Then
ChldItm.Set "ON"
End If

End Function

!**********************************************************!
1.1  Working with WebTable Examples





!**********************************************************!
2.   Working with WebSites

2.1 Once we get the Test Result from QTP. I have to convert into excel file format.



If Browser("Yahoo").Page("Yahoopage").WebButton("Login").Exist Then
DataTable.value("result",3)="Pass"
Browser("Yahoo").Page("Yahoopage").WebButton("Login").click
Else
DataTable.Value("result",3)="Fail"
End If


2.2 How to execute the functions with select statement using the Design time DataTable.


Dim Var
Var = DataTable.Value ("key",dtGlobalSheet)
Select Case Var
Case "la" launch_app()
Case "ln" login()
Case "ca" Close_app()
End Select
2.3. Find the Inbox Unread mails count



2.4. Click the Particular Mail in the Mails List 

!**********************************************************!
3.    Working with Browser Examples:
3.1  Find the Total Browsers on the desktop (IE, MozillaFireFox, ......)


------------------------------------------------------------------------------------------------------------------------
'Write a function to close all opened Browsers on Desktop
Function Close_Browsers()
   Dim oBrowser, Browsers, i
   Set oBrowser=Description.Create
oBrowser("micclass").Value="Browser"
Set Browsers= Desktop.ChildObjects(oBrowser)
Msgbox Browsers.count

For i= 0 to Browsers.count- 1 Step 1
Browsers(i).Close
Next

End Function
------------------------------------------------------------------------------------------------------------------------
Call Close_Browsers()

3.2 Close the Particular Browser on the desktop

3.3 Cross-Browser Testing using QTP



'Write a function to Count links in Google Home Page
Function Count_Links()
   Dim oLink, Links, i
   Set oLink = description.Create
oLink("micclass").Value="Link"
SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE","http://www.dealsdirect.com.au/"
Set Links=Browser("Online Shopping | Australia").Page("Online Shopping | Australia").ChildObjects(oLink)
Msgbox Links.Count
End Function
---------------------------------------------------------------------------------
Call Count_Links()

------------------------------
'Write a function to Launch Dieals direct web Portal
Function App_Launch()
SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE","http://www.dealsdirect.com.au/"

If Browser("Online Shopping | Australia").Exist(10) Then
App_Launch="Application Launched successfully"
Else
App_Launch="Application Not Launched "
End If
Msgbox App_Launch
End Function

Call App_Launch()
-----------------------------------------------------------------------------
'Write a function to Launch Dieals direct web Portal
Function Register(Email)
SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE","http://www.dealsdirect.com.au/"
    Browser("Online Shopping | Australia").Page("Online Shopping | Australia_2").Link("Register").Click
Browser("Online Shopping | Australia").Page("DealsDirect.com.au Secure_2").WebEdit("cEmail2").Set Email 
Browser("Online Shopping | Australia").Page("DealsDirect.com.au Secure_2").WebEdit("cEmail3").Set Email 
Browser("Online Shopping | Australia").Page("DealsDirect.com.au Secure_2").WebEdit("cPass2").SetSecure "4ecda6b8749877a727d3e893c85fbb8b0120"
Browser("Online Shopping | Australia").Page("DealsDirect.com.au Secure_2").Image("image-register-and-continue-bu").Click 209,17

Message = Browser("Online Shopping | Australia").Page("DealsDirect.com.au Secure_3").WebElement("Welcome Back").GetROProperty("innertext")

If  Message ="Welcome Back "  Then
Register="Registration Successful"
Else
    Register="Registration failed"
End If
Msgbox Register
End Function
------------------------------------------------------------------------
Call Register ("hydhyda25677@gmail.com")
--------------------------------------------------------------------------
Function Login(Email, Password)
SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE","","C:\Documents and Settings\Administrator","open"
Browser("Browser").Page("Page").Sync
Browser("Browser").Navigate "http://www.dealsdirect.com.au/"
Browser("Browser").Page("Online Shopping | Australia").Link("Login").Click
Browser("Browser").Page("DealsDirect.com.au Secure").WebEdit("cEmail1").Set Email 
Browser("Browser").Page("DealsDirect.com.au Secure").WebEdit("cPass1").Set Password
Browser("Browser").Page("DealsDirect.com.au Secure").Image("image-login-and-continue-butto").Click 152,13

If Browser("Browser").Page("DealsDirect.com.au Secure_2").Link("Logout").Exist(10) Then 
Login="Login Sucessful"
Else
Login="Login Failed"
End If
Msgbox Login
End Function
Call Login("hydhyda25677@gmail.com","asdf12")




Get TooTip text from Java Table
JavaWindow(“abc”).JavaTable(“xyz”).Object.setColumnSelectionAllowed=False

JavaWindow(“abc”).JavaTable(“xyz”).Object.setRowSelectionAllowed=False

JavaWindow(“abc”).JavaTable(“xyz”).ClickCell”#1?,”#0?

set obj=JavaWindow(“abc”).JavaTable(“xyz”).Object.getCellRect(1,0,True)

JavaWindow(“abc”).JavaTable(“xyz”).FireEvent micMouseMove,0, “BUTTON1_MASK”, obj.x, obj.y, 1, “OFF”

msgbox JavaWindow(“abc”).JavaObject(“toolkit class:=javax\.swing\.JToolTip
“).Object.tipText
---------------------------------------
Close Opened Browsers Except QC
Dim intIndex
Set oDesc=Description.Create
oDesc(“micclass”).Value=”Browser”
intIndex=0
While Browser(“micclass:=Browser”,”index:=”&intIndex).exist(0) and intIndex<Desktop.ChildObjects(oDesc).count
If instr(1, Browser("micclass:=Browser","index:="&intIndex).getRoProperty("name"),"Quality Center") = 0 Then
SystemUtil.CloseProcessByHwnd( Browser("micclass:=Browser","index:="&intIndex).getRoProperty("hwnd"))
else
intIndex=intIndex+1
End if
wend

---------------------------------------

No comments

Post a Comment