我正在“开发”Mercury / HP QuickTest Pro 9.1中的测试计划,我必须在其中提取电子邮件中所有链接的列表,并针对每个链接执行逻辑。
在这种情况下,我使用的是Webmail,因此该消息将显示为网页;虽然我希望稍后使用Outlook来复制更现实的用户体验。
我是开发人员,而不是测试人员。任何人都可以向我提供一些将执行此提取的“代码”吗?
答案 0 :(得分:3)
您可以调用ChildObjects
方法返回给定类型的子对象的集合。例如,要获取Google主页上所有链接对象的列表:
set oDesc = Description.Create()
oDesc("micclass").Value = "Link"
set links = Browser("title:=Google").Page("title:=Google").ChildObjects(oDesc)
For i = 0 To links.Count-1
reporter.ReportEvent micInfo, links(i).GetROProperty("text"), ""
Next
因此,您只需要识别包含电子邮件正文的网页元素,并将其用作搜索的父级。
答案 1 :(得分:1)
如果您最终使用Outlook路由,则可以使用Outlook API执行此操作,而无需使用QTP的GUI代码。
sServer = "your.server.address.here" '"your.server.address.here"
sMailbox = "JoeSmith" '"mailboxName"
' build the ProfileInfo string
sProfileInfo = sServer & vbLf & sMailbox
' create your session and log on
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, True, 0, True, sProfileInfo
' create your Inbox object and get the messages collection
Set oInbox = oSession.Inbox
Set oMessageColl = oInbox.Messages
' get the first message in the collection
Set oMessage = oMessageColl.GetFirst
If oMessage Is Nothing Then
MsgBox "No messages found"
Else
' loop through inbox
Do
With oMessage
' message data:
Debug.Print .Subject & vbCrLf & .TimeReceived & vbCrLf & .Text
' this triggers the clever Outlook security dialog:
'Debug.Print .Sender(1) & vbCrLf & .Recipients(1)
Debug.Print
End With
Set oMessage = oMessageColl.GetNext
Loop Until oMessage Is Nothing
End If
'Logoff your session and cleanup
oSession.Logoff
Set oMessage = Nothing
Set oMessageColl = Nothing
Set oInbox = Nothing
Set oSession = Nothing
答案 2 :(得分:0)
'write qtp script to display names of links in jkcwebsite page
Option explicit
Dim bro,url,n,desc,childs,i
bro="c:\Program Files\Internet Explorer\IEXPLORE.EXE"
url="http://ieg.gov.in/"
invokeapplication bro&" "&url
'create description for link type
Set desc=description.Create
desc ("micclass").value="link"
'get all links in jkc page
Set childs=browser("title:=Jawahar Knowledge Center").Page("title:=Jawahar Knowledge Center").ChildObjects(desc)
For i=0 to childs.count-1 step 1
n=childs(i).getroproperty("name")
print n
Next
n=childs.count
browser("title:=Jawahar Knowledge Center").Close