For QTP Scripts & Documents Visit: [Link].
com
QTP Web Script Examples
'On error resume next
Dim strMainLink, strChildLink, strActualUrl, strTargetUrl
Dim intBCount, objBCount
'___________________________________________________________________
_______________________________________________
'Clear the Cookies
Call ClearCookies
'___________________________________________________________________
_______________________________________________
'select Environment and get related info from spread sheet
Dim strEnvrnName
Dim strServerName
Dim strUrl
ipEnvrnName = "prod" 'InputBox ("Please enter DB Environment (ex:
qap/beta/prod)","Database Environment","prod")
ipEnvrnName = lcase(trim(ipEnvrnName))
If ipEnvrnName = "" Then
msgbox "Enter DB Environment Name"
ExitTest
End If
Call DBEnvrnListFile(ipEnvrnName)
strEnvrnName = [Link]("EnvrnName")
strServerName = [Link]("ServerName")
strUrl = [Link]("Url")
If strEnvrnName = "" Then
For Software Testing Documents visit: [Link] 1
For QTP Scripts & Documents Visit: [Link]
msgbox "Please valid DB Environment Name"
ExitTest
End If
'___________________________________________________________________
_______________________________________________
'get login details
Call LoginInfo()
strComputerName = [Link]("envComputerName")
strUserName = [Link]("envUserName")
strUserDomain = [Link]("envUserDomain")
'___________________________________________________________________
________________________________________________
Set objBrwsr=[Link]
objBrwsr("micclass").value="Browser"
objBrwsr("name").value=".*"
Set objLink=[Link]
objLink("html tag").value="A"
objLink("micclass").value="Link"
[Link] "[Link]",strUrl & "/home-finance/"
Wait(10)
strOutputFilePath = "C:\Move\Retail\TestData\Output\Global\Retail Test [Link]"
Set objBCount = [Link](objBrwsr)
For Software Testing Documents visit: [Link] 2
For QTP Scripts & Documents Visit: [Link]
intBCount = [Link]-1
If Browser("creationtime:=" & intBCount).Link("name:=Insurance","index:=0").Exist
= False Then
[Link] micFail,"HF_Insurance","Link is not available"
ExitTest
End If
'___________________________________________________________________
________________________________________________
'clearing variables
strBreadCrumb="":strMainLink="":strChildLink="":strActualUrl="":strTargetUrl="":st
rStatus=""
intfailCount = 0
'___________________________________________________________________
________________________________________________
strMainLink = Browser("creationtime:=" &
intBCount).Link("name:=Insurance","index:=0").GetROProperty("text")
strChildLink = ""
strActualUrl = Browser("creationtime:=" &
intBCount).Link("name:=Insurance","index:=0").GetROProperty("url")
Browser("creationtime:=" & intBCount).Link("name:=Insurance","index:=0").Click
Wait(5)
strTargetUrl = Browser("creationtime:=" & intBCount).GetROProperty("url")
strBreadCrumb = Browser("creationtime:=" &
intBCount).WebElement("class:=slideBreadcumbLine").GetROProperty("outertext")
'verify the link
If Instr(strActualUrl,strTargetUrl ) <=0 Then
intfailCount = intfailCount +1
strStatus = "Fail"
For Software Testing Documents visit: [Link] 3
For QTP Scripts & Documents Visit: [Link]
LogFile()
End If
'___________________________________________________________________
________________________________________________
Set ObjWE=[Link]
ObjWE("class").value="hf_Insurance_Outerwraper"
ObjWE("index").value=0
ObjWE("html tag").value="DIV"
ObjWE("micclass").value="WebElement"
If Browser("creationtime:=" & intBCount).WebElement(objWE).Exist Then
intLinksCount1 = Browser("creationtime:=" &
intBCount).WebElement(ObjWE).ChildObjects(ObjLink).Count
For intCount1 = 0 to intLinksCount1 -1
'______________________________________________________________
'clearing variables
strBreadCrumb="":strChildLink="":strActualUrl="":strTargetUrl="":strStatus=""
'______________________________________________________________
Set objBrowser1 = Browser("creationtime:=" &
intBCount).WebElement(ObjWE).ChildObjects(ObjLink)
strChildLink = trim(objBrowser1(intCount1).GetROProperty("text"))
strActualUrl = objBrowser1(intCount1).GetROProperty("url")
strTarget = objBrowser1(intCount1).GetROProperty("target")
If mid(strActualUrl,1,10) <> "javascript"
Then
For Software Testing Documents visit: [Link] 4
For QTP Scripts & Documents Visit: [Link]
objBrowser1(intCount1).Click
'if it opens in new browser
If strTarget = "_blank" Then
Set objBCount1 = [Link](objBrwsr)
intBCount1 = [Link] - 1
Set objBCount1 = Nothing
strTargetUrl = Browser("creationtime:=" &
intBCount1).GetROProperty("url")
If Browser("creationtime:=" &
intBCount1).WebElement("class:=slideBreadcumbLine").Exist Then
strBreadCrumb = Browser("creationtime:="
&
intBCount1).WebElement("class:=slideBreadcumbLine").GetROProperty("outertext")
Else
strBreadCrumb = "Not Available"
End If
Browser("creationtime:=" & intBCount1).Close
Else
strTargetUrl = Browser("creationtime:=" &
intBCount).GetROProperty("url")
If Browser("creationtime:=" &
intBCount).WebElement("class:=slideBreadcumbLine").Exist Then
strBreadCrumb = Browser("creationtime:="
& intBCount).WebElement("class:=slideBreadcumbLine").GetROProperty("outertext")
Else
strBreadCrumb = "Not Available"
End If
Browser("creationtime:=" &
intBCount).Back
For Software Testing Documents visit: [Link] 5
For QTP Scripts & Documents Visit: [Link]
End If
'verify the link
If Instr(strActualUrl,strTargetUrl) <= 0 Then
intfailCount = intfailCount +1
strStatus = "Fail"
LogFile()
End If
End If
Next
End If
'___________________________________________________________________
________________________________________________
Set ObjWE1=[Link]
ObjWE1("class").value="hf_Insurance_Outerwraper"
ObjWE1("index").value=1
ObjWE1("html tag").value="DIV"
ObjWE1("micclass").value="WebElement"
If Browser("creationtime:=" & intBCount).WebElement(objWE1).Exist
Then
intLinksCount1 = Browser("creationtime:=" &
intBCount).WebElement(objWE1).ChildObjects(ObjLink).Count
For intCount1 = 0 to intLinksCount1 -1
'______________________________________________________________
'clearing variables
For Software Testing Documents visit: [Link] 6
For QTP Scripts & Documents Visit: [Link]
strBreadCrumb="":strChildLink="":strActualUrl="":strTargetUrl="":strStatus=""
'______________________________________________________________
Set objBrowser1 = Browser("creationtime:=" &
intBCount).WebElement(objWE1).ChildObjects(ObjLink)
strChildLink = trim(objBrowser1(intCount1).GetROProperty("text"))
strActualUrl = objBrowser1(intCount1).GetROProperty("url")
strTarget = objBrowser1(intCount1).GetROProperty("target")
If mid(strActualUrl,1,10) <> "javascript"
Then
objBrowser1(intCount1).Click
'if it opens in new browser
If strTarget = "_blank" Then
Set objBCount1 = [Link](objBrwsr)
intBCount1 = [Link] - 1
Set objBCount1 = Nothing
strTargetUrl = Browser("creationtime:=" &
intBCount1).GetROProperty("url")
If Browser("creationtime:=" &
intBCount1).WebElement("class:=slideBreadcumbLine").Exist Then
strBreadCrumb = Browser("creationtime:="
&
intBCount1).WebElement("class:=slideBreadcumbLine").GetROProperty("outertext")
Else
strBreadCrumb = "Not Available"
End If
Browser("creationtime:=" & intBCount1).Close
Else
For Software Testing Documents visit: [Link] 7
For QTP Scripts & Documents Visit: [Link]
strTargetUrl = Browser("creationtime:=" &
intBCount).GetROProperty("url")
If Browser("creationtime:=" &
intBCount).WebElement("class:=slideBreadcumbLine").Exist Then
strBreadCrumb = Browser("creationtime:="
& intBCount).WebElement("class:=slideBreadcumbLine").GetROProperty("outertext")
Else
strBreadCrumb = "Not Available"
End If
Browser("creationtime:=" &
intBCount).Back
End If
'verify the link
If Instr(strActualUrl,strTargetUrl) <= 0 Then
intfailCount = intfailCount +1
strStatus = "Fail"
LogFile()
End If
End If
Next
End If
'___________________________________________________________________
________________________________________________
Set ObjWE2=[Link]
ObjWE2("class").value="hf_Insurance_Outerwraper"
ObjWE2("index").value=2
ObjWE2("html tag").value="DIV"
For Software Testing Documents visit: [Link] 8
For QTP Scripts & Documents Visit: [Link]
ObjWE2("micclass").value="WebElement"
If Browser("creationtime:=" & intBCount).WebElement(objWE2).Exist
Then
intLinksCount1 = Browser("creationtime:=" &
intBCount).WebElement(objWE2).ChildObjects(ObjLink).Count
For intCount1 = 0 to intLinksCount1 -1
'______________________________________________________________
'clearing variables
strBreadCrumb="":strChildLink="":strActualUrl="":strTargetUrl="":strStatus=""
'______________________________________________________________
Set objBrowser1 = Browser("creationtime:=" &
intBCount).WebElement(objWE2).ChildObjects(ObjLink)
strChildLink = trim(objBrowser1(intCount1).GetROProperty("text"))
strActualUrl = objBrowser1(intCount1).GetROProperty("url")
strTarget = objBrowser1(intCount1).GetROProperty("target")
If mid(strActualUrl,1,10) <> "javascript"
Then
objBrowser1(intCount1).Click
'if it opens in new browser
If strTarget = "_blank" Then
Set objBCount1 = [Link](objBrwsr)
intBCount1 = [Link] - 1
Set objBCount1 = Nothing
strTargetUrl = Browser("creationtime:=" &
intBCount1).GetROProperty("url")
For Software Testing Documents visit: [Link] 9
For QTP Scripts & Documents Visit: [Link]
If Browser("creationtime:=" &
intBCount1).WebElement("class:=slideBreadcumbLine").Exist Then
strBreadCrumb = Browser("creationtime:="
&
intBCount1).WebElement("class:=slideBreadcumbLine").GetROProperty("outertext")
Else
strBreadCrumb = "Not Available"
End If
Browser("creationtime:=" & intBCount1).Close
Else
strTargetUrl = Browser("creationtime:=" &
intBCount).GetROProperty("url")
If Browser("creationtime:=" &
intBCount).WebElement("class:=slideBreadcumbLine").Exist Then
strBreadCrumb = Browser("creationtime:="
& intBCount).WebElement("class:=slideBreadcumbLine").GetROProperty("outertext")
Else
strBreadCrumb = "Not Available"
End If
Browser("creationtime:=" &
intBCount).Back
End If
'verify the link
If Instr(strActualUrl,strTargetUrl) <= 0 Then
intfailCount = intfailCount +1
strStatus = "Fail"
LogFile()
End If
End If
For Software Testing Documents visit: [Link] 10
For QTP Scripts & Documents Visit: [Link]
Next
End If
'___________________________________________________________________
________________________________________________
'Close the Browsers and advertisement windows
Set objBCount2 = [Link](objBrwsr)
intBCount2 = [Link] - 1
For I = intBCount to intBCount2
Browser("creationtime:=" & intBCount).Close
Next
'___________________________________________________________________
________________________________________________
Set objMainLink = Nothing
Set objChildLink = Nothing
Set objBrwsr = Nothing
Set ObjWE = Nothing
Set ObjWE1 = Nothing
Set objBCount = nothing
Set objBCount1 = Nothing
'___________________________________________________________________
________________________________________________
'To send Email when test failed
If intfailCount > 0 Then
SendMail
End If
'___________________________________________________________________
________________________________________________
For Software Testing Documents visit: [Link] 11
For QTP Scripts & Documents Visit: [Link]
''SubRoutine to CreateLogFile
Sub LogFile
Set objExcel=CreateObject("[Link]")
[Link]=False
[Link](strOutputFilePath)
r=1
Do Until len([Link](r,1))=0
r=r+1
Loop
[Link](r,1).value=strBreadCrumb
[Link](r,2).value=strMainLink
[Link](r,3).value=strChildLink
[Link](r,4).value=strActualUrl
[Link](r,5).value=strTargetUrl
[Link](r,6).value=Date
[Link](r,7).value= Time
[Link](r,8).value=strEnvrnName
[Link](r,9).value=strServerName
[Link](r,10).value=strComputerName
[Link](r,11).value=strUserName
[Link](r,12).value=strUserDomain
[Link](r,13).value=strStatus
[Link] = False
[Link]
[Link]
For Software Testing Documents visit: [Link] 12
For QTP Scripts & Documents Visit: [Link]
Set objExcel = Nothing
End Sub
'___________________________________________________________________
________________________________________________
'SubRoutine to Send Mail
Sub SendMail
msgSub = "2 Step_Geo_Mileage Pattern Search:" &vbcrLf &"One or more of
the Test Cases Failed." &vbcrLf &"See attachment for details."
doc=strOutputFilePath
Set objConf = CreateObject("[Link]")
cdoSendUsingPort=2
sMailServerName="[Link]"
cdoAnonymous=cdoNONE
[Link]("[Link] =
cdoSendUsingPort
[Link]("[Link] =
sMailServerName
[Link]("[Link]
te") = cdoAnonymous 'cdoBasic
[Link]("[Link] =
False
[Link]("[Link]
t") = 25
'[Link]("[Link]
") = "corp\GEdamadaka"
For Software Testing Documents visit: [Link] 13
For QTP Scripts & Documents Visit: [Link]
'[Link]("[Link]
) = "$lgs0112"
[Link]("[Link]
ntimeout") = 60
[Link]
Set objMsg = CreateObject("[Link]")
[Link] = objConf
[Link] = "[Link]@[Link]"
[Link] = "[Link]@[Link]"
[Link] = "~2 Step_Geo_Mileage Pattern Search"
[Link] =msgSub
[Link](doc)
[Link]
Set objMsg = Nothing
NewMail = True
End Sub
####################################################
QTP Information:
[Link]
For Manual Testing:
For Software Testing Documents visit: [Link] 14
For QTP Scripts & Documents Visit: [Link]
[Link]
For Software Testing Documents visit: [Link] 15