我正在“开发”Mercury/HP QuickTest Pro 9.1中的测试计划,其中我必须提取电子邮件中所有链接的列表并执行逻辑对他们每个人。QTP:获取电子邮件中所有链接的列表
在这种情况下,我使用Webmail,因此该消息将显示为网页;尽管我希望稍后可以使用Outlook来复制更实际的用户体验。
我是开发人员,而不是测试人员。任何人都可以提供我一些“代码”,将执行此提取?
我正在“开发”Mercury/HP QuickTest Pro 9.1中的测试计划,其中我必须提取电子邮件中所有链接的列表并执行逻辑对他们每个人。QTP:获取电子邮件中所有链接的列表
在这种情况下,我使用Webmail,因此该消息将显示为网页;尽管我希望稍后可以使用Outlook来复制更实际的用户体验。
我是开发人员,而不是测试人员。任何人都可以提供我一些“代码”,将执行此提取?
您可以调用ChildObjects
方法来返回给定类型的子对象的集合。例如,要获得谷歌主页上的所有链接对象的列表:
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
'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
欢迎堆栈溢出!请不要仅发布一段代码,请解释为什么此代码可解决问题。没有解释,这不是一个答案。 – Artemix 2012-11-22 11:24:56