views:

1168

answers:

2

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?

+3  A: 

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.

Sam Warwick
+1  A: 

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
Tom E