Monday, 14 March 2016

Creates and save the newly created word doc,Save the Word Doc (FSO Object file path) and Takes the Screenshot of Application

'*******************************************Function*********************************
'Author:-              Vishweshwar Reddy
'Function Name:-        fn_CreateWordDoc
'Function Description:- Creates and save the newly created word doc
'Input Parameters:-     Reporting folder Path
'Output Parameters:-    None
''***********************************************************************************
Dim objWordDoc
Public Function fn_CreateWordDoc(sReportingPath)
'Dim sReportingPath
'Creating the Microsoft Word object to capture ScreenShot
Set objWordDoc = Createobject("Word.Application")
'Making it visible for Testing purposes only
objWordDoc.visible = true
'Adding a new Blank document
objWordDoc.Documents.Add
'Selection method represents the current selected doc
Set objSelection = objWordDoc.Selection
'Saving the word doc file inside Screenshot folder
' msgbox sReportingPath
objWordDoc.ActiveDocument.SaveAs sReportingPath&Environment("TestName")&"_"&_
        Right("0" & Day(Date), 2) & Right("0" & Month(Date), 2) & Year(Date) & "_" & _
Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
End Function

'*******************************************Function*********************************
'Author:-              Vishweshwar Reddy
'Function Name:-        fn_SaveWordDoc
'Function Description:- Save the Word Doc
'Input Parameters:-     None
'Output Parameters:-    None
''***********************************************************************************
Public Function fn_SaveWordDoc
objWordDoc.ActiveDocument.Save
objWordDoc.ActiveDocument.Close
objWordDoc.Quit
'Destroying the word object
Set objWordDoc = Nothing
Set objSelection = Nothing
End Function

'*******************************************Function*********************************
'Author:-              Vishweshwar Reddy
'Function Name:-        fn_TakeScreenShot
'Function Description:- Takes the Screenshot of Application
'Input Parameters:-     Failure Step
'Output Parameters:-    None
''***********************************************************************************
Public Function fn_TakeScreenShot(sReportStep)
'Creating the Screenshot Name
Dim sScreenshotName
sScreenshotName = Environment("ActionName")&"_"& Right("0" & Day(Date), 2) & Right("0" & Month(Date), 2) & Year(Date) & "_" & _
Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
'Taking the Screenshot and saving as .png in temporary location
Desktop.CaptureBitmap sReportingPath & "\" & sScreenshotName & ".png", True
'TypeParagraph method to Inserts a new, blank paragraph.(Enter Key)
objWordDoc.Selection.TypeParagraph
'Inserting BOLD Text before the screenshot
objSelection.Font.Bold = True
objSelection.TypeText "Step Name:"&sReportStep
objSelection.Font.Bold = False
'Adding screenshot to the document
objSelection.InlineShapes.AddPicture sReportingPath & "\" & sScreenshotName & ".png"
'Deleting the temporarly saved screenshot .png file using objFSO object
objFSO.DeleteFile sReportingPath & "\" & sScreenshotName & ".png"
fn_TakeScreenShot = fn_TakeScreenShot
End Function
'*******************************************Function*********************************
'Function Name:-        fn_filesystemObject
'Function Description:- Creating FSO object to work with files
'Input Parameters:-     FSO Object file path
'Output Parameters:-    None
''***********************************************************************************
'Creating FSO object to work with files

Dim Ofilelocation,sReportingPath1

Ofilelocation =Environment("ActionName") & Day(now) & Month(now) & year(now)& hour(now)& Minute(now) & second(now)
sReportingPath1 = Trim("D:Automation" & Ofilelocation)
'msgbox sReportingPath
Function fn_filesystemObject(sReportingPath1)
Dim objFSO,PFSO,SubFSO
Set objFSO = createobject("Scripting.FileSystemObject")
Set PFSO=objFSO.CreateFolder(sReportingPath1)
' Set SubFSO=PFSO.CreateFolder(ScreenShots)
' Set SubFSO=objFSO.CreateFolder(sReportingPath)
' sReportingPath = sReportingPath & ScreenShots
' fn_filesystemObject=PFSO.path
Set SubFSO=PFSO.SubFolders.Add("ScreenShots")
fn_filesystemObject=SubFSO.path
' sReportingPath = PFSO.Path
' msgbox sReportingPath
End Function

No comments:

Post a Comment