Tuesday, 25 December 2018

Basic FrameWork: CLass File

Set objectname = New ClassDemo

Class ClassDemo
Public LocalResults
Public strTestName
Public LocalResultsParent
Public SerialNumber
Public IterationFile
Public iIndex 'fot test step in report

Public IterationFolder

Private Sub Class_Initialize(  )
'Initalization code goes here
iIndex=1
SerialNumber=0
LocalResults="C:\Results\"
strTestName=Environment.Value("TestName")&"_"
LocalResultsParent=LocalResults&strTestName&FormattedTime()
CreateFolder(LocalResultsParent)
Cleanup()

'Systemutil.Run "Chrome.exe","https://opensource-demo.orangehrmlive.com"
'Browser("Rediff.com: Online Shopping,").ClearCache
'Browser("Rediff.com: Online Shopping,").DeleteCookies
'strWND=Browser("Rediff.com: Online Shopping,").GetROProperty("hwnd")
'Window("hwnd="&strWND).maximize
'


'print LocalResultsParent

End Sub

'When Object is Set to Nothing
Private Sub Class_Terminate(  )
'Termination code goes here

'Msgbox "Done"
End Sub

public Function FormattedTime()

FormattedTime=Replace(Replace(now(),"/","-"),":","-")
End Function

Public Function SerialNumbr()


End Function

'End Function


Public Function WriteHeader(IterationFile)

Set objFSO=CreateObject("Scripting.FileSystemObject")
Set ofile=objFSO.OpenTextFile(IterationFile,8)

ofile.WriteLine ("<html><body  bgcolor= white>")
ofile.WriteLine ("<table align=center width=900 border=0><tr><td align=center bgcolor=#3869B5><font color=white><b>"&clsResultName&" Test Results</b></font></td></tr></table>")
ofile.WriteLine ("<br>")
ofile.WriteLine ("<table align=center width=900 border=0>")
ofile.WriteLine ("<table align=center width= 900>")
ofile.WriteLine ("<tr bgcolor=#3869B5>")
ofile.WriteLine ("<td><font color=white><b>S.No</b></font></td>")
ofile.WriteLine ("<td><font color=white><b>Step Name</b></font></td>")
ofile.WriteLine ("<td><font color=white><b>Description</b></font></td>")
ofile.WriteLine ("<td><font color=white><b>Status</b></font></td>")
ofile.WriteLine ("<td><font color=white><b>ScreenShot</b></font></td></tr>")

ofile.Close()
End  Function





Public Function WriteReport (Status,StepDesc)

Set objFSO=CreateObject("Scripting.FileSystemObject")

'msgbox IterationFile

Set ofile=objFSO.OpenTextFile(IterationFile,8)



'ofile.Close()

'Set objFSO=nothing

'ofile.WriteLine ("<html><body  bgcolor= white>")
'ofile.WriteLine ("<table align=center width=900 border=0><tr><td align=center bgcolor=#3869B5><font color=white><b>"&clsResultName&" Test Results</b></font></td></tr></table>")
'ofile.WriteLine ("<br>")
'ofile.WriteLine ("<table align=center width=900 border=0>")
'
'ofile.WriteLine ("<table align=center width= 900>")
' ofile.WriteLine ("<tr bgcolor=#3869B5>")
' ofile.WriteLine ("<td><font color=white><b>S.No</b></font></td>")
' ofile.WriteLine ("<td><font color=white><b>Step Name</b></font></td>")
' ofile.WriteLine ("<td><font color=white><b>Description</b></font></td>")
' ofile.WriteLine ("<td><font color=white><b>Status</b></font></td>")
' ofile.WriteLine ("<td><font color=white><b>ScreenShot</b></font></td></tr>")

ofile.Writeline(cstr(Status)& " "&cstr(StepDesc)&"<br>")

Ofile.Close()


Set objFSO=Nothing

End  Function



Function OpenFileForWriting(strFilename)
    Set ObjFSO=CreateObject("Scripting.FileSystemObject")
Set Ofile=  ObjFSO.OpenTextFile(strFilename,8)
Ofile.Write("test")
Set ObjFSO=Nothing

'End If
Set ObjFSO=Nothing

End Function



Function  ReportEvent1(qEventStatus,sReportStepName,sDetails)

'@ Description : Report result for each statement
' This functions will called when ever there is a statement reporter.reportevent
' This function is called by QTP script/function
'Syntax : Reporter.ReportEvent micFail,"StepName",StepDescription"

'Event status are the QTP constants
'Status string and status color assigned based on the constant value

Set objFSO=CreateObject("Scripting.FileSystemObject")

'msgbox IterationFile

Set ofile=objFSO.OpenTextFile(IterationFile,8)


Select case qEventStatus
case 3
cEventStatus="WARNING"
reportColor="FF9900"
Case 2
cEventStatus="DONE"
reportColor="#000080"
case 1
cEventStatus="FAIL"
reportColor="CC0000"
case 0
cEventStatus="PASS"
reportColor="#000080"
End Select

'Prepare Html code for each statement
HTMLStepStart="<TR bgColor=#e4f0ff>"
HTMLStepIndex="<td align='center' bgcolor='#E4F0FF'><font color="&reportColor&">"&iIndex&"</font></td>"
HTMLStepName="<td bgcolor='#E4F0FF'><font color="&reportColor&">"&sReportStepName&"</font></td>"
HTMLStepDescription="<td bgcolor=#E4F0FF><font color="&reportColor&">"&sDetails&"</font></td>"
HTMLStepStatus="<td bgcolor=#E4F0FF><font color= "&reportColor&">"&cEventStatus&"</font></td>"

' 'Capture Bitmap based on Step Status
' 'If no creation time specified then capture 0th browser screenshot
If ucase(cEventStatus)="FAIL" Then
' eImageFilePath=CreateImageFilePath
               

eImageFilePath= TakeSnap(IterationFolder)
            End If
' If BrowserCreationTimeIndex="" Then
' BrowserCreationTimeIndex=0
' End If
'
' 'If no browser found capture desktop screenshot
' If Browser("creationtime:="&BrowserCreationTimeIndex).Exist then
' Browser("creationtime:="&BrowserCreationTimeIndex).CaptureBitmap eImageFilePath,true
' Else
' Desktop.CaptureBitmap eImageFilePath,true
' BrowserCreationTimeIndex=""
' End If
' End If
'
' 'prepare Image file Html Code
' If eImageFilePath<>"" Then
' HTMLStepScreenPath="<td bgcolor=#E4F0FF><a href='"&eImageFilePath&"' target="""">View Error</a></td>"

HTMLStepScreenPath="<td bgcolor=#E4F0FF><a href='"&eImageFilePath&"' target="""">View Error</a></td>"


' else
' HTMLStepScreenPath="<td bgcolor=#E4F0FF>-</td>"
' End If

'Combine All html step code and write in to html file
HTMLStepEnd="</TR>"
HTMLStep=HTMLStepStart&HTMLStepIndex&HTMLStepName&HTMLStepDescription&HTMLStepStatus&HTMLStepScreenPath&HTMLStepEnd
ofile.WriteLine(HTMLStep)

'Parallelly Send QTP result with the stored qReporter object
' qReporter.ReportEvent qEventStatus,sReportStepName,sDetails

'Increase step index for the use of next statement
iIndex=iIndex+1

'Make eImageFilePath to empty for the use of next error image
eImageFilePath=""


ofile.Close
Set objFSO=Nothing

End Function


public Function TakeSnap(IterationFolder)

SerialNumber=SerialNumber+1
Filename=IterationFolder&"\"&SerialNumber&"."&"png"
desktop.CaptureBitmap Filename,False
TakeSnap=Filename
End  Function
'




End Class






No comments:

Post a Comment

Spring Boot : Exception Handler 14