Wednesday, February 9, 2011

Write Log Report in QTP with the help of Class


' Calling class method.
dim fineName
set objLogger = new Logger fileName = objLogger.createLogFile()
objLogger.getInput "1",Date,"Login","User can Login","Login successfully","Pass"
objLogger.writeLogDetails fileName

' Class defination


Class Logger
           dim slNo
           dim dtTime
           dim functionName
           dim expectedResult
           dim actualResult
           dim status
           dim path

             Function createLogFile()

                            path = inputbox("Enter the log path:")
                            driveName = "d:\" 
                            Fullpath = driveName & path 
                            set fso = CreateObject("Scripting.FileSystemObject")
                            set f1 = fso.CreateTextFile(FullPath, True)

                             If (fso.FileExists(Fullpath)) Then
                                    msgbox Fullpath & " exists."                            
                             Else
                                    msgbox = Fullpath & " doesn't exists."
                             End If                            
                             createLogFile=Fullpath
            End Function

  Function getInput(VslNo,VdtTime,VfunctionName,VexpectedResult,VactualResult,Vstatus)      
                            slNo = Vslno
                            dtTime = VdtTime
                             functionName = VfunctionName 
                             expectedResult = VexpectedResult
                             actualResult = VactualResult
                             status = Vstatus
            End Function 

            Function writeLogDetails(fpath)
                            f1.writeLine = slNo
                            f1.writeLine = dtTime
                            f1.writeLine = functionName
                            f1.writeLine = expectedResult
                            f1.writeLine = actualResult
                            f1.writeLine = status
                           msgbox "write Done"
           End function
End Class

No comments: