【问题标题】:QTP: Get list of all links in an E-mailQTP:获取电子邮件中所有链接的列表
【发布时间】:2009-02-16 15:22:38
【问题描述】:

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

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

我是开发人员,而不是测试人员。谁能给我一些“代码”来执行这个提取?

【问题讨论】:

    标签: parsing automated-tests qtp extraction


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      如果您最终选择了 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
      

      【讨论】:

        【解决方案3】:
        '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
        

        【讨论】:

        • 欢迎来到 Stack Overflow!而不是只发布一段代码,请解释为什么这段代码解决了所提出的问题。没有解释,这不是答案。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-22
        • 1970-01-01
        • 1970-01-01
        • 2011-05-20
        • 2014-08-02
        • 2016-04-16
        相关资源
        最近更新 更多