Tuesday, 25 December 2018

Basic FrameWork:Basic FSO


Function Cleanup()
Systemutil.CloseDescendentProcesses
Systemutil.CloseProcessByName("chrome.exe")

End Function


Function CreateFolder(strFolderName)
    Set ObjFSO=CreateObject("Scripting.FileSystemObject")
If Not ObjFSO.FolderExists(strFolderName)  Then

ObjFSO.CreateFolder(strFolderName)


End If
Set ObjFSO=Nothing

End Function

'Function OpenFileForWriting(strFilename)
'    Set ObjFSO=CreateObject("Scripting.FileSystemObject")
'     ObjFSO.Op
'
'
' End If
'Set ObjFSO=Nothing
'
'End Function
'




Function GetExecutionTime(StartTime,EndTime)
'@ Description : This will get the execution time
' This function is called by Class_Terminate

'Seperate hours, minutes and seconds
StartHour = Hour(StartTime)
StartMin = Minute(StartTime)
StartSec = Second(StartTime)
EndHour = Hour(EndTime)
EndMin = Minute(EndTime)
EndSec = Second(EndTime)

'Convert all in to seconds
StartingSeconds = (StartSec + (StartMin * 60) + (StartHour * 3600))
EndingSeconds = (EndSec + (EndMin * 60) + (EndHour * 3600))

'Use subtraction to know the execution time
GetExecutionTime = EndingSeconds - StartingSeconds
End Function





Function CreateFile(strFileName)
    Set ObjFSO=CreateObject("Scripting.FileSystemObject")
If Not ObjFSO.fileExists(strFileName)  Then

ObjFSO.CreateTextFile(strFileName)
Set ObjFSO=Nothing

End If

End  Function

Function ReportEvent(EventType,EventDescription)

If EventType="PASS" Then



End If

If EventType="FAIL" Then


End If


If EventType="DONE" Then


End If

End Function

Basic FrameWork: Action Driver

On Error Resume Next
'SerialNumber=0

Function CheckExecutionFlag()
strExFlag=Ucase(datatable.Value("EXECUTE"))
If ucase(strExFlag)="X" Then
CheckExecutionFlag=Datatable.GetCurrentRow
End If
End Function

CurrentRow=CheckExecutionFlag()
datatable.SetCurrentRow(CurrentRow)
TotalRows=Datatable.GetRowCount

'Function TakeSnap(IterationFolder)
'
'SerialNumber=SerialNumber+1
'Filename=IterationFolder&"\"&SerialNumber&"."&"png"
'desktop.CaptureBitmap Filename,False
'
'End  Function
'
IterationFolder=objectname.LocalResultsParent&"\"&CurrentRow&" Iteration"
CreateFolder(IterationFolder)

'CurrentRow=CheckExecutionFlag()
IterationFile=IterationFolder&"\"&CurrentRow&"."&"html"
objectname.IterationFile=IterationFile
CreateFile(IterationFile)
objectname.WriteHeader IterationFile
objectname.IterationFolder=IterationFolder

If not isNumeric(CurrentRow) Then


Else
Systemutil.Run "Chrome.exe","https://opensource-demo.orangehrmlive.com"
'objectname.WriteReport "0","Launched Browser"

objectname.ReportEvent1 "0","Launched Browser","Launched Browser"

'Browser("Rediff.com: Online Shopping,").FullScreen
'TakeSnap IterationFolder
'Browser("Rediff.com: Online Shopping,").Page("Rediff.com: Online Shopping,").Link("Sign in").ClickNew
'objectname.WriteReport "Pass","Signin Page"
'
'TakeSnap IterationFolder
'Browser("Rediff.com: Online Shopping,").Page("Rediffmail").WebEdit("login").SetNew "W_USERNAME"
'Browser("Rediff.com: Online Shopping,").Page("Rediffmail").WebEdit("passwd").Set "W_PASSWORD"
'objectname.WriteReport "Pass","Signin page shwon"
'TakeSnap IterationFolder

'Cleanup()



'End If
'Browser("Rediff.com: Online Shopping,").Page("Rediffmail").WebButton("Go").Click




'Next



'Set ObjFSO=CreateObject("Scripting.FileSystemObject")
 
'Function OpenFileForWriting(strFilename)
'    Set ObjFSO=CreateObject("Scripting.FileSystemObject")
'     ObjFSO.
'
'
' End If
'Set ObjFSO=Nothing
'
'End Function

Login()

Function Login()

Browser("Rediff.com: Online Shopping,").Page("OrangeHRM").WebEdit("txtPassword").SetNew "W_PASSWORD"
Browser("Rediff.com: Online Shopping,").Page("OrangeHRM").WebEdit("txtUsername").SetNew "W_USERNAME"
'TakeSnap IterationFolder
Browser("Rediff.com: Online Shopping,").Page("OrangeHRM").WebButton("Login").ClickNew

If Browser("Rediff.com: Online Shopping,").Page("OrangeHRM").Link("Welcome Admin").Exist(60) Then
    Browser("Rediff.com: Online Shopping,").Page("OrangeHRM").Sync
'objectname.WriteReport "Pass","Signin Success"
objectname.ReportEvent1 "0","Login Step","Login Success"

'Launched Browser
' Reportevent
'ReportEvent "PASS","steep","test"
'TakeSnap IterationFolder
Else
   ' objectname.WriteReport "FAIL","Signin FAIL"
  objectname.ReportEvent1 "1","Login Step","Login Failed"
    'TakeSnap IterationFolder

End If
End Function

'msgbox IterationFolder
filename= IterationFolder&"\"&"Data"&"."&"xls"
Datatable.Export cstr(filename)

'msgbox err.Description

Cleanup()
objectname.iIndex=1
objectname.SerialNumber=0

'Browser("Rediff.com: Online Shopping,").ClearCache
'Browser("Rediff.com: Online Shopping,").DeleteCookies
'strWND=Browser("Rediff.com: Online Shopping,").Object.HWND
'Window("hwnd="&strWND).maximize

End  If

'
'strWND=Browser("Rediff.com: Online Shopping,").GetROProperty("hwnd")
'Window("hwnd="&strWND).maximize
'

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






Basic FrameWork Functions: Webmethods Overloading

RegisterUserFunc "Link","ClickNew","ClickNew"
RegisterUserFunc "WebEdit","SetNew","SetNew"
RegisterUserFunc "Webbutton","ClickNew","ClickNew"

Function SetNew(obj,Parameter)
On Error Resume Next
ParameterValue=Datatable.Value(cstr(Parameter))

If Ucase(trim(ParameterValue))="<SKIP>" Then

Else

obj.Set ParameterValue
If Err.Number<>0 Then


objectname.ReportEvent1 "1","Could not write "&ParameterValue,""&err.description
'objectname.ReportEvent1 "0","clicking link","Cliked "&strLogicalName

Else

objectname.ReportEvent1 "2","Entered "&ParameterValue &"in "&obj.GetTOProperty("name"),"enter value"

'objectname.ReportEvent1 "0","Login Step","Login Success"
End If

End If

End Function

Function ClickNew(objlink)
       On Error Resume Next
    objlink.Click
    strLogicalName= objlink.GetTOProperty("name")
If err.number<>0 Then

' msgbox Err.Description&""

objectname.ReportEvent1 "1","clicking link",""&err.Description

Else
objectname.ReportEvent1 "0","clicking link","Cliked "&strLogicalName

End If



End Function



Spring Boot : Exception Handler 14