Parsing QTP:获取电子邮件中所有链接的列表
我正在Mercury/HP QuickTest Pro 9.1中开发一个测试计划,其中我必须提取电子邮件中所有链接的列表,并对每个链接执行逻辑 在本例中,我使用的是Webmail,因此邮件将显示为网页;尽管我希望以后使用Outlook复制更真实的用户体验 我是开发人员,不是测试人员。有人能给我提供一些执行此提取的代码吗?您可以调用ChildObjects方法来返回给定类型的子对象集合。例如,要获取Google主页上所有链接对象的列表:Parsing QTP:获取电子邮件中所有链接的列表,parsing,automated-tests,qtp,extraction,Parsing,Automated Tests,Qtp,Extraction,我正在Mercury/HP QuickTest Pro 9.1中开发一个测试计划,其中我必须提取电子邮件中所有链接的列表,并对每个链接执行逻辑 在本例中,我使用的是Webmail,因此邮件将显示为网页;尽管我希望以后使用Outlook复制更真实的用户体验 我是开发人员,不是测试人员。有人能给我提供一些执行此提取的代码吗?您可以调用ChildObjects方法来返回给定类型的子对象集合。例如,要获取Google主页上所有链接对象的列表: set oDesc = Description.Create
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
因此,您只需识别包含电子邮件正文的web元素,并将其用作搜索的父元素。您可以调用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
因此,您只需识别包含电子邮件正文的web元素,并将其用作搜索的父元素。如果您最终选择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
如果您最终选择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
欢迎来到堆栈溢出!与其只发布一段代码,不如解释一下为什么这段代码可以解决这个问题。没有解释,这不是答案。欢迎使用堆栈溢出!与其只发布一段代码,不如解释一下为什么这段代码可以解决这个问题。没有解释,这不是答案。