Friday, May 9, 2014

Qtp code for Sending email using GMail site

Option explicit
Dim u, p, oex, ows, owb, i, nur, nuc, s

'go to excel file
Set oex=createobject("Excel.Application")
oex.Visible=true
'go to workbook
Set owb=oex.Workbooks.Open("F:\QTP\mytest1.xls")
'go to worksheet
Set ows=owb.Worksheets("Sheet1")
    nur=ows.usedrange.rows.count
nuc=ows.usedrange.columns.count
'associate functions file
Executefile("F:\QTP\gml.vbs")
'launching site
launch
'log in site
u="USER ID"
p="PASSWORD"
login u, p
For i=2 to nur step 1
'click compose
With browser("title:=.*")
With .page("title:=.*")
.link("name:=Compose Mail").click
End With
End With
'Fill fields to send mail
With browser("title:=.*")
With .page("title:=.*")
.webedit("name:=to").Set ows.cells(i,1)
.webedit("name:=cc").Set ows.cells(i,2)
.webedit("name:=bcc").Set ows.cells(i,3)
.webedit("name:=subject").Set ows.cells(i,4)
.webedit("name:=body").Set ows.cells(i,5)
.webbutton("name:=Send","index:=0").Click
End With
End With
'check correctness of mail
With browser("title:=.*")
With .page("title:=.*")
s=.webelement("html tag:=B","x:=655","y:=116").GetROProperty ("innertext")
        End With
End With
If trim(s)="Your message has been sent." Then
ows.cells(i,6)="Test Passed"
ows.cells(i,6).font.colorindex=1
Else
ows.cells(i,6)="Test Failed"
End If
Next
'signout and close browser
sgnf
'save work sheet
ows.rows.autofit
ows.columns.autofit
owb.Save
'close excel
oex.Quit
'destroy objects
Set ows=nothing
Set owb=nothing
Set oex=nothing

No comments:

Post a Comment