QTP Outlook Excel XML



Quick Test Professional does not have special support for the Outlook application, so there is no built-in method that will locate an e-mail and allow you to view the attachments.

However, Microsoft does have an Object Model for Outlook that can be used to automate many of the features.

You can refer to "Microsoft Outlook 2000 Object Model" for a complete listing of Outlook methods and properties that can be used within a Quick Test Professional (QTP) script.

How to open outlook from QTP
Set myOlApp = CreateObject("Outlook.Application")
‘to create an object
Set myNameSpace = myOlApp.GetNameSpace("QAT")
‘to create an name space
Set myFolder= myNameSpace.GetDefaultFolder(6)
‘to open inbox (inbox is the sixth folder)
myFolder.Display

How to show/display the total mails in inbox via QTP using Outlook methods?

Items.count - To display the total mails in the Inbox

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("QAT")
Set myFolder= _
myNameSpace.GetDefaultFolder(6)
myFolder.Display
msgbox myfolder.items.count

How to send emails using QTP?
Set myOlApp = CreateObject("Outlook.Application")
‘ to create object for outlook
Set mail = myOlApp.CreateItem(0)
‘to click on the new message
mail.to = "admin@qatutorial.com“
‘to edit the mail id
mail.body = "Hi user, Welcome to QAT“
‘to edit the subject
mail.display
‘to display the outlook
mail.send
‘to send the mail

Displaying how many unread mails are there in QTP.
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("QAT")
Set myFolder= myNameSpace.GetDefaultFolder(6)
myFolder.Display
msgbox myFolder.UnReadItemCount
‘for displaying how many items are unread till now


QTP - Working with Excel

  • Opening workbook.
  • Opening worksheets.
  • Reading data from Excel sheet.
  • Writing data to Excel sheet.
  • Saving data to Excel sheet.

    Opening workbook from QTP
    Set xl = CreateObject("Excel.Application")
    ‘to create object for the excel object
    xl.workbooks.open "c:\qatutorial_template.xls“
    ‘to open file

    Opening worksheets from QTP
    Set xl = CreateObject("Excel.Application")
    xl.workbooks.open "c:\qatutorial_template.xls“
    xl.sheets("sheet1").activate

    Reading data from Excel from QTP
    Set xl = CreateObject("Excel.Application")
    xl.workbooks.open "c:\qatutorial_template.xls“
    xl.sheets("sheet1").activate
    msgbox xl.sheets("sheet1").cells(2,2)
    xl.quit

    Writing data to Excel from QTP
    Set xl = CreateObject("Excel.Application")
    xl.workbooks.open "c:\qatutorial_template.xls“
    xl.sheets("sheet1").activate
    xl.sheets("sheet1").cells(2,2) = "mercury123"

    Saving excel file from QTP
    Set xl = CreateObject("Excel.Application")
    xl.workbooks.open "c:\qatutorial_template.xls“
    xl.sheets("sheet1").activate
    xl.sheets("sheet1").cells(2,2) = "mercury123“
    xl.Save
    xl.quit


    Working with XML object from QTP
    Quick Test Professional provides several scripting methods that we can use with XML data. We can use these scripting methods to retrieve data and return new XML objects from existing XML data.

    XMLUtil in QTP
    The object used to access and return XML objects.

    Syntax
    Set Object = XMLUtil.CreateXML()

    Loading XML file from QTP
    Set XMLObj = XMLUtil.CreateXML()

    XMLObj.LoadFile("C:\XML\qatutorial.xml")

    Example
    Code for replacing the value in XML file using XML Object:
    Set doc = XMLUtil.CreateXML()
    doc.LoadFile "C:\qatutorial.xml"
    Set root = doc.GetRootElement()
    Set children = root.ChildElements()
    if children.Count() <> 0 then
    Set firstChild = children.Item(1)
    firstChildName = firstChild.ElementName()
    Set sameNameChildren = children.AllItemsByName(firstChildName)
    msg = "My first child name is " + firstChildName + " and I have " + FormatNumber(sameNameChildren.Count(),0) + " of them."
    End If
    msgbox msg
    set firstChild=root.ChildElements().Item(2)
    Set child2 = firstChild.ChildElements().Item(2)
    Msgbox child2.Value()
    child2.SetValue("replacement")
    firstChild.AddChildElementByName "Value", "replacement"
    Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set MyFile = fso.OpenTextFile("C:\qatutorial.xml")
    MsgBox MyFile.ReadAll
    MyFile.Close

  • style="display:block"
    data-ad-client="ca-pub-9945402454384428"
    data-ad-slot="3540880857"
    data-ad-format="autorelaxed">