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 =
Environment.Value("EnvrnName")
strServerName =
Environment.Value("ServerName")
strUrl =
Environment.Value("Url")
If strEnvrnName =
"" Then
msgbox "Please valid DB Environment Name"
ExitTest
End If
'__________________________________________________________________________________________________________________
'get login details
Call
LoginInfo()
strComputerName =
Environment.Value("envComputerName")
strUserName =
Environment.Value("envUserName")
strUserDomain =
Environment.Value("envUserDomain")
'___________________________________________________________________________________________________________________
Set
objBrwsr=Description.Create
objBrwsr("micclass").value="Browser"
objBrwsr("name").value=".*"
Set
objLink=Description.Create
objLink("html
tag").value="A"
objLink("micclass").value="Link"
SystemUtil.Run
"iexplore.exe",strUrl & "/home-finance/"
Wait(10)
strOutputFilePath =
"C:\Move\Retail\TestData\Output\Global\Retail Test Log.xls"
Set objBCount =
Desktop.ChildObjects(objBrwsr)
intBCount =
objBCount.Count-1
If
Browser("creationtime:=" &
intBCount).Link("name:=Insurance","index:=0").Exist = False
Then
Reporter.ReportEvent micFail,"HF_Insurance","Link is not
available"
ExitTest
End If
'___________________________________________________________________________________________________________________
'clearing variables
strBreadCrumb="":strMainLink="":strChildLink="":strActualUrl="":strTargetUrl="":strStatus=""
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"
LogFile()
End
If
'___________________________________________________________________________________________________________________
Set ObjWE=Description.Create
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
objBrowser1(intCount1).Click
'if it opens in new browser
If strTarget = "_blank" Then
Set objBCount1 = Desktop.ChildObjects(objBrwsr)
intBCount1 = objBCount1.Count - 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
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=Description.Create
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
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 = Desktop.ChildObjects(objBrwsr)
intBCount1 = objBCount1.Count - 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
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=Description.Create
ObjWE2("class").value="hf_Insurance_Outerwraper"
ObjWE2("index").value=2
ObjWE2("html
tag").value="DIV"
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 = Desktop.ChildObjects(objBrwsr)
intBCount1 = objBCount1.Count - 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
End If
'verify the link
If Instr(strActualUrl,strTargetUrl) <= 0 Then
intfailCount = intfailCount +1
strStatus = "Fail"
LogFile()
End If
End If
Next
End If
'___________________________________________________________________________________________________________________
'Close the Browsers
and advertisement windows
Set objBCount2 =
Desktop.ChildObjects(objBrwsr)
intBCount2 =
objBCount2.Count - 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
'___________________________________________________________________________________________________________________
''SubRoutine to
CreateLogFile
Sub LogFile
Set objExcel=CreateObject("Excel.Application")
objExcel.visible=False
objExcel.workbooks.open(strOutputFilePath)
r=1
Do Until len(objExcel.cells(r,1))=0
r=r+1
objExcel.cells(r,1).value=strBreadCrumb
objExcel.cells(r,2).value=strMainLink
objExcel.cells(r,3).value=strChildLink
objExcel.cells(r,4).value=strActualUrl
objExcel.cells(r,5).value=strTargetUrl
objExcel.cells(r,6).value=Date
objExcel.cells(r,7).value= Time
objExcel.cells(r,8).value=strEnvrnName
objExcel.cells(r,9).value=strServerName
objExcel.cells(r,10).value=strComputerName
objExcel.cells(r,11).value=strUserName
objExcel.cells(r,12).value=strUserDomain
objExcel.cells(r,13).value=strStatus
objExcel.DisplayAlerts = False
objExcel.Save
objExcel.Quit
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("CDO.Configuration")
cdoSendUsingPort=2
sMailServerName="smtp.phx.move.com"
cdoAnonymous=cdoNONE
objConf.fields.item("http://schemas.microsoft.com/cdo/configuration/sendusing")
= cdoSendUsingPort
objConf.fields.item("http://schemas.microsoft.com/cdo/configuration/smtpserver")
= sMailServerName
objConf.fields.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")
= cdoAnonymous 'cdoBasic
objConf.fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")
= False
objConf.fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= 25
'objConf.fields.item("http://schemas.microsoft.com/cdo/configuration/sendusername")
= "corp\GEdamadaka"
'objConf.fields.item("http://schemas.microsoft.com/cdo/configuration/sendpassword")
= "$lgs0112"
objConf.fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")
= 60
objConf.fields.Update
Set objMsg = CreateObject("CDO.Message")
objMsg.Configuration = objConf
objMsg.to = "nageswara.raoJ@move.com"
objMsg.From = "nageswara.raoJ@move.com"
objMsg.Subject = "~2 Step_Geo_Mileage Pattern Search"
objMsg.TextBody =msgSub
objMsg.AddAttachment(doc)
objMsg.Send
Set objMsg = Nothing
NewMail = True
End Sub
####################################################
No comments:
Post a Comment