Reputation: 8035
I'm "developing" a test plan in Mercury/HP QuickTest Pro 9.1, in which I must extract a list of all links in an E-mail and perform logic against each of them.
In this case, I am using Webmail, so the message will appear as a web page; though I hope to use Outlook later to replicate a more realistic UX.
I am a Developer, not a Tester. Can anyone provide me with some "code" that will perform this extraction?
Upvotes: 1
Views: 6507
Reputation: 1
'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
Upvotes: 0
Reputation: 2482
If you end up going the Outlook route, you can use the Outlook API to do it, without having to use QTP's GUI code.
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
Upvotes: 1
Reputation: 2872
You can call the ChildObjects
method to return a collection of child objects of a given type. For example, to get a list of all the Link objects on the Google home page:
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
So you just need to identify the web element that contains the body of the email and use that as the parent for the search.
Upvotes: 3