Saturday, December 29, 2012

How to schedule a batch execution

In this video, i covered following concepts:

How to execute batch of QTP Tests.
How to capture QTP Execution status.
How to send the execution status as a Outlook Mail.


Following is the AOM script for the above functionality:

Set qtpApp = CreateObject("QuickTest.Application")
Set fsObj = CreateObject("Scripting.FileSystemObject")
Set qtpResObj = CreateObject("QuickTest.RunResultsOptions")

sFolderPath="E:\Batch Tests"

qtpApp.Launch
qtpApp.Visible = True


Set mainFolderObj = fsObj.GetFolder(sFolderPath)
Set testSubFolders = mainFolderObj.SubFolders

sPath="E:\"&formatDate&"\"

For each folderObj in testSubFolders

   chkfolderObj = folderObj.Path & "\Action0"

   If (fsObj.FolderExists(chkfolderObj)) Then ' The folder is a QTP test folder

      qtpApp.Open folderObj.Path, True, False


      sResultFolderPath=sPath&folderObj.Name & "\Res" ' Set the results location

      qtpResObj.ResultsLocation = sResultFolderPath

    
      qtpApp.Test.Run qtpResObj, True

      strResult=qtpApp.Test.LastRunResults.Status

      'WScript.echo strResult

      qtpApp.Test.Close

    End If
Next

'SendMail()

qtpApp.Quit


' Release the File System Objects
Set testSubFolders  = Nothing
Set mainFolderObj = Nothing
Set fsObj = Nothing                                          
set qtpResObj=nothing
set qtpApp=nothing

Function formatDate()
    str=now()
    str=replace(str,"/","")
    str=replace(str,":","")
    str=replace(str," ","")
    formatDate= mid(str,1,len(str)-2)
End Function

function SendMail()
    Set Outlook = CreateObject("Outlook.Application")
    Set Message = Outlook.CreateItem(olMailItem)
    With Message
        .Subject = "Test results for Date "&sPath
        .HTMLBody = "This is an automated mail for Test Results"
        .Recipients.Add ("udayanem@gmail.com")
        .attachments.add sFilePath
        .Send
    End With

    set Outlook=nothing
end function

2 comments:

  1. Thanks , it helped me a lot to understand AOM concepts , keep posting such a good stuff (y)

    ReplyDelete
  2. Mahesh, thanks for your comments. Please subscribe to my youtube channel or to my blog to get updated content.

    ReplyDelete