Tuesday, March 2, 2010

QTP - Schedule framework or test using AOM script.

QTP - Schedule framework or test using AOM script.

Good framework need to run the test automatically and send the results through email to all the stake holders.

Below AOM script perform following actions.
1. Find the place of execution using system IP, so that people can understand where exactly test got executed. If your test is executing from different locations, implementing this feature is a good option.
2. Empty few folders before starting the test, as per my dual function framework requirement.
2. Open the QTP with the corresponding test and pass the framework parameters as environment variables.
3. Once test got completed, copy the test folder to another new folder (folder name created using current time stamp), so that results are preserved from being overwritten by the next scheduled test.

Note: Script need to be customized as per the requirements and integrated with the windows scheduler.

'Folders path
sParentFolder = "C:\Automation FrameWork\AutomationTestDocuments\ProductionLoginTesting"
sControlFilePath = "AutomationTestDocuments\ProductionLoginTesting\ProductionLoginTestingControlFile.xls"

'******************************* Don't Edit the code beyond this line *******


sToCopyFolder = "C:\Automation FrameWork\ExecutedScripts\"

'Find system IP address

strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > ''"

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )

For Each objItem In colItems
    If IsArray( objItem.IPAddress ) Then
        If UBound( objItem.IPAddress ) = 0 Then
            strIP = objItem.IPAddress(0)
        Else
            strIP = Join( objItem.IPAddress, "," )
        End If
    End If
Next

Set objWMIService = Nothing
Set colItems      = Nothing


'Compare the IP address with the known location IP address 
Select Case strIP
        Case "xxx.22.0.xxxx" : sPlace  = "HYD" ' QTP HYD System IP Address
        Case "xxxx.168.1.xxx" : sPlace = "NJ"  ' QTP  NJ system
'        Case "xx.xxx.xx.xxx" : sPlace = "MUM"

        Case Else : sPlace = "IP_" & strIP
End Select


' Delete all the files from the folders
set oFso =createObject("scripting.filesystemobject")
folder = sParentFolder & "\ExecutionLog\*.*"
On Error Resume Next
oFso.DeleteFile(folder)
On Error Goto 0
set oFso = Nothing

set oFso=createObject("scripting.filesystemobject")
folder = sParentFolder &  "\ScreenShots\*.*"
On Error Resume Next
oFso.DeleteFile(folder)
On Error Goto 0
set oFso = Nothing


'Call AOM script to activate QTP and run test by passing environment variables as parameters
Dim qtApp
Set qtApp = CreateObject("QuickTest.Application")
If qtApp.Launched Then ' If QuickTest is  open
  qtApp.Quit 
End If
qtApp.Launch
qtApp.Open "C:\Automation FrameWork\Frame_Work GeP"
qtApp.Visible = True
qtApp.WindowState = "Maximized"
qtApp.Test.Environment.Value("envsDataFileSelect") = sControlFilePath
qtApp.Test.Environment.Value("envsPlace") = sPlace
qtApp.Test.Run
qtApp.Test.Close
qtApp.Quit 
Set qtApp = nothing
Set qtResultsObj = nothing


sDateTIme = Now()

iDate = Datepart("d",sDateTime)
iLen = Len(iDate)
If iLen = 1 Then
        iDate = "0" & iDate
End If

sMonth=  mid(MonthName(Datepart("m",sDateTime)),1,3)

iYear = Datepart("yyyy",sDateTime)

iHour = Datepart("h",sDateTime)
iLen = Len(iHour)
If iLen = 1 Then
        iHour = "0" & iHour
End If

iMinute = Datepart("n",sDateTime)
iLen = Len(iMinute)
If iLen = 1 Then
        iMinute = "0" & iMinute
End If

iSec = Datepart("s",sDateTime)
iLen = Len(iSec)
If iLen = 1 Then
        iSec = "0" & iSec
End If


'sFileName =  iDate & "_" & sMonth & "_" & iYear & "_" & iHour & "_" & iMinute & "_" & iSec & "_" & sPlace
sFileName =  sMonth & "_" & iDate & "_" & iYear & "_" & iHour & "_" & iMinute & "_" & iSec & "_" & sPlace
sNewFolder = sToCopyFolder & sFileName

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(sNewFolder )
Set objFolder = Nothing
Set objFSO = Nothing 

Execute "Const  FOF_CREATEPROGRESSDLG = &H0&"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(sNewFolder) 
objFolder.CopyHere sParentFolder , FOF_CREATEPROGRESSDLG
Set objFolder = Nothing
Set objShell = Nothing


sRenameFolderPath = sNewFolder & "\ProductionLoginTesting"
sRenameFolderPathTestCase = sNewFolder & "\ProductionLoginTesting\AutomationTestCases"

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
abc="ASSOCIATORS OF {Win32_Directory.Name='" & sRenameFolderPath & "'} Where  ResultClass = CIM_DataFile"
Set colFiles = objWMIService.ExecQuery  (abc)
For Each objFile In colFiles
    strEnd = Right(objFile.Name, 4)
    If Ucase(strEnd) = ".XLS" then
    iLen = Len(objFile.Name)
    'MsgBox iLen
    sFolderPath = mid(objFile.Name,1,ilen-4)
    'Msgbox sFolderPath 
    strNewName = sFolderPath & sFileName & ".xls"
        'MsgBox strNewName 
        errResult = objFile.Rename(strNewName)

    End If
Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
abc="ASSOCIATORS OF {Win32_Directory.Name='" & sRenameFolderPathTestCase & "'} Where  ResultClass = CIM_DataFile"
Set colFiles = objWMIService.ExecQuery  (abc)
For Each objFile In colFiles
    strEnd = Right(objFile.Name, 4)
    If Ucase(strEnd) = ".XLS" then
    iLen = Len(objFile.Name)
    'MsgBox iLen
    sFolderPath = mid(objFile.Name,1,ilen-4)
    'Msgbox sFolderPath 
    strNewName = sFolderPath & sFileName & ".xls"
        'MsgBox strNewName 
        errResult = objFile.Rename(strNewName)

    End If
Next

Set objWMIService = Nothing





---

No comments:

Post a Comment