1

我正在 Mercury/HP QuickTest Pro 9.1 中“开发”一个测试计划,我必须在其中提取电子邮件中所有链接的列表并对每个链接执行逻辑。

在这种情况下,我使用的是 Webmail,因此邮件将显示为网页;虽然我希望以后使用 Outlook 来复制更真实的 UX。

我是开发人员,而不是测试人员。任何人都可以为我提供一些将执行此提取的“代码”吗?

4

3 回答 3

3

您可以调用该ChildObjects方法以返回给定类型的子对象的集合。例如,要获取 Google 主页上所有 Link 对象的列表:

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 元素并将其用作搜索的父元素。

于 2009-02-17T02:27:59.040 回答
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
于 2009-02-17T16:04:36.300 回答
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
于 2011-05-12T07:54:26.763 回答