自动化报告,把我们定义好,输出到XLS。实现自动化执行完成后,自己还地去复制数据都自定义的报告上....目前还没有全部实现;
第一部份:
要点1:借用网上的 ReporterManager,完成他自已本身的东西;要注意的是,每次启动QTP都必需要重新加载一次VBS(也是Demo.vbs \ Class Templates.vbs \ Engines.vbs \ Filters.vbs \ ReporterManager.vbs,不然会提示VBS中的语句错误)
要点2:读取外部XLS数据实现QTP数据输入
要点3:通本信息输出,把运行QTP本机硬件信息输出
'******************************************************************
'脚本名称:系统信息&外部数据输入
'作用:通用获取运行信息
'前提:设置好系统信息的环境变量:file->setting->Environment
'影响功能点:无
'作者:vikesgao
'编写日期:2011-12-08
'修改日期: 修改原因:
'******************************************************************
'''获取系统信息
OS=Environment.Value("OS")
OSVersion=Environment.Value("OSVersion")
TestName=Environment.Value("TestName")
IEversion=Environment.Value("IEversion")
Reporter.ReportEvent micDone , "Environment" ,"运行测试脚本:" &TestName & "的操作系统为:" & OS & "版本为:" & OSVersion & "浏览器为:" & IEversion
''获取系统日志信息---start perf_log 放在脚本最上层 stop perf_lof放到脚本最下层
'systemutil.Run "logman","start perf_log"
'systemutil.Run "logman","stop perf_log"
'获得数据文件路径,并将数据文件导入到DataTable运行表中
'DataTable.AddSheet("TestData") QTP中建立一个Test Data的数据表
'DataTable.ImportSheet DataStr,"Sheet1","TestData" sheet1 的数据转换到QTP 数据表Test Data
DataStr= "d:\data.xls"
DataTable.AddSheet("TestData")
DataTable.ImportSheet DataStr,"Sheet1","TestData"
wait 1
'输入用户名和密码------------------
'UserName=DataTable.Value("UserName","TestData")
'注意:Value("UserName","TestData")里面的username大小,大小错误会出现报错
'UserName=DataTable.Value("UserName","TestData") 修改username从而添加更多的参数化数据
'Reporter 判断是否正常打开IE对应的地址
For i=1 to DataTable.GetSheet("TestData").GetRowCount
systemutil.Run "IEXPLORE.exe","http://108.88.3.253:9030/"
Reporter.ReportEvent micPass,"IE","浏览器"
DataTable.SetCurrentRow i '把i设置为当前执行行
UserName=DataTable.Value("UserName","TestData")
PassWord=DataTable.Value("PassWord","TestData")
Call oReporterManager.StartEngine("Excel", "test_name", "File>C:\Logs\test_name.xls")
Call oReporterManager.Report("Pass","Step 1","预期结果","实际结果","用例通过")
Call oReporterManager.Report("Fail","Step 1","预期结果","实际结果","错误信息")
Browser("鉴定劳鉴管理系统").Page("鉴定劳鉴管理系统").WebEdit("WebEdit").Set UserName
Browser("鉴定劳鉴管理系统").Page("鉴定劳鉴管理系统").WebEdit("WebEdit_2").SetSecure PassWord
Browser("鉴定劳鉴管理系统").Page("鉴定劳鉴管理系统").Link("登陆").Click
wait 1
Browser("鉴定劳鉴管理系统").Close
Next
'Browser("title := 鉴定劳鉴管理系统").Page("title:=鉴定劳鉴管理系统").WebEdit("type:=text").Set "root"
------------------------------------------------------------Demo.vbs-----------------------------------------------------------------------------------------------------------------------
'''<summary>This is a demo QTP test, that showcases some of the ReporterManager abilities</summary>
'''<datecreated>01/09/2007</datecreated>
'''<version>0.9</version>
Option Explicit
''Written by Yaron Assa, 1/9/07. Project home at www.AdvancedQTP.com
'Here's an extensive yet effective reporting framework example:
'Add QTP native reporter to the party. This way we wont need 2 reporting commands - one to ReporterManager, and one to the QTP result log
Call oReporterManager.StartEngine("QTP", "QTP", "")
'Set up a complete backup log - the basics
Call oReporterManager.StartEngine("Text", "Backup", "File>C:\Logs\QTPLog.txt")
Call oReporterManager.StartEngine("XML", "XML Backup", "File>C:\Logs\QTPLog.XML")
'Make sure to copy the demo MDB database to c:\QTP Log.mdb
Call oReporterManager.StartEngine("DB", "DB Backup", "CreateNew>True")
'Set up statistics log - with it we can later produce the step pass/fail ratio with a click of a button
Call oReporterManager.StartEngine("Text", "Stats", "File>C:\Logs\Statistics.CSV|BodyTemplate>""%Status%, %StepName%, %Expected%, %Actual%, %Details%"" & vbcrlf|NewTestCaseTemplate>""General, Switched TestCase, , , %TestCaseName%"" & vbcrlf")
'Set up dedicated performence log - we can load it to excel and imiddiatly extract the time-step differences between relevant steps
Call oReporterManager.StartEngine("Text", "Performance", "File>C:\Logs\Performance.CSV|BodyTemplate>""%Time%, %StepName%"" & vbcrlf|NewTestCaseTemplate>"" "" ")
'Set up a top view excel log, so we'll have something pretty to send to management
Call oReporterManager.StartEngine("Excel", "TopView", "File>C:\Logs\TopView.xls")
'Set up a dedicated error & warnning logs
Call oReporterManager.StartEngine("Text", "Errors", "File>C:\Logs\Errors.txt|BodyTemplate>""%Time%, %Status%, %StepName%, %Expected%, %Actual%"" & vbcrlf")
Call oReporterManager.StartEngine("Winlog", "Win Errors", "ShowAs>QTP Errors")
Call oReporterManager.StartEngine("ScreenCapture", "Error Captures", "Path>C:\Logs\|Prefix>Error -")
'Set up the filter for errors
Call oReporterManager.AddFilter("RegEx", "Errors>Win Errors>Error Captures", "Pattern>Fail|WhatToSearch>Status")
'Set up a user popup that alerts whoever's watching that an error has occured - enable major time saves as a script can be stopped imidiatly
Call oReporterManager.StartEngine("User", "Errors Pop Up", "Timer>2")
Call oReporterManager.AddFilter("RegEx", "Errors Pop Up", "Pattern>Fail|WhatToSearch>Status")
'Test the logs :
'Call oReporterManager.Report ("Pass", "Step 1" ,"Window Should Open" ,"All OK", "No Details")
'Call oReporterManager.Report ("Warning", "Step 2" ,"Window Should Open" ,"It Didn't", "Some Details")
'Call oReporterManager.Report ("Fail", "Step 3" ,"Window Should Open" ,"App. Crashed", "Bla Bla Bla")
-----------------------------------------------------------------------------------Class Templates.VBS------------------------------------------------------------------------------------------
'''<summary>This file holds the base classes for an engine and a filter</summary>
''' <datecreated>01/09/2007</datecreated>
'''<version>0.9</version>
Option Explicit
'ReporterManager Project home at www.AdvancedQTP.com
'A template class for a Filter
''' <summary>
''' A Base class for a filter
''' </summary>
''' <author>Yaron Assa</author>
''' <datecreated>01/09/2007</datecreated>
''' <remarks>This class is essential for the intellisense of the whole project</remarks>
Class XFilter 'Change X to the name of the class (keep the "filter" part)
'Written by Yaron Assa, 1/8/07. Project home at www.AdvancedQTP.com
'I find that keeping the settings withing a dictionary object is the best way to manage things
'Feel free to change this mechanism, it's invisible to the outside world
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' Holds a link to the relevant engine
''' </summary>
''' <value type="XEngine"/>
Public Engine 'Holds a link to the relevant engine
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings 'Will hold the settings dictionary
''' <summary>
''' ID for the type of the filter
''' </summary>
''' <value type="String"/>
''' <example>"DB"</example>
Public Property Get FilterType
FilterType = "Name" 'Change Name to the name of the class
End Property
''' <summary>
''' The Engine's Version
''' </summary>
''' <value type="String"/>
''' <example>"0.8"</example>
Public Property Get Version
Version = "9.0" 'Change to the filter version. Must be 9+
End Property
''' <summary>
''' The minimum version of the manager, required for this filter to work
''' </summary>
''' <value type="String"/>
''' <example>"0.8"</example>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.0" 'The minimum version of the manager, required for this filter to work
End Property
'*************************************************************'
' Function StartFilter (Public)
' Goal Makes the filter ready for use
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params Boolean - True/False
'*************************************************************'
''' <summary>
''' Makes the filter ready for use
''' </summary>
''' <param name="sSettings" type="String">The Filter's init settings as "Field1>Value1|Field2>Value2|...</param>
''' <returns type="Boolean">True if succeeded to start the filter, False if failed</returns>
Public Function StartFilter(sSettings)
''' <value type="Boolean"/>
Dim bResult
Load_Settings(sSettings)
'Add more filter init code here
bResult = AllowCreate 'Can we start the filter?
StartFilter = bResult
End Function
'*************************************************************'
' Function Check (Public)
' Goal Checks if an event matches the filter's criteria
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params Boolean - Does it match the criteria?
'*************************************************************'
''' <summary>Checks if an event matches the filter's criteria</summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status</param>
''' <paramlist name="StatusType">
''' <item>"Fail"<description>The Step Failed</description></item>
''' <item>"Pass"<description>The Step Passed</description></item>
''' <item>"Warning"<description>A Warning</description></item>
''' <item>"General"<description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
''' <returns type="Boolean">Returns True if the event matches, otherwise False</returns>
Public Function Check(sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="Boolean"/>
Dim bResult
bResult = False
'Implement Check code here!
'This is the heart of the filter class
Check = bResult
End Function
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
Private Sub Init_Settings
Set oSettings = CreateObject("Scripting.Dictionary")
'Add Default Settings Here
'e.g. oSettings.Add "ClearExisting" , "True"
'Make sure all mandatory fields have default values!
End Sub
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the filter, False otherwise</returns>
Private Function AllowCreate
''' <value type="Boolean"/>
Dim bResult
bResult = CheckVersion
'Add more pass/Fail conditions here
AllowCreate = bResult
End Function
'*************************************************************'
' Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the filter passes the version check, False otherwise</returns>
Function CheckVersion
''' <value type="Integer"/>
Dim iDiff
''' <value type="String"/>
Dim sEngineVersion
''' <value type="String"/>
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(iDiff, "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(iDiff, "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize()
Init_Settings
'Add Initialization events here
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate
Set oSettings = Nothing
'Add Termination events here
End Sub
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Filter's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
''' <value type="Array"/>
Dim ReplaceArray
''' <value type="Array"/>
Dim arrData
''' <value type="Array"/>
Dim arrSettingData
''' <value type="Integer"/>
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
''' <summary>
''' Forces the filter to close and clear all its references
''' </summary>
Public Sub ClearFilter
Class_Terminate
End Sub
End Class
'A template class for a reporter engine
''' <summary>
''' A Base class for an Engine
''' </summary>
''' <author>Yaron Assa</author>
''' <datecreated>01/09/2007</datecreated>
''' <remarks>This class is essential for the intellisense of the whole project</remarks>
Class XEngine 'Change X to the name of the class (keep the "Engine" part)
'Written by Yaron Assa, 1/8/07. Project home at www.AdvancedQTP.com
'I find that keeping the settings withing a dictionary object is the best way to manage things
'Feel free to change this mechanism, it's invisible to the outside world
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' The user logical name for an instance of this engine (in run-time)
''' </summary>
''' <value type="String"/>
Public Name
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings
''' <value type="Object"/>
''' <summary>Holds the engine's main object</summary>
''' <remarks>You can use it or not, according to your specific implementation</remarks>
Private oEngine 'Holds the engine's main object
''' <summary>
''' ID for the type of the engine
''' </summary>
''' <value type="String"/>
''' <example>"DB"</example>
Public Property Get EngineType
EngineType = "Name" 'Add Engine Type Here
End Property
''' <summary>
''' The Engine's Version
''' </summary>
''' <value type="String"/>
''' <example>"0.8"</example>
Public Property Get Version
Version = "9.0" 'Change to the engine version. Must be 9+
End Property
''' <summary>
''' The minimum version of the manager, required for this engine to work
''' </summary>
''' <value type="String"/>
''' <example>"0.8"</example>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.0" 'The minimum version of the manager, required for this engine to work
End Property
'*************************************************************'
' Function StartEngine (Public)
' Goal Makes the engine ready for use
' In Params sSettings - The Engine's init settings as "Field1>Value1|Field2>Value2|...
' Out Params Boolean - Didn't the engine manage to start?
'*************************************************************'
''' <summary>
''' Makes the engine ready for use
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...</param>
''' <returns type="Boolean">True if succeeded to start the engine, False if failed</returns>
Public Function StartEngine(sSettings)
''' <value type="Boolean"/>
Dim bResult
Load_Settings(sSettings)
'More engine start code here
bResult = AllowCreate 'Can we create this engine?
StartEngine = bResult
End Function
'*************************************************************'
' Function StopEngine (Public)
' Goal Stops the engine
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Stops the engine
''' </summary>
Public Sub StopEngine
Set oEngine = Nothing
Set oSettings = Nothing
'More engine stop code here
End Sub
'*************************************************************'
' Sub Report (Public)
' Goal Reports an event
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params None
'*************************************************************'
''' <summary>
''' Reports an event to all possible reporters
''' </summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status</param>
''' <paramlist name="StatusType">
''' <item>"Fail"<description>The Step Failed</description></item>
''' <item>"Pass"<description>The Step Passed</description></item>
''' <item>"Warning"<description>A Warning</description></item>
''' <item>"General"<description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
Public Sub Report (sStatus, sStepName,sExpected,sActual, sDetails)
'Enter Report Code Here
'This is the heart of the engine's class!
End Sub
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
Private Sub Init_Settings
Set oSettings = CreateObject("Scripting.Dictionary")
'Add Default Settings Here
'e.g. oSettings.Add "File" , "C:\QTPLog.txt"
'Make sure all mandatory fields have default values!
End Sub
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the filter, False otherwise</returns>
Private Function AllowCreate
''' <value type="Boolean"/>
Dim bResult
bResult = CheckVersion
'Add more pass/fail conditions here
AllowCreate = bResult
End Function
'*************************************************************'
' Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the engine passes the version check, False otherwise</returns>
Function CheckVersion
''' <value type="Integer"/>
Dim iDiff
''' <value type="String"/>
Dim sEngineVersion
''' <value type="String"/>
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(iDiff, "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(iDiff, "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize()
Set oEngine = X 'Change X to the engine's object,
'or use any other method to create the engine
Init_Settings
'Add Initialization events here
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate
StopEngine
'Add Terminate Events Here
End Sub
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
''' <value type="Array"/>
Dim ReplaceArray
''' <value type="Array"/>
Dim arrData, arrSettingData
''' <value type="Integer"/>
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
End Class
-----------------------------------------------------------------------------------------------Engines.VBS----------------------------------------------------------------------------------------
'''<summary>This file holds all the different engine classes</summary>
''' <datecreated>20/01/2008</datecreated>
'''<version>0.9.2</version>
Option Explicit
'**********************************************************************'
' Engines
'**********************************************************************'
''' <summary>
''' This Engine is the native QTP reporter.Reportevent engine
''' </summary>
''' <author>Yaron Assa</author>
''' <datecreated>01/09/2007</datecreated>
''' <remarks>Possible Settings:
''' <para>
''' Filter = Integer - 0 / 1 / 2 / 3. 1 Sets the filtering on the native QTP results file (see reporter.Filter help for details)<br/>
''' Default = 1 ( rfEnableErrorsAndWarnings = Only event with a warning or fail status are displayed in the Test Results.)<br/>
''' The Filter Settings DOES NOT filter any event sent by the Report function, ONLY those who QTP logs ON ITS OWN.<br/>
''' </para>
''' See settings details at <see cref="QTPEngine.StartEngine"/>
''' </remarks>
''' <example><c>"Filter>3"</c> - This will block any non-error event QTP would usually log (e.g. Button.Click etc.)</example>
Class QTPEngine
'Written by Yaron Assa, 1/8/07. Project home at www.AdvancedQTP.com
'This Engine is the native QTP reporter.Reportevent engine
'Possible Settings :
'Filter = Integer - 0 / 1 / 2 / 3. 1 Sets the filtering on the native QTP results file (see reporter.Filter help for details)
' Default = 1 ( rfEnableErrorsAndWarnings = Only event with a warning or fail status are displayed in the Test Results.)
' The Filter Settings DOES NOT filter any event sent by the Report function, ONLY those who QTP logs ON ITS OWN.
'
'E.g. : "Filter>3"
'This will block any non-error event QTP would usually log (e.g. Button.Click etc.)
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
''' <seealso cref="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' The user logical name for an instance of this engine (in run-time)
''' </summary>
''' <value type="String"/>
Public Name
''' <summary>
''' The Engine's Version
''' </summary>
''' <value type="String"/>
Public Property Get Version
Version = "0.9.2"
End Property
''' <summary>
''' The minimum version of the manager, required for this engine to work
''' </summary>
''' <value type="String"/>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.9"
End Property
''' <summary>
''' ID for the type of the engine
''' </summary>
''' <value type="String"/>
Public Property Get EngineType
EngineType = "QTP" 'ID
End Property
'*************************************************************'
' Function StartEngine (Public)
' Goal Makes the engine ready for use
' In Params sSettings - The Engine's init settings as "Field1>Value1|Field2>Value2|...
' Out Params Boolean - Didn't the engine manage to start?
'*************************************************************'
''' <summary>
''' Makes the engine ready for use
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...
''' <list type="table">
''' <item><term>Filter</term>
''' <description>Integer - 0 / 1 / 2 / 3. 1 Sets the filtering On the native QTP results file (see reporter.Filter help For details)<br/>
''' Default = 1 ( rfEnableErrorsAndWarnings = Only event with a warning or fail status are displayed in the Test Results.)
''' </description></item>
''' </list></param>
''' <returns type="Boolean">True if succeeded to start the engine, False if failed</returns>
''' <example><c>"Filter>3"</c> - This will block any non-error event QTP would usually log (e.g. Button.Click etc.)</example>
Public Function StartEngine(sSettings)
Load_Settings(sSettings)
Reporter.Filter = oSettings("Filter")
StartEngine = AllowCreate
End Function
'*************************************************************'
' Function StopEngine (Public)
' Goal Stops the engine
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Stops the engine
''' </summary>
Public Sub StopEngine
Set oSettings = Nothing
Set Manager = Nothing
End Sub
'*************************************************************'
' Sub Report (Public)
' Goal Reports an event
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params None
'*************************************************************'
''' <summary>
''' Reports an event
''' </summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status<note>Legacy suppurt for integer status code exists</note></param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
Public Sub Report (sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="Integer"/>
Dim iStatus
''' <value type="String"/>
Dim sContent
sContent = "Expected Result: " & sExpected & vbCrLf & _
"Actual Result: " & sActual & vbCrLf & vbCrLf & _
"Details: " & sDetails
Select Case sStatus
Case "Pass"
iStatus = MicPass
Case "Fail"
iStatus = MicFail
Case "Warning"
iStatus = MicWarning
Case Else
iStatus = micDone
End Select
Reporter.Filter = rfEnableAll 'Allow all events to be logged
Reporter.ReportEvent iStatus, sStepName, sContent
Reporter.Filter = CInt(oSettings("Filter")) 'Return to the screening setting
End Sub
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
''' <remarks>Filter = rfEnableErrorsAndWarnings (Screen any general event not specifically sent to QTP Reporter)</remarks>
Private Sub Init_Settings
Set oSettings = CreateObject("Scripting.Dictionary")
oSettings.Add "Filter", rfEnableErrorsAndWarnings 'Screen any general event not specifically sent to QTP Reporter
End Sub
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params sType - The reporter Type
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the filter, False otherwise</returns>
''' <remarks>Checks if there already exists an engine for type = QTP</remarks>
Private Function AllowCreate
''' <value type="Boolean"/>
Dim bResult
''' <value type="Integer"/>
Dim i
''' <value type="Scripting.Dictionary"/>
'''<summary>The manager's reporters collection</summary>
Dim oReporters
''' <value type="Array"/>
Dim arrKeys
bResult = CheckVersion
If bResult = False Then
AllowCreate = False
Exit Function
End If
'Check There're no multiple QTP engines
Set oReporters = Manager.Reporters
arrKeys = oReporters.Keys
For i = 0 To oReporters.Count -1
If oReporters(arrKeys(i))("Engine").EngineType = "QTP" Then
bResult = False
Reporter.ReportEvent MicFail, "Start Engine", "Can't initiate multiple instances of this engine"
Exit For
End If
Next
Set oReporters = Nothing
AllowCreate = bResult
End Function
'*************************************************************'
' Private Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the engine passes the version check, False otherwise</returns>
Private Function CheckVersion
Dim iDiff
Dim sEngineVersion
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
''' <value type="Array"/>
Dim ReplaceArray
''' <value type="Array"/>
Dim arrData, arrSettingData
''' <value type="Integer"/>
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize() ' Setup Initialize event.
Init_Settings
Set Manager = Nothing
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate ' Setup Terminate event.
StopEngine
End Sub
End Class
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
''' <summary>
''' This Engine pops-up messages for the used, that disappear after a few seconds
''' It also allows for script pausing
''' </summary>
''' <author>Yaron Assa</author>
''' <datecreated>01/09/2007</datecreated>
''' <remarks>Possible Settings:
''' <para>
''' Timer = Integer - the number of seconds before the message disappears<br/>
''' Default = 3
''' </para>
''' See settings details at <see cref="UserEngine.StartEngine"/>
''' </remarks>
''' <example><c>"Timer>2"</c></example>
Class UserEngine
'Written by Yaron Assa, 1/8/07. Project home at www.AdvancedQTP.com
'This Engine pops-up messages for the used, that disappear after a few seconds
'It also allows for script pausing
'Possible Settings :
'Timer = Integer - the number of seconds before the message disappears
' Default = 3
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings
''' <value type="Wscript.Shell"/>
''' <summary>Will hold the pop-up script object</summary>
Private oEngine
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
''' <seealso cref="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' The user logical name for an instance of this engine (in run-time)
''' </summary>
''' <value type="String"/>
Public Name
''' <summary>
''' The Engine's Version
''' </summary>
''' <value type="String"/>
Public Property Get Version
Version = "0.8"
End Property
''' <summary>
''' The minimum version of the manager, required for this engine to work
''' </summary>
''' <value type="String"/>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.9"
End Property
''' <summary>
''' ID for the type of the engine
''' </summary>
''' <value type="String"/>
Public Property Get EngineType
EngineType = "User" 'ID
End Property
'*************************************************************'
' Function StartEngine (Public)
' Goal Makes the engine ready for use
' In Params sSettings - The Engine's init settings as "Field1>Value1|Field2>Value2|...
' Out Params Boolean - Didn't the engine manage to start?
'*************************************************************'
''' <summary>
''' Makes the engine ready for use
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...
''' <list type="table">
''' <item><term>Timer</term>
''' <description>Integer - the number of seconds before the message disappears<br/>
''' Default = 3
''' </description></item>
''' </list></param>
''' <returns type="Boolean">True if succeeded to start the engine, False if failed</returns>
''' <example><c>"Timer>2"</c></example>
Public Function StartEngine(sSettings)
Load_Settings(sSettings)
Set oEngine = CreateObject("WScript.Shell")
StartEngine = AllowCreate
End Function
'*************************************************************'
' Function StopEngine (Public)
' Goal Stops the engine
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Stops the engine
''' </summary>
Public Sub StopEngine
Set oSettings = Nothing
Set oEngine = Nothing
Set Manager = Nothing
End Sub
'*************************************************************'
' Sub Report (Public)
' Goal Reports an event
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params None
'*************************************************************'
''' <summary>
''' Reports an event
''' </summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status<note>Legacy suppurt for integer status code exists</note></param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
Public Sub Report (sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="Integer"/>
Dim iTimer
''' <value type="Integer"/>
Dim iResult
''' <value type="String"/>
Dim sMessage
''' <value type="String"/>
Dim sOriginalMessage
''' <value type="Integer"/>
Dim iMessageType
iTimer = CInt(oSettings("Timer"))
sMessage = "Status = " & sStatus & vbCrLf & _
"Step = " & sStepName & vbCrLf & _
"Expected Result = " & sExpected & vbCrLf & _
"Actual Result = " & sActual & vbCrLf & _
"Details = " & sDetails & vbCrLf
sOriginalMessage = sMessage
sMessage = sMessage & vbCrLf & "This message will close automatically " & vbCrLf & "Press OK to pause the script"
iMessageType = 0
Select Case sStatus
Case "Fail"
iMessageType = 16
Case "Warning"
iMessageType = 48
Case Else
iMessageType = 64
End Select
iResult = oEngine.PopUp(sMessage , iTimer, "ReportManager - User Reporter", iMessageType)
If iResult = 1 Then MsgBox sOriginalMessage & vbCrLf & vbCrLf & "Automation Paused - Press OK to continue", , "Script Paused By User"
End Sub
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
''' <remarks>Timer = 3</remarks>
Private Sub Init_Settings
Set oSettings = CreateObject("Scripting.Dictionary")
oSettings.Add "Timer", "3"
End Sub
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the filter, False otherwise</returns>
Private Function AllowCreate
Dim bResult
bResult = CheckVersion
AllowCreate = bResult
End Function
'*************************************************************'
' Private Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the engine passes the version check, False otherwise</returns>
Private Function CheckVersion
Dim iDiff
Dim sEngineVersion
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
''' <value type="Array"/>
Dim ReplaceArray
''' <value type="Array"/>
Dim arrData, arrSettingData
''' <value type="Integer"/>
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize() ' Setup Initialize event.
Set Manager = Nothing
Init_Settings
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate ' Setup Terminate event.
StopEngine
End Sub
End Class
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
''' <summary>
''' This Engine is a simple text file logger, with template support
''' </summary>
''' <author>Yaron Assa</author>
''' <datecreated>01/09/2007</datecreated>
''' <remarks>Possible Settings:
''' <para>
''' File = String - the log file path and name. (e.g. "C:\LogFile.Txt")<br/>
''' Default = "C:\QTPLog.txt"
''' </para>
''' <para>
''' ClearExisting = True/False - Should we erase the existing log. True = Erase.<br/>
''' Default = True
''' </para>
''' <para>
''' BodyTemplate = String. The template for reporting the actual event. <br/>
''' See template tags (blow) for more details.
''' </para>
''' <para>
''' NewTestCaseTemplate = String. The template for the title that's added when the event belongs to a different test-case than before.<br/>
''' See template tags (blow) for more details.
''' </para>
''' <para>
''' Template Tags:<br/>
''' ==============
''' </para>
''' <para>
''' A template string represents a valid REPRESENTATION of a VBScript script. Usually this just means doubling all the double-quotes (" -> "")<br/>
''' E,g, <c>" vbcrlf & ""Hello"" " </c>= Valid REPRESENTATION<br/>
''' <c>vbcrlf & "Hello"</c> = This IS a valid string, but not a valid REPRESENTATION of a string<br/>
''' <c>" vbcrlf & "Hello" "</c> = This isn't even a valid string<br/>
''' </para>
''' <para>
''' Within a template string you can use the following tags (put them as you would put regular text):
''' </para>
''' <para>
''' %Status% = Will be replace with the event status
''' </para>
''' <para>
''' %Details% = Will be replace with the event Details
''' </para>
''' <para>
''' %StepName% = Will be replace with the event Step Name
''' </para>
''' <para>
''' %Expected% = Will be replace with the event expected result
''' </para>
''' <para>
''' %Actual% = Will be replace with the event actual result
''' </para>
''' <para>
''' %TestCaseName% = Will be replaced with the event Test Case Name (This is the action name + iteration)
''' </para>
''' <para>
''' %Time% = The timestamp at the moment of the event
''' </para>
''' <para>
''' YOU MUST WRITE THESE TAGS EXACTLY AS THEY APPEAR. e.g. %Actual% is OK, but %actual% will NOT work<br/>
''' Make sure you fully grasp the difference between a string, and a REPRESENTATION of a string
''' </para>
''' See settings details at <see cref="TextEngine.StartEngine"/>
''' </remarks>
''' <example><c>"vbcrlf & ""%StepName%, %Status%"" & vbcrlf & String(40, ""-"") & vbcrlf &"" Expected : %Expected%"" & vbcrlf & ""Actual : %Actual% "" & vbcrlf & ""Details: %Details% """</c></example>
Class TextEngine
'Written by Yaron Assa, 1/8/07. Project home at www.AdvancedQTP.com
'This Engine is a simple text file logger, with template support
'Possible Settings :
'File = String - the log file path and name. (e.g. "C:\LogFile.Txt")
' Default = "C:\QTPLog.txt"
'ClearExisting = True/False - Should we erase the existing log. True = Erase.
' Default = True
'
'BodyTemplate = String. The template for reporting the actual event.
' See template tags (blow) for more details.
' Default = A default template
'
'NewTestCaseTemplate = String. The template for the title that's added when the event belongs to a different test-case than before.
' See template tags (blow) for more details.
' Default = A default template
'
'Template Tags:
'==============
' A template string represents a valid REPRESENTATION of a VBScript script. Usually this just means doubling all the double-quotes (" -> "")
' E,g, " vbcrlf & ""Hello"" "= Valid REPRESENTATION
' vbcrlf & "Hello" = This IS a valid string, but not a valid REPRESENTATION of a string
' " vbcrlf & "Hello" " = This isn't even a valid string
'
'Within a template string you can use the following tags (put them as you would put regular text):
' %Status% = Will be replace with the event status
' %Details% = Will be replace with the event Details
' %StepName% = Will be replace with the event Step Name
' %Expected% = Will be replace with the event expected result
' %Actual% = Will be replace with the event actual result
' %TestCaseName% = Will be replaced with the event Test Case Name (This is the action name + iteration)
' %Time% = The timestamp at the moment of the event
'
' YOU MUST WRITE THESE TAGS EXACTLY AS THEY APPEAR. e.g. %Actual% is OK, but %actual% will NOT work
'
' E.g. for template with tags (These are actually the default templates):
' "vbcrlf & "" ************************** %TestCaseName% ************************** "" & vbcrlf & vbcrlf"
'
' And a more complex example for the body:
' "vbcrlf & ""%StepName%, %Status%"" & vbcrlf & String(40, ""-"") & vbcrlf &"" Expected : %Expected%"" & vbcrlf & ""Actual : %Actual% "" & vbcrlf & ""Details: %Details% """
'
' Make sure you fully grasp the difference between a string, and a REPRESENTATION of a string
''' <value type="Scripting.FileSystemObject"/>
''' <summary>Holds the FileSystemObject</summary>
Private oEngine
''' <value type="TextStream"/>
''' <summary>Holds the text file TextStream</summary>
Private oFile
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings
''' <value type="String"/>
Private sLastTestCase
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
''' <seealso cref="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' The user logical name for an instance of this engine (in run-time)
''' </summary>
''' <value type="String"/>
Public Name
''' <summary>
''' The Engine's Version
''' </summary>
''' <value type="String"/>
Public Property Get Version
Version = "0.9"
End Property
''' <summary>
''' The minimum version of the manager, required for this engine to work
''' </summary>
''' <value type="String"/>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.9"
End Property
''' <summary>
''' ID for the type of the engine
''' </summary>
''' <value type="String"/>
Public Property Get EngineType
EngineType = "Text" 'Add Engine Type Here
End Property
'*************************************************************'
' Function StartEngine (Public)
' Goal Makes the engine ready for use
' In Params sSettings - The Engine's init settings as "Field1>Value1|Field2>Value2|...
' Out Params Boolean - Didn't the engine manage to start?
'*************************************************************'
''' <summary>
''' Makes the engine ready for use
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...
''' <list type="table">
''' <item><term>File</term>
''' <description>String - the log file path and name. (e.g. "C:\LogFile.Txt")<br/>
''' Default = "C:\QTPLog.txt"
''' </description></item>
''' <item><term>ClearExisting</term>
''' <description>True/False - Should we erase the existing log. True = Erase.<br/>
''' Default = True
''' </description></item>
''' <item><term>BodyTemplate</term>
''' <description>String. The template for reporting the actual event. <br/>
''' For template details, See <see cref="TextEngine"/>
''' </description></item>
''' <item><term>NewTestCaseTemplate</term>
''' <description>String. The template for the title that's added when the event belongs to a different test-case than before.<br/>
''' For template details, See <see cref="TextEngine"/>
''' </description></item>
''' </list></param>
''' <returns type="Boolean">True if succeeded to start the engine, False if failed</returns>
Public Function StartEngine(sSettings)
''' <value type="String"/>
''' <summary>Will hold the containing folder for the report</summary>
Dim ParentFolder
Load_Settings(sSettings)
'Should we erase the file?
If CBool(oSettings("ClearExisting")) = True Then _
If oEngine.FileExists(oSettings("File")) Then oEngine.DeleteFile(oSettings("File"))
If Not oEngine.FileExists(oSettings("File")) Then
'Create the log file, if needed
ParentFolder = oEngine.GetParentFolderName(oSettings("File"))
If Not oEngine.FolderExists(ParentFolder) Then
MakePath ParentFolder
End If
CreateResultFile(oSettings("File"))
End If
'Keep a living reference to the text file
Set oFile = oEngine.OpenTextFile(oSettings("File"), 8, True)
StartEngine = AllowCreate
End Function
'*************************************************************'
' Function StopEngine (Public)
' Goal Stops the engine
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Stops the engine
''' </summary>
Public Sub StopEngine
Set Manager = Nothing
If Not oFile Is Nothing Then oFile.Close
Set oEngine = Nothing
Set oFile = Nothing
Set oSettings = Nothing
End Sub
'*************************************************************'
' Sub Report (Public)
' Goal Reports an event
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params None
'*************************************************************'
''' <summary>
''' Reports an event
''' </summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status<note>Legacy suppurt for integer status code exists</note></param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
Public Sub Report (sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="String"/>
Dim sMessage, sTestcaseName
''' <value type="String"/>
Dim sBodyTemplate, sNewTestCaseTemplate
''' <value type="String"/>
Dim sBody, sNewTestCase
''' <value type="Array"/>
Dim arrTags
''' <value type="Integer"/>
Dim i
''' <value type="Boolean"/>
Dim bResult
''' <value type="String"/>
Dim sTime
sTime = Time
bResult = True
On Error Resume Next
arrTags = Array("Status", "StepName", "Expected", "Actual", "Details", "TestCaseName", "Time")
sBodyTemplate = oSettings("BodyTemplate")
sNewTestCaseTemplate = oSettings("NewTestCaseTemplate")
For i = 0 To UBound(arrTags)
sBodyTemplate = Replace(sBodyTemplate, "%" & arrTags(i) & "%", Chr(34) & "& s" & arrTags(i) & " & " & Chr(34))
sNewTestCaseTemplate = Replace(sNewTestCaseTemplate , "%" & arrTags(i) & "%", Chr(34) & "& s" & arrTags(i) & " & " & Chr(34))
Next
If Mid(sBodyTemplate,1,1) = Chr(34) Then sBodyTemplate = Mid(sBodyTemplate,1)
If Mid(sBodyTemplate,1,1) = "&" Then sBodyTemplate = Mid(sBodyTemplate,1)
If Mid(sNewTestCaseTemplate,1,1) = Chr(34) Then sBodyTemplate = Mid(sBodyTemplate,1)
If Mid(sNewTestCaseTemplate,1,1) = "&" Then sBodyTemplate = Mid(sBodyTemplate,1)
sMessage = ""
sTestcaseName = Environment("ActionName") & " > Iteration (Test-Action) = " & Environment("TestIteration") & "-" & Environment("ActionIteration")
'Are we dealing with a different Action / Iteration? If so, add a nice big header
If sTestcaseName <> sLastTestCase Then Execute "sMessage = " & sNewTestCaseTemplate
'sMessage = vbcrlf & "************************** " & TestcaseName & " **************************" & vbcrlf & vbcrlf
sLastTestCase = sTestcaseName
'Compile text message
Execute "sMessage = sMessage & " & sBodyTemplate
If Err.Number <> 0 Then
bResult = False
End If
On Error Goto 0
If bResult = False Then sMessage = "Engine Template Problem. Make sure you've read the help file"
oFile.Write sMessage 'Add message to the file
End Sub
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
''' <remarks>
''' <para> File = "C:\QTPLog.txt" </para>
''' <para> ClearExisting = True </para>
''' <para> NewTestCaseTemplate = <c>"vbcrlf & ""************************** %TestCaseName% **************************"" & vbcrlf & vbcrlf" </c></para>
''' <para> <c>BodyTemplate = "vbcrlf & ""%StepName% (%Time%) %Status%"" & vbcrlf & String(40, ""-"") & vbcrlf &""" & _
''' "Expected Result: %Expected%"" & vbcrlf & ""Actual Result: %Actual% "" & vbcrlf & ""Details: %Details% "" & vbcrlf & vbcrlf" </c></para>
''' </remarks>
Private Sub Init_Settings
Set oSettings = CreateObject("Scripting.Dictionary")
oSettings.Add "File", "C:\QTPLog.txt" 'What is the log file?
oSettings.Add "ClearExisting", "True" 'Should we start a new log? True = Delete existing file.
oSettings.Add "NewTestCaseTemplate", "vbcrlf & ""************************** %TestCaseName% **************************"" & vbcrlf & vbcrlf"
oSettings.Add "BodyTemplate", "vbcrlf & ""%StepName% (%Time%) %Status%"" & vbcrlf & String(40, ""-"") & vbcrlf &""" & _
"Expected Result: %Expected%"" & vbcrlf & ""Actual Result: %Actual% "" & vbcrlf & ""Details: %Details% "" & vbcrlf & vbcrlf"
End Sub
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the filter, False otherwise</returns>
Private Function AllowCreate
Dim bResult
bResult = CheckVersion
AllowCreate = bResult
End Function
'*************************************************************'
' Private Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the engine passes the version check, False otherwise</returns>
Private Function CheckVersion
Dim iDiff
Dim sEngineVersion
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
''' <value type="Array"/>
Dim ReplaceArray
''' <value type="Array"/>
Dim arrData, arrSettingData
''' <value type="Integer"/>
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
'**********************************************************************************************************************************
'Function Name: MakePath
'Description: This Function creates the result file
'Parameter: This function takes the following parameters
' sPath - Required path (must be fully qualified)
' Returns: True - Path now exists
' False - Path does not exist
'Created By: Sameer Girolkar
'Creation Date: 07-Dec-2005
'**********************************************************************************************************************************
''' <summary>
''' This Function creates the result file
''' </summary>
''' <author>Sameer Girolkar</author>
''' <param name="sPath" type="String">Required path (must be fully qualified)</param>
''' <returns type="Boolean">True if the path now exists, False otherwise</returns>
Private Function MakePath(sPath)
' Default result
MakePath = False
' Fail if drive is not valid
If Not oEngine.DriveExists(oEngine.GetDriveName(sPath)) Then Exit Function
' Succeed if folder exists
If oEngine.FolderExists(sPath) Then
MakePath = True
Exit Function
End If
' Call self to ensure parent path exists
If Not MakePath(oEngine.GetParentFolderName(sPath)) Then Exit Function
' Create folder
On Error Resume Next
oEngine.CreateFolder sPath
MakePath = oEngine.FolderExists(sPath)
End Function
'*************************************************************'
' Sub CreateResultFile (Private)
' Goal Creates a new text file
' In Params sFile - The name of the file to create
' Out Params None
'*************************************************************'
''' <summary>
''' Creates a text result file
''' </summary>
''' <param name="sFile" type="String">The path and name of the file to create</param>
Private Sub CreateResultFile(sFile)
''' <value type="TextStream"/>
Dim oNewFile
Set oNewFile = oEngine.CreateTextFile(sFile, True)
oNewFile.Close
Set oNewFile = Nothing
End Sub
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize()
Set Manager = Nothing
Set oEngine = CreateObject("Scripting.FileSystemObject")
Set oFile = Nothing
Init_Settings
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate
StopEngine
End Sub
End Class
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
''' <summary>
''' This Engine is a an Excel logger, built upon Sameer Girolkar's ResultToXL.
''' </summary>
''' <author>Yaron Assa And Sameer Girolkar</author>
''' <datecreated>01/09/2007</datecreated>
''' <remarks>Possible Settings :
''' <para>
''' File = String - the log file path and name. (e.g. "C:\LogFile.xls")<br/>
''' Default = "C:\QTPLog.xls"
''' </para>
''' <para>
''' ClearExisting = True/False - Should we erase the existing log. True = Erase.<br/>
''' Default = True
''' </para>
''' See settings details at <see cref="ExcelEngine.StartEngine"/>
''' </remarks>
''' <example><c>"File>C:\Logs\Errors.xls"</c></example>
Class ExcelEngine
'Written by Yaron Assa, 1/8/07. Project home at www.AdvancedQTP.com
'This Engine is a an Excel logger, built upon Sameer Girolkar's ResultToXL.
'All of the excel code is Girolkar's, I've just wrapped it into the Engine class
'Possible Settings :
'File = String - the log file path and name. (e.g. "C:\LogFile.Txt")
' Default = "C:\QTPLog.xls"
'ClearExisting = True/False - Should we erase the existing log. True = Erase.
' Default = True
'
'E.g. : "File>C:\QTP\Log.xls|ClearExisting>False"
'This will write the log to C:\QTP\Log.xls, appending the text if the file already exists
''' <value type="Excel.Application"/>
''' <summary>Holds the engine's core object</summary>
Private oEngine
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings
''' <value type="Scripting.FileSystemObject"/>
Private oFSO
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
''' <seealso cref="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' The user logical name for an instance of this engine (in run-time)
''' </summary>
''' <value type="String"/>
Public Name
''' <summary>
''' The Engine's Version
''' </summary>
''' <value type="String"/>
Public Property Get Version
Version = "0.9"
End Property
''' <summary>
''' The minimum version of the manager, required for this engine to work
''' </summary>
''' <value type="String"/>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.9"
End Property
''' <summary>
''' ID for the type of the engine
''' </summary>
''' <value type="String"/>
Public Property Get EngineType'ID
EngineType = "Excel"
End Property
'*************************************************************'
' Function StartEngine (Public)
' Goal Makes the engine ready for use
' In Params sSettings - The Engine's init settings as "Field1>Value1|Field2>Value2|...
' Out Params Boolean - Didn't the engine manage to start?
'*************************************************************'
''' <summary>
''' Makes the engine ready for use
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...
''' <list type="table">
''' <item><term>File</term>
''' <description>String - the log file path and name. (e.g. "C:\LogFile.xls")<br/>
''' Default = "C:\QTPLog.xls"
''' </description></item>
''' <item><term>ClearExisting</term>
''' <description>True/False - Should we erase the existing log. True = Erase.<br/>
''' Default = True
''' </description></item>
''' </list></param>
''' <returns type="Boolean">True if succeeded to start the engine, False if failed</returns>
''' <example><c>"File>C:\Logs\Errors.xls|ClearExsiting>False"</c></example>
Public Function StartEngine(sSettings)
''' <value type="String"/>
''' <summary>This will hold the file's containing folder</summary>
Dim ParentFolder
Load_Settings(sSettings)
'Should we delete the file?
If CBool(oSettings("ClearExisting")) = True Then _
If oFso.FileExists(oSettings("File")) Then oFSO.DeleteFile(oSettings("File"))
'Create the log file, if needed
If Not oFSO.FileExists(oSettings("File")) Then
ParentFolder = oFSO.GetParentFolderName(oSettings("File"))
If Not oFSO.FolderExists(ParentFolder) Then
MakePath ParentFolder
End If
CreateResultFile(oSettings("File"))
End If
StartEngine = AllowCreate
End Function
'*************************************************************'
' Function StopEngine (Public)
' Goal Stops the engine
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Stops the engine
''' </summary>
Public Sub StopEngine
Set Manager = Nothing
If Not oEngine Is Nothing Then oEngine.Quit
Set oEngine = Nothing
Set oSettings = Nothing
Set oFSO = Nothing
End Sub
'**********************************************************************************************************************************
'Function Name: MakePath
'Description: This Function creates the result file in XLS format and formats the Header section
'Parameter: This function takes the following parameters
' sPath - Required path (must be fully qualified)
' Returns: True - Path now exists
' False - Path does not exist
'Created By: Sameer Girolkar
'Creation Date: 07-Dec-2005
'**********************************************************************************************************************************
''' <summary>
''' This Function creates the result file
''' </summary>
''' <author>Sameer Girolkar</author>
''' <param name="sPath" type="String">Required path (must be fully qualified)</param>
''' <returns type="Boolean">True if the path now exists, False otherwise</returns>
Private Function MakePath(sPath)
' Default result
MakePath = False
' Fail if drive is not valid
If Not oFso.DriveExists(oFso.GetDriveName(sPath)) Then Exit Function
' Succeed if folder exists
If oFso.FolderExists(sPath) Then
MakePath = True
Exit Function
End If
' Call self to ensure parent path exists
If Not MakePath(oFso.GetParentFolderName(sPath)) Then Exit Function
' Create folder
On Error Resume Next
oFso.CreateFolder sPath
MakePath = oFso.FolderExists(sPath)
End Function
'*************************************************************'
' Sub Report (Public)
' Goal Reports an event
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params None
'
'This function was 99.99% written by Sameer Girolkar, 08-Dec-2005
'*************************************************************'
''' <summary>
''' Reports an event
''' </summary>
''' <author>Sameer Girolkar And Yaron Assa</author>
''' <remarks>This function was 99.99% written by Sameer Girolkar, 08-Dec-2005</remarks>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status<note>Legacy suppurt for integer status code exists</note></param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
Public Sub Report (sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="String"/>
Dim TestcaseName
''' <value type="String"/>
Dim ParentFolder
''' <value type="Excel.Workbook"/>
Dim objWorkBook
''' <value type="Excel.Worksheet"/>
Dim objSheet
''' <value type="Integer"/>
Dim Row, TCRow, NewTC
TestcaseName = Environment("ActionName") & " > Iteration (Test-Action) = " & Environment("TestIteration") & "-" & Environment("ActionIteration")
'Open the Result file
Set objWorkBook = oEngine.Workbooks.Open (oSettings("File"))
'Select the Summery Sheet
Set objSheet = oEngine.Sheets("Test_Summary")
oEngine.Sheets("Test_Summary").Select
With objSheet
'Note the Row No on which to Report the result
Row = .Range("C8").Value + 2*.Range("C7").Value + 2
TCRow = .Range("C7").Value + 11
NewTC = False
'Check if it is a new Tetstcase
If objSheet.Cells(TCRow - 1, 2).Value <> TestcaseName Then
.Cells(TCRow, 2).Value = TestcaseName
oEngine.ActiveSheet.Hyperlinks.Add objSheet.Cells(TCRow, 2), "", "Test_Result!A" & Row+1, TestcaseName
.Cells(TCRow, 3).Value = sStatus
Select Case sStatus
Case "Fail"
.Range("C" & TCRow).Font.ColorIndex = 3
Case "Pass"
.Range("C" & TCRow).Font.ColorIndex = 50
Case "Warning"
.Range("C" & TCRow).Font.ColorIndex = 46
End Select
.Cells(TCRow, 4).Value = 1
NewTC = True
.Range("C7").Value = .Range("C7").Value + 1
'Set the Borders for the Result Header
.Range("B" & TCRow & ":D" & TCRow).Borders(1).LineStyle = 1
.Range("B" & TCRow & ":D" & TCRow).Borders(2).LineStyle = 1
.Range("B" & TCRow & ":D" & TCRow).Borders(3).LineStyle = 1
.Range("B" & TCRow & ":D" & TCRow).Borders(4).LineStyle = 1
'Set color and Fonts for the Header
.Range("B" & TCRow & ":D" & TCRow).Interior.ColorIndex = 19
.Range("B" & TCRow).Font.ColorIndex = 53
.Range("B" & TCRow & ":D" & TCRow).Font.Bold = True
Else
.Range("D" & TCRow-1).Value = .Range("D" & TCRow-1).Value + 1
End If
If (Not NewTC) And (sStatus = "Fail") Then
.Cells(TCRow-1, 3).Value = "Fail"
.Range("C" & TCRow-1).Font.ColorIndex = 3
End If
If (Not NewTC) And (sStatus = "Warning") Then
If .Cells(TCRow-1, 3).Value = "Pass" Then
.Cells(TCRow-1, 3).Value = "Warning"
.Range("C" & TCRow-1).Font.ColorIndex = 46
End If
End If
.Range("C8").Value = .Range("C8").Value + 1
'Update the End Time
.Range("C5").Value = Time
'Set Column width
.Columns("B:D").Select
.Columns("B:D").Autofit
End With
'Select the Result Sheet
Set objSheet = oEngine.Sheets("Test_Result")
oEngine.Sheets("Test_Result").Select
With objSheet
'Enter the Result
If NewTC Then
.Range("A" & Row & ":E" & Row).Interior.ColorIndex = 15
.Range("A" & Row & ":E" & Row).Merge
Row = Row + 1
.Range("A" & Row & ":E" & Row).Merge
.Range("A" & Row).Value = TestcaseName
'Set color and Fonts for the Header
.Range("A" & Row & ":E" & Row).Interior.ColorIndex = 19
.Range("A" & Row & ":E" & Row).Font.ColorIndex = 53
.Range("A" & Row & ":E" & Row).Font.Bold = True
Row = Row + 1
End If
.Range("A" & Row).Value = sStepName
'oEngine.Selection.ShapeRange.ScaleWidth 1.72, msoFalse, msoScaleFromTopLeft
'oEngine.Selection.ShapeRange.ScaleHeight 1.81, msoFalse, msoScaleFromTopLeft
.Range("B" & Row).Value = sStatus
.Range("B" & Row).Font.Bold = True
Select Case sStatus
Case "Pass"
.Range("B" & Row).Font.ColorIndex = 50
Case "Fail"
.Range("A" & Row & ":E" & Row).Font.ColorIndex = 3
Case "Warning"
.Range("A" & Row & ":E" & Row).Font.ColorIndex = 46
End Select
.Range("B" & Row).Font.Bold = True
.Range("C" & Row).Value = sExpected
.Range("D" & Row).Value = sActual
.Range("E" & Row).Value = sDetails
'Set the Borders
.Range("A" & Row & ":E" & Row).Borders(1).LineStyle = 1
.Range("A" & Row & ":E" & Row).Borders(2).LineStyle = 1
.Range("A" & Row & ":E" & Row).Borders(3).LineStyle = 1
.Range("A" & Row & ":E" & Row).Borders(4).LineStyle = 1
.Range("A" & Row & ":E" & Row).VerticalAlignment = -4160
End With
oEngine.Sheets("Test_Summary").Select
oEngine.Sheets("Test_Summary").Range("B1").Select
'Save the Workbook
objWorkBook.Save
Set objWorkBook = Nothing
End Sub
'**********************************************************************************************************************************
'Function Name: CreateResultFile
'Description: This Function creates the result file in XLS format and formats the Header section
'Parameter: This function takes the following parameters
' FilePath - Path of the result file
'Created By: Sameer Girolkar
'Creation Date: 07-Dec-2005
'**********************************************************************************************************************************
''' <summary>
''' This Function creates the result file in XLS format and formats the Header section
''' </summary>
''' <author>Sameer Girolkar</author>
''' <remarks>Slightly modifies by Yaron Assa</remarks>
''' <param name="FilePath" type="String">The result file path</param>
''' <returns type="Boolean">Pass/Fail</returns>
Private Function CreateResultFile(FilePath)
''' <value type="Excel.Worksheet"/>
Dim objSheet
'Disable alerts
oEngine.DisplayAlerts = False
'Add a workbook to the Excel App
oEngine.Workbooks.Add
'Get the object of the first sheet in the workbook
Set objSheet = oEngine.Sheets.Item(1)
oEngine.Sheets.Item(1).Select
With objSheet
'Rename the first sheet to "Test_Summery"
.Name = "Test_Summary"
'Set the Heading
.Range("B1").Value = "Test Results"
.Range("B1:C1").Merge
'Set color and Fonts for the Header
.Range("B1:C1").Interior.ColorIndex = 53
.Range("B1:C1").Font.ColorIndex = 19
.Range("B1:C1").Font.Bold = True
'Set the Date and time of Execution
.Range("B3").Value = "Test Date: "
.Range("B4").Value = "Test Start Time: "
.Range("B5").Value = "Test End Time: "
.Range("B6").Value = "Test Duration: "
.Range("C3").Value = Date
.Range("C4").Value = Time
.Range("C5").Value = Time
.Range("C6").Value = "=R[-1]C-R[-2]C"
.Range("C6").NumberFormat = "[h]:mm:ss;@"
'Set the Borders for the Date & Time Cells
.Range("B3:C8").Borders(1).LineStyle = 1
.Range("B3:C8").Borders(2).LineStyle = 1
.Range("B3:C8").Borders(3).LineStyle = 1
.Range("B3:C8").Borders(4).LineStyle = 1
'Format the Date and Time Cells
.Range("B3:C8").Interior.ColorIndex = 40
.Range("B3:C8").Font.ColorIndex = 12
.Range("B3:A8").Font.Bold = True
'Track the Row Count and insrtuct the viewer not to disturb this
.Range("C7").AddComment
.Range("C7").Comment.Visible = False
.Range("C7").Comment.Text "This is a very Important field for the script." & vbCrLf & "Please Do not Edit or Delete."
.Range("C7").Value = "0"
.Range("B7").Value = "No Of Testcases:"
'Track the Testcase Count Count and insrtuct the viewer not to disturb this
.Range("C8").AddComment
.Range("C8").Comment.Visible = False
.Range("C8").Comment.Text "This is a very Important field for the script." & vbCrLf & "Please Do not Edit or Delete."
.Range("C8").Value = "0"
.Range("B8").Value = "Total No Of Test Steps:"
.Range("B10").Value = "TestCase Name"
.Range("C10").Value = "Status"
.Range("D10").Value = "No Of Steps"
.Range("E10").Value = "*Click the TestCase Name to see detail result."
'Format the Heading for the Result Summery
.Range("B10:D10").Interior.ColorIndex = 53
.Range("B10:D10").Font.ColorIndex = 19
.Range("B10:D10").Font.Bold = True
'Set the Borders for the Result Summery
.Range("B10:D10").Borders(1).LineStyle = 1
.Range("B10:D10").Borders(2).LineStyle = 1
.Range("B10:D10").Borders(3).LineStyle = 1
.Range("B10:D10").Borders(4).LineStyle = 1
'Set Column width
.Columns("B:D").Select
.Columns("B:D").Autofit
.Range("B11").Select
End With
'Freez pane
oEngine.ActiveWindow.FreezePanes = True
'Get the object of the first sheet in the workbook
Set objSheet = oEngine.Sheets.Item(2)
oEngine.Sheets.Item(1).Select
With objSheet
'Rename the first sheet to "Test_Result"
.Name = "Test_Result"
'Set the Column widths
.Columns("A:A").ColumnWidth = 30
.Columns("B:B").ColumnWidth = 8
.Columns("C:D").ColumnWidth = 35
.Columns("E:E").ColumnWidth = 35
.Columns("A:E").HorizontalAlignment = -4131
.Columns("A:E").WrapText = True
'Set the Heading for the Result Columns
.Range("A1").Value = "STEP NAME"
.Range("B1").Value = "STATUS"
.Range("C1").Value = "EXPECTED RESULT"
.Range("D1").Value = "ACTUAL RESULT"
.Range("E1").Value = "ERROR MESSAGE"
'Format the Heading for the Result Columns
.Range("A1:E1").Interior.ColorIndex = 53
.Range("A1:E1").Font.ColorIndex = 19
.Range("A1:E1").Font.Bold = True
'Set the Borders for the Result Header
.Range("A1:E1").Borders(1).LineStyle = 1
.Range("A1:E1").Borders(2).LineStyle = 1
.Range("A1:E1").Borders(3).LineStyle = 1
.Range("A1:E1").Borders(4).LineStyle = 1
' .Range("A2").Select
End With
'Freez pane
oEngine.ActiveWindow.FreezePanes = True
'Save the Workbook at the specified Path with the Specified Name
oEngine.ActiveWorkbook.saveas FilePath
'Relese the Object
Set objSheet = Nothing
End Function
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
''' <remarks>
''' <para> File = "C:\QTPLog.xls"</para>
''' <para>ClearExisting = True</para>
''' </remarks>
Private Sub Init_Settings
Set oSettings = CreateObject("Scripting.Dictionary")
oSettings.Add "File", "C:\QTPLog.xls" 'What is the log file?
oSettings.Add "ClearExisting", "True" 'Should we start a new log? True = Delete existing file.
End Sub
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the filter, False otherwise</returns>
Private Function AllowCreate
Dim bResult
bResult = CheckVersion
AllowCreate = bResult
End Function
'*************************************************************'
' Private Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the engine passes the version check, False otherwise</returns>
Private Function CheckVersion
Dim iDiff
Dim sEngineVersion
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
''' <value type="Array"/>
Dim ReplaceArray
''' <value type="Array"/>
Dim arrData, arrSettingData
''' <value type="Integer"/>
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize()
Set Manager = Nothing
Set oEngine = CreateObject("Excel.Application")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Init_Settings
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate
StopEngine
End Sub
End Class
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
''' <summary>
''' This Engine captures screenshots and saves them
''' </summary>
''' <author>Yaron Assa</author>
''' <datecreated>01/09/2007</datecreated>
''' <remarks>Possible Settings :
''' <para>
''' Path = String - Where to save the pictures. e.g. "C:\Logs. <br/>
''' Default = "C:\"
''' </para>
''' <para>
''' Prefix = How will the file names begin. e.g. "Error". File names always end with Time-Stamp<br/>
''' Default = "QTP Capture "
''' </para>
''' See settings details at <see cref="ScreenCaptureEngine.StartEngine"/>
''' </remarks>
''' <example><c>"Path>C:\Logs|Prefix>Error - "</c></example>
Class ScreenCaptureEngine
'Written by Yaron Assa, 1/8/07. Project home at www.AdvancedQTP.com
'This Engine captures screenshots and saves them
'Possible Settings :
'Path String - Where to save the pictures. e.g. "C:\Logs.
' Default = "C:\"
'
'Prefix String - How will the file names begin. e.g. "Error". File names always end with Time-Stamp
' Default = "QTP Capture "
'
'If the file already exists, the file name is appended with "_1"
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings
''' <value type="Scripting.FileSystemObject"/>
''' <summary>Holds the FileSystemObject for file manipulations</summary>
Private oFSO
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
''' <seealso cref="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' The user logical name for an instance of this engine (in run-time)
''' </summary>
''' <value type="String"/>
Public Name
''' <summary>
''' The Engine's Version
''' </summary>
''' <value type="String"/>
Public Property Get Version
Version = "0.9"
End Property
''' <summary>
''' The minimum version of the manager, required for this engine to work
''' </summary>
''' <value type="String"/>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.9"
End Property
''' <summary>
''' ID for the type of the engine
''' </summary>
''' <value type="String"/>
Public Property Get EngineType
EngineType = "ScreenCapture" 'ID
End Property
'*************************************************************'
' Function StartEngine (Public)
' Goal Makes the engine ready for use
' In Params sSettings - The Engine's init settings as "Field1>Value1|Field2>Value2|...
' Out Params Boolean - Didn't the engine manage to start?
'*************************************************************'
''' <summary>
''' Makes the engine ready for use
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...
''' <list type="table">
''' <item><term>Path</term>
''' <description>String - Where to save the pictures. e.g. "C:\Logs. <br/>
''' Default = "C:\"
''' </description></item>
''' <item><term>Prefix</term>
''' <description>String - How will the file names begin. e.g. "Error". File names always end with Time-Stamp<br/>
''' Default = "QTP Capture "
''' </description></item>
''' </list></param>
''' <returns type="Boolean">True if succeeded to start the engine, False if failed</returns>
''' <example><c>"Prefix>Error Screenshot - "</c></example>
Public Function StartEngine(sSettings)
''' <value type="String"/>
''' <summary>This will hold the file's containing folder</summary>
Dim ParentFolder
Set oFSO = CreateObject("Scripting.FileSystemObject")
Load_Settings(sSettings)
ParentFolder = oSettings("Path")
If Not oFSO.FolderExists(ParentFolder) Then MakePath ParentFolder
StartEngine = AllowCreate
End Function
'*************************************************************'
' Function StopEngine (Public)
' Goal Stops the engine
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Stops the engine
''' </summary>
Public Sub StopEngine
Set Manager = Nothing
Set oSettings = Nothing
Set oFSO = Nothing
End Sub
'*************************************************************'
' Sub Report (Public)
' Goal Reports an event
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params None
'*************************************************************'
''' <summary>
''' Reports an event
''' </summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status<note>Legacy suppurt for integer status code exists</note></param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
Public Sub Report (sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="String"/>
'''<summary>The file the screenshot will be saved to</summary>
Dim sFile
''' <value type="String"/>
'''<summary>Current time, stripped of all illegal chars</summary>
Dim sTimeStamp
sTimeStamp = CStr(Now)
sTimeStamp = Replace(sTimeStamp , "\", "")
sTimeStamp = Replace(sTimeStamp , "/", "")
sTimeStamp = Replace(sTimeStamp , ":", "")
sFile = oSettings("Path")
If Mid(sFile, Len(sFile),1) <> "\" Then sFile = sFile & "\"
sFile = sFile & oSettings("Prefix") &" " & sTimeStamp & ".png"
While oFSO.FileExists(sFile)
sFile = Mid(sFile ,1,Len(sFile)-4) & "_1" & ".png"
Wend
Desktop.CaptureBitmap(sFile)
End Sub
'**********************************************************************************************************************************
'Function Name: MakePath
'Description: This Function creates the result file in XLS format and formats the Header section
'Parameter: This function takes the following parameters
' sPath - Required path (must be fully qualified)
' Returns: True - Path now exists
' False - Path does not exist
'Created By: Sameer Girolkar
'Creation Date: 07-Dec-2005
'**********************************************************************************************************************************
''' <summary>
''' This Function creates the path for the screen cpatures
''' </summary>
''' <author>Sameer Girolkar</author>
''' <param name="sPath" type="String">Required path (must be fully qualified)</param>
''' <returns type="Boolean">True if the path now exists, False otherwise</returns>
Private Function MakePath(sPath)
' Default result
MakePath = False
' Fail if drive is not valid
If Not oFSO.DriveExists(oFSO.GetDriveName(sPath)) Then Exit Function
' Succeed if folder exists
If oFSO.FolderExists(sPath) Then
MakePath = True
Exit Function
End If
' Call self to ensure parent path exists
If Not MakePath(oFSO.GetParentFolderName(sPath)) Then Exit Function
' Create folder
On Error Resume Next
oFSO.CreateFolder sPath
MakePath = oFSO.FolderExists(sPath)
End Function
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
''' <remarks><para>Path = "C:\"</para>
''' <para>Prefix = "QTP Capture "</para>
''' </remarks>
Private Sub Init_Settings
Set oSettings = CreateObject("Scripting.Dictionary")
oSettings.Add "Path", "C:\"
oSettings.Add "Prefix", "QTP Capture "
End Sub
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the filter, False otherwise</returns>
Private Function AllowCreate
''' <value type="Boolean"/>
Dim bResult
bResult = CheckVersion
AllowCreate = bResult
End Function
'*************************************************************'
' Private Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the engine passes the version check, False otherwise</returns>
Private Function CheckVersion
''' <value type="Integer"/>
Dim iDiff
''' <value type="String"/>
Dim sEngineVersion
''' <value type="String"/>
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
''' <value type="Array"/>
Dim ReplaceArray
''' <value type="Array"/>
Dim arrData, arrSettingData
''' <value type="Integer"/>
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize() ' Setup Initialize event.
Set Manager = Nothing
Init_Settings
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate ' Setup Terminate event.
StopEngine
End Sub
End Class
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
''' <summary>
''' This engine reports to the windows event log
''' </summary>
''' <author>Yaron Assa</author>
''' <datecreated>01/09/2007</datecreated>
''' <remarks>Possible Settings :
''' <para>
''' LogName = String - The name of the log in the event-viewer. <br/>
''' Default = "QTP Log"
''' </para>
''' <para>
''' ShowAs = String - What will be the event's source in the log<br/>
''' Default = The current test's name
''' </para>
''' <para>
''' ClearExisting = Boolean - Should we earse the log?<br/>
''' Default = True
''' </para>
''' <para>
''' Computer = Log to local machine or to a remote computer?<br/>
''' Default = "." (local machine)
''' </para>
''' See settings details at <see cref="WinLogEngine.StartEngine"/>
''' </remarks>
''' <example><c>"Computer>192.168.0.1"</c></example>
Class WinLogEngine
'Written by Yaron Assa, 1/8/07. Project home at www.AdvancedQTP.com
'This engine reports to the windows event log
'Possible Settings :
' LogName = String - The name of the log in the event-viewer.
' Default = "QTP Log"
' ShowAs = String - What will be the event's source in the log
' Default = The current test's name
' ClearExisting = Boolean - Should we earse the log?
' Default = True
' Computer = Log to local machine or to a remote computer?
' Default = "." (local machine)
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings
''' <value type="System.Diagnostics.EventLog"/>
''' <summary>Will hold the win-log object</summary>
Private oEngine
''' <value type="System.Diagnostics.EventLogEntryType"/>
''' <summary>Will hold the win-log object' status list</summary>
Private oStatus
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
''' <seealso cref="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' The user logical name for an instance of this engine (in run-time)
''' </summary>
''' <value type="String"/>
Public Name
''' <summary>
''' ID for the type of the engine
''' </summary>
''' <value type="String"/>
Public Property Get EngineType
EngineType = "WinLog"
End Property
''' <summary>
''' The Engine's Version
''' </summary>
''' <value type="String"/>
Public Property Get Version
Version = "0.9"
End Property
''' <summary>
''' The minimum version of the manager, required for this engine to work
''' </summary>
''' <value type="String"/>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.9"
End Property
'*************************************************************'
' Function StartEngine (Public)
' Goal Makes the engine ready for use
' In Params sSettings - The Engine's init settings as "Field1>Value1|Field2>Value2|...
' Out Params Boolean - Didn't the engine manage to start?
'*************************************************************'
''' <summary>
''' Makes the engine ready for use
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...
''' <list type="table">
''' <item><term>LogName</term>
''' <description>String - The name of the log in the event-viewer. <br/>
''' Default = "QTP Log"
''' </description></item>
''' <item><term>ShowAs</term>
''' <description>String - What will be the event's source in the log<br/>
''' Default = The current test's name
''' </description></item>
''' <item><term>ClearExisting</term>
''' <description>Boolean - Should we earse the log?<br/>
''' Default = True
''' </description></item>
''' <item><term>Computer</term>
''' <description>Log to local machine or to a remote computer?<br/>
''' Default = "." (local machine)
''' </description></item>
''' </list></param>
''' <returns type="Boolean">True if succeeded to start the engine, False if failed</returns>
''' <example><c>"Computer>192.168.0.1"</c></example>
Public Function StartEngine(sSettings)
''' <value type="Boolean"/>
Dim bResult
''' <value type="String"/>
Dim sMachine
''' <value type="String"/>
Dim sSource
''' <value type="String"/>
Dim sLog
bResult = True
Load_Settings(sSettings)
sMachine = oSettings("Computer")
sLog = oSettings("LogName")
sSource = oSettings("ShowAs")
'On Error Resume Next
Set oStatus = DotNetFactory.CreateInstance("System.Diagnostics.EventLogEntryType")
Set oEngine = DotNetFactory.CreateInstance("System.Diagnostics.EventLog")
oEngine.Log = sLog
oEngine.Source = sSource
oEngine.MachineName = sMachine
On Error Resume Next
If oSettings("ClearExisting") = "True" Then _
If oEngine.Exists(sLog, sMachine) Then oEngine.Clear
If oEngine.SourceExists(sSource,sMachine) Then 'The source exists
If Not oEngine.LogNameFromSourceName(sSource, sMachine) = sLog Then
'The source is registered to another Log
bResult = False
Set oEngine = Nothing
End If
End If
On Error Goto 0
If Not oEngine.SourceExists(sSource, sMachine) Then _
Call oEngine.CreateEventSource(sSource, sLog, sMachine) 'Create the source in the log
If err.Number <> 0 Then
bResult = False
Set oEngine = Nothing
End If
On Error Goto 0
bResult = bResult And AllowCreate
StartEngine = bResult
End Function
'*************************************************************'
' Function StopEngine (Public)
' Goal Stops the engine
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Stops the engine
''' </summary>
Public Sub StopEngine
Set Manager = Nothing
If Not oEngine Is Nothing Then
If oEngine.SourceExists(oSettings("ShowAs"), oSettings("Computer")) Then _
Call oEngine.DeleteEventSource(oSettings("ShowAs"), oSettings("Computer") ) 'Unregister the source
End If
Set oEngine = Nothing
Set oSettings = Nothing
Set oStatus = Nothing
End Sub
'*************************************************************'
' Sub Report (Public)
' Goal Reports an event
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params None
'*************************************************************'
''' <summary>
''' Reports an event
''' </summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status<note>Legacy suppurt for integer status code exists</note></param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
Public Sub Report (sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="Integer"/>
Dim iStatus
''' <value type="String"/>
Dim sMessage
''' <value type="System.Diagnostics.EventLogEntryType"/>
Dim oCurrentStatus
Select Case sStatus
Case "Fail"
Set oCurrentStatus = oStatus.Error
Case "Warning"
Set oCurrentStatus = oStatus.Warning
Case Else
Set oCurrentStatus = oStatus.Information
End Select
sMessage = "Status = " & sStatus & vbCrLf & _
"Step = " & sStepName & vbCrLf & _
"Expected Result = " & sExpected & vbCrLf & _
"Actual Result = " & sActual & vbCrLf & _
"Details = " & sDetails & vbCrLf
Call oEngine.WriteEntry(sMessage, oCurrentStatus)
Set oCurrentStatus = Nothing
End Sub
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
''' <remarks><para>LogName = "QTP Log"</para>
''' <para>ShowAs = Current test</para>
''' <para>ClearExisting = True</para>
''' <para>Computer = "." (Local) </para>
''' </remarks>
Private Sub Init_Settings
Set oSettings = CreateObject("Scripting.Dictionary")
oSettings.Add "LogName", "QTP Log"
oSettings.Add "ShowAs", Environment("TestName")
oSettings.Add "ClearExisting", "True"
oSettings.Add "Computer", "."
End Sub
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the filter, False otherwise</returns>
Private Function AllowCreate
Dim bResult
bResult = CheckVersion
AllowCreate = bResult
End Function
'*************************************************************'
' Private Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the engine passes the version check, False otherwise</returns>
Private Function CheckVersion
Dim iDiff
Dim sEngineVersion
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize()
Set Manager = Nothing
Init_Settings
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate
StopEngine
End Sub
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
Dim ReplaceArray
Dim arrData, arrSettingData
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
End Class
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
''' <summary>
''' This Engine reports to any database ADODB can access
''' </summary>
''' <author>Yaron Assa</author>
''' <datecreated>01/09/2007</datecreated>
''' <remarks>Possible Settings :
''' <para>
''' ConnectionString = String - The database connectionstring text.<br/>
''' Default = "DBQ=C:\QTP Log.mdb;UID=admin;Driver={Microsoft Access Driver (*.mdb)}"
''' </para>
''' <para>
''' TableName = String - The DB Log Table Name.<br/>
''' Default = "Log"
''' </para>
''' <para>
''' CreateNew= True/False - Should we Create a new table (deleting existing). True = Erase.<br/>
''' Default = False
''' </para>
''' <para>
''' StepNameField = String - The DB fieldname for StepName.<br/>
''' Default = "StepName"
''' </para>
''' <para>
''' StatusField = String - The DB fieldname for Status.<br/>
''' Default = "Status"
''' </para>
''' <para>
''' ExpectedField = String - The DB fieldname for Expected result.<br/>
''' Default = "Expected"
''' </para>
''' <para>
''' ActualField = String - The DB fieldname for Actual result.<br/>
''' Default = "Actual"
''' </para>
''' <para>
''' DetailsField = String - The DB fieldname for Details.<br/>
''' Default = "Details"
''' </para>
''' <para>
''' TimeField = String - The DB fieldname for the event's time stamp.<br/>
''' Default = "EventTime"
''' </para>
''' <para>
''' If a field name is set to "", the field will not be reported, and if a new table is created, it will be created without the field's column<br/>
''' If you do not create a new table, the table you are using MUST include all the fields you've specified
''' </para>
''' See settings details at <see cref="DBEngine.StartEngine"/>
''' </remarks>
''' <example><c>"TableName>ERRORLOG|TimeField>TIMESTAMP"</c></example>
Class DBEngine
'Written by Yaron Assa, 1/8/07. Project home at www.AdvancedQTP.com
'This Engine reports to any database ADODB can access
'Possible Settings :
'ConnectionString String - The database connectionstring text.
' Default = "DBQ=C:\QTP Log.mdb;UID=admin;Driver={Microsoft Access Driver (*.mdb)}"
'TableName= String - The DB Log Table Name.
' Default = "Log"
'CreateNew= True/False - Should we Create a new table (deleting existing). True = Erase.
' Default = True
'StepNameField String - The DB fieldname for StepName.
' Default = "StepName"
'StatusField String - The DB fieldname for Status.
' Default = "Status"
'ExpectedField String - The DB fieldname for Expected Result.
' Default = "Expected"
'ActualField String - The DB fieldname for Actual Result.
' Default = "Actual"
'DetailsField String - The DB fieldname for Details.
' Default = "Details"
'TimeField String - The DB fieldname for the event's time stamp.
' Default = "EventTime"
'
'If a field name is set to "", the field will not be reported, and if a new table is created, it will be created without the field's column
'If you do not create a new table, the table you are using MUST include all the fields you've specified
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings
''' <value type="ADODB.Connection"/>
''' <summary>Holds the connection to the database</summary>
Private oEngine
''' <value type="ADODB.Recordset"/>
''' <summary>Holds a pointer to the relevant table</summary>
Private oRecordSet
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
''' <seealso cref="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' The user logical name for an instance of this engine (in run-time)
''' </summary>
''' <value type="String"/>
Public Name
''' <summary>
''' The Engine's Version
''' </summary>
''' <value type="String"/>
Public Property Get Version
Version = "0.9"
End Property
''' <summary>
''' The minimum version of the manager, required for this engine to work
''' </summary>
''' <value type="String"/>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.9"
End Property
''' <summary>
''' ID for the type of the engine
''' </summary>
''' <value type="String"/>
Public Property Get EngineType
EngineType = "DB"
End Property
'*************************************************************'
' Function StartEngine (Public)
' Goal Makes the engine ready for use
' In Params sSettings - The Engine's init settings as "Field1>Value1|Field2>Value2|...
' Out Params Boolean - Didn't the engine manage to start?
'*************************************************************'
''' <summary>
''' Makes the engine ready for use
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...
''' <list type="table">
''' <item><term>ConnectionString</term>
''' <description>String - The database connectionstring text.<br/>
''' Default = "DBQ=C:\QTP Log.mdb;UID=admin;Driver={Microsoft Access Driver (*.mdb)}"
''' </description></item>
''' <item><term>TableName</term>
''' <description>String - The DB Log Table Name.<br/>
''' Default = "Log"
''' </description></item>
''' <item><term>CreateNew</term>
''' <description>True/False - Should we Create a new table (deleting existing). True = Erase.<br/>
''' Default = False
''' </description></item>
''' <item><term>StepNameField</term>
''' <description>String - The DB fieldname for StepName.<br/>
''' Default = "StepName"
''' </description></item>
''' <item><term>StatusField</term>
''' <description>String - The DB fieldname for Status.<br/>
''' Default = "Status"
''' </description></item>
''' <item><term>ExpectedField</term>
''' <description>String - The DB fieldname for Expected result.<br/>
''' Default = "Expected"
''' </description></item>
''' <item><term>ActualField</term>
''' <description>String - The DB fieldname for Actual result.<br/>
''' Default = "Actual"
''' </description></item>
''' <item><term>DetailsField</term>
''' <description>String - The DB fieldname for Details.<br/>
''' Default = "Details"
''' </description></item>
''' <item><term>TimeField</term>
''' <description>String - The DB fieldname for the event's time.<br/>
''' Default = "EventTime"
''' </description></item>
''' </list></param>
''' <remarks>
''' If a field name is set to "", the field will not be reported, and if a new table is created, it will be created without the field's column<br/>
''' If you do not create a new table, the table you are using MUST include all the fields you've specified
''' </remarks>
''' <returns type="Boolean">True if succeeded to start the engine, False if failed</returns>
''' <example><c>"TableName>ERRORLOG|TimeField>TIMESTAMP"</c></example>
Public Function StartEngine(sSettings)
''' <value type="Boolean"/>
Dim bResult
Load_Settings(sSettings)
bResult = AllowCreate
If bResult = False Then
StartEngine = False
Exit Function
End If
On Error Resume Next
Set oEngine = CreateObject("ADODB.Connection")
Set oRecordSet = CreateObject("ADODB.RecordSet")
oEngine.ConnectionString = oSettings("ConnectionString")
oEngine.Open
If CBool(oSettings("CreateNew")) = True Then CreateNewTable
oRecordSet.Open oSettings("TableName"), oEngine, 3,3,2
If Err.Number <> 0 Then
StopEngine
bResult = False
End If
On Error Goto 0
StartEngine = bResult
End Function
'*************************************************************'
' Function StopEngine (Public)
' Goal Stops the engine
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Stops the engine
''' </summary>
Public Sub StopEngine
Set oSettings = Nothing
Set Manager = Nothing
On Error Resume Next
If Not oRecordSet Is Nothing Then _
If oRecordSet.State = 1 Then oRecordSet.Close
If Not oEngine Is Nothing Then _
If oEngine.State = 1 Then oEngine.Close
On Error Goto 0
Set oRecordSet = Nothing
Set oEngine = Nothing
End Sub
'*************************************************************'
' Sub Report (Public)
' Goal Reports an event
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params None
'*************************************************************'
''' <summary>
''' Reports an event
''' </summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status<note>Legacy suppurt for integer status code exists</note></param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
Public Sub Report (sStatus, sStepName,sExpected,sActual, sDetails)
On Error Resume Next
oRecordSet.AddNew
If oSettings("TimeField") <> "" Then _
oRecordSet(UCase(oSettings("TimeField"))) = Now
If oSettings("StatusField") <> "" Then _
oRecordSet(UCase(oSettings("StatusField"))) = sStatus
If oSettings("StepNameField") <> "" Then _
oRecordSet(UCase(oSettings("StepNameField"))) = sStepName
If oSettings("ExpectedField") <> "" Then _
oRecordSet(UCase(oSettings("ExpectedField"))) = sExpected
If oSettings("ActualField") <> "" Then _
oRecordSet(UCase(oSettings("ActualField"))) = sActual
If oSettings("DetailsField") <> "" Then _
oRecordSet(UCase(oSettings("DetailsField"))) = sDetails
oRecordSet.Update
If Err.Number<>0 Then
Reporter.ReportEvent micFail, "Report via DB reporter", "An Error Occured"
End If
End Sub
'*************************************************************'
' Sub CreateNewTable (Private)
' Goal Creates a new table in the database
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Creates a new table in the database
''' </summary>
Private Sub CreateNewTable
''' <value type="String"/>
Dim sCreate
'Delete Existing
On Error Resume Next
oEngine.Execute "DROP TABLE " & oSettings("TableName") & ";"
On Error Goto 0
sCreate = "CREATE TABLE " & UCase(oSettings("TableName")) & " ("
If oSettings("TimeField") <> "" Then sCreate = sCreate & UCase(oSettings("TimeField")) & " DATETIME NOT NULL, "
If oSettings("StatusField") <> "" Then sCreate = sCreate & UCase(oSettings("StatusField")) & " VARCHAR(255) NOT NULL, "
If oSettings("StepNameField") <> "" Then sCreate = sCreate & UCase(oSettings("StepNameField")) & " VARCHAR(255) NOT NULL, "
If oSettings("ExpectedField") <> "" Then sCreate = sCreate & UCase(oSettings("ExpectedField")) & " VARCHAR(255) NOT NULL, "
If oSettings("ActualField") <> "" Then sCreate = sCreate & UCase(oSettings("ActualField")) & " VARCHAR(255) NOT NULL, "
If oSettings("DetailsField") <> "" Then sCreate = sCreate & UCase(oSettings("DetailsField")) & " VARCHAR(255) NOT NULL, "
sCreate = Mid(sCreate, 1, Len(sCreate) -2) 'Remove last ","
sCreate = sCreate & ");"
oEngine.Execute sCreate
End Sub
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
''' <remarks><para>ConnectionString = "DBQ=C:\QTP Log.mdb;UID=admin;Driver={Microsoft Access Driver (*.mdb)}"</para>
''' <para>TableName = "Log"</para>
''' <para>CreateNew = False</para>
''' <para>StepNameField = "StepName"</para>
''' <para>StatusField = "Status"</para>
''' <para>ExpectedField = "Expected"</para>
''' <para>ActualField = "Actual"</para>
''' <para>DetailsField = "Details"</para>
''' <para>TimeField = "EventTime" </para>
''' </remarks>
Private Sub Init_Settings
Set oSettings = CreateObject("Scripting.Dictionary")
oSettings.Add "ConnectionString", "DBQ=C:\QTP Log.mdb;UID=admin;Driver={Microsoft Access Driver (*.mdb)}"
'Open a default access DB
oSettings.Add "TableName", "Log"
oSettings.Add "CreateNew", "False"
oSettings.Add "StepNameField", "StepName"
oSettings.Add "StatusField", "Status"
oSettings.Add "ExpectedField", "Expected"
oSettings.Add "ActualField", "Actual"
oSettings.Add "DetailsField", "Details"
oSettings.Add "TimeField", "EventTime"
End Sub
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the filter, False otherwise</returns>
Private Function AllowCreate
Dim bResult
bResult = CheckVersion
AllowCreate = bResult
End Function
'*************************************************************'
' Private Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the engine passes the version check, False otherwise</returns>
Private Function CheckVersion
Dim iDiff
Dim sEngineVersion
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
''' <value type="Array"/>
Dim ReplaceArray
''' <value type="Array"/>
Dim arrData, arrSettingData
''' <value type="Integer"/>
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize() ' Setup Initialize event.
Set Manager = Nothing
Init_Settings
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate ' Setup Terminate event.
StopEngine
End Sub
End Class
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
''' <summary>
''' This engine reports via XML
''' </summary>
''' <author>Yaron Assa</author>
''' <datecreated>20/01/2008</datecreated>
''' <remarks>Possible Settings :
''' <para>
''' File = String - the log file path and name. (e.g. "C:\LogFile.xml")<br/>
''' Default = "C:\QTPLog.xml"
''' </para>
''' <para>
''' AutoSave = Integer - Save data to file every X minutes. e.g. 2<br/>
''' Default = 0<br/>
''' Higher values = better performance<br/>
''' Lower values = better robustness (if QTP gets stuck, less data is lost)
''' </para>
''' <para>
''' ClearExisting = True/False - Should we erase the existing log. True = Erase.<br/>
''' Default = True
''' </para>
''' <para>
''' StyleSheet = String - Path and name of the XSL stylesheet for the log.<br/>
''' If value = "", no stylesheet instruction will be added<br/>
''' Default = "C:\QTPLog.XSL"
''' <tip>a default QTPLog.XSL is supplied with the project files</tip>
''' </para>
''' See settings details at <see cref="XMLEngine.StartEngine"/>
''' <warning>If you use the default stylesheet, you must place it under C:\<br/>
''' Or change the stylesheet path via the StyleSheet parameter</warning>
''' </remarks>
''' <example><c>"File>C:\Logs\Errors.xml"</c></example>
Class XMLEngine
'This Engine writes the log to an XML file
'Possible Settings :
'File String - Where to save the XML log. e.g. "C:\Logs\Log.XML".
' Default = "C:\QTPLog.XML"
'AutoSave Integer - Save data to file every X minutes. e.g. 2
' Default = 0 (every report re-saves the file)
' Higher values = better performance
' Lower values = better robustness (if QTP gets stuck, less data is lost)
'ClearExisting True/False - Should we erase the existing log. True = Erase.
' Default = True
'StyleSheet String - Path and name of the XSL stylesheet for the log.<br/>
' Default = "C:\QTPLog.XSL"
' If value = "", no stylesheet instruction will be added
' a default QTPLog.XSL is supplied with the project files
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' The user logical name for an instance of this engine (in run-time)
''' </summary>
''' <value type="String"/>
Public Name
''' <value type="Scripting.FileSystemObject"/>
''' <summary>Used to created directories and check files' existance</summary>
Private oFSO
''' <value type="Integer"/>
''' <summary>Used to measure intervals between disk-writes of the log</summary>
Private iTimer
''' <value type="Integer"/>
''' <summary>Used to detect changes in test iteration</summary>
Private iCurrentIteration
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings
''' <value type="System.XML.XMLDocument"/>
''' <summary>Holds the engine's main object</summary>
Private oEngine 'Holds the engine's main object
''' <value type="System.XML.XMLElement"/>
''' <summary>Holds the XML root element of the current log</summary>
Private oRoot
''' <value type="System.Xml.XmlNodeType"/>
''' <summary>Used to create different types of XML nodes</summary>
Private iNodeType
''' <summary>
''' ID for the type of the engine
''' </summary>
''' <value type="String"/>
''' <example>"DB"</example>
Public Property Get EngineType
EngineType = "XML" 'Add Engine Type Here
End Property
''' <summary>
''' The Engine's Version
''' </summary>
''' <value type="String"/>
''' <example>"0.8"</example>
Public Property Get Version
Version = "9.2" 'Change to the engine version. Must be 9+
End Property
''' <summary>
''' The minimum version of the manager, required for this engine to work
''' </summary>
''' <value type="String"/>
''' <example>"0.8"</example>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.9" 'The minimum version of the manager, required for this engine to work
End Property
'*************************************************************'
' Function StartEngine (Public)
' Goal Makes the engine ready for use
' In Params sSettings - The Engine's init settings as "Field1>Value1|Field2>Value2|...
' Out Params Boolean - Didn't the engine manage to start?
'*************************************************************'
''' <summary>
''' Makes the engine ready for use
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...
''' <list type="table">
''' <item><term>File</term>
''' <description>String - the log file path and name. (e.g. "C:\LogFile.xml")<br/>
''' Default = "C:\QTPLog.xml"
''' </description></item>
''' <item><term>AutoSave</term>
''' <description>Integer - Save data to file every X minutes. e.g. 2<br/>
''' Default = 0<br/>
''' Higher values = better performance<br/>
''' Lower values = better robustness (if QTP gets stuck, less data is lost)
''' </description></item>
''' <item><term>ClearExisting</term>
''' <description>True/False - Should we erase the existing log. True = Erase.<br/>
''' Default = True
''' </description></item>
''' <item><term>StyleSheet</term>
''' <description>String - Path and name of the XSL stylesheet for the log.<br/>
''' Default = C:\QTPLog.XSL
''' If value = "", no stylesheet instruction will be added<br/>
''' <tip>a default QTPLog.XSL is supplied with the project files</tip>
''' </description></item>
''' </list></param>
''' <remarks>
''' <warning>If you use the default stylesheet, you must place it under C:\<br/>
''' Or change the stylesheet path via the StyleSheet parameter</warning>
'''</remarks>
''' <returns type="Boolean">True if succeeded to start the engine, False if failed</returns>
''' <example><c>"File>C:\Logs\Errors.xml|AutoSave>1"</c></example>
Public Function StartEngine(sSettings)
''' <value type="String"/>
''' <summary>This will hold the file's containing folder</summary>
Dim ParentFolder
''' <value type="Boolean"/>
Dim bCreateNew
bCreateNew = False
Load_Settings(sSettings)
Set oEngine = DotNetFactory.CreateInstance("System.Xml.XmlDocument")
Set iNodeType = DotNetFactory.CreateInstance("System.Xml.XmlNodeType")
'Should we delete the file?
If CBool(oSettings("ClearExisting")) = True Then bCreateNew = True
'Is the file valid?
If bCreateNew = False Then
On Error Resume Next
'Try to read the file
oEngine.Load(oSettings("File"))
If err.Number<> 0 Then
bCreateNew = True
Reporter.ReportEvent micWarning, "Create XML Report", "File corrupted, overwriting" & vbCrLf & _
"File = " & oSettings("File")
End If
On Error Goto 0
End If
'Create the log file if needed
If bCreateNew = True Then
If oFso.FileExists(oSettings("File")) Then oFSO.DeleteFile(oSettings("File"))
ParentFolder = oFSO.GetParentFolderName(oSettings("File"))
If Not oFSO.FolderExists(ParentFolder) Then
MakePath ParentFolder
End If
'Add StyleSheet information
If oSettings("StyleSheet") <> "" Then
Call oEngine.AppendChild(oEngine.CreateProcessingInstruction("xml-stylesheet", "href='" & oSettings("StyleSheet") & "' type='text/xsl'"))
If Not oFso.FileExists(oSettings("StyleSheet")) Then _
Reporter.ReportEvent micWarning, "Stylesheet not found", "The stylesheet you've specified (" & oSettings("StyleSheet") & ") doesn't exist." & vbCrLf & _
"If you're using the default stylesheet, make sure you copy the supplied QTPLog.XLS file to " & oSettings("StyleSheet")
End If
'Set document root
Call oEngine.AppendChild(oEngine.CreateNode(iNodeType.Element, "QTPLogs", ""))
End If
Set oRoot = oEngine.CreateNode(iNodeType.Element, "QTPLog", "")
oRoot.Attributes.Append(oEngine.CreateAttribute("Start"))
oRoot.Attributes.GetNamedItem("Start").Value = CStr(Now)
oRoot.Attributes.Append(oEngine.CreateAttribute("Status"))
oRoot.Attributes.GetNamedItem("Status").Value = "Pass"
oRoot.Attributes.Append(oEngine.CreateAttribute("TestName"))
oRoot.Attributes.GetNamedItem("TestName").Value = Environment.Value("TestName")
Call oEngine.DocumentElement.AppendChild(oRoot)
oEngine.Save(oSettings("File"))
StartEngine = AllowCreate
End Function
'*************************************************************'
' Function StopEngine (Public)
' Goal Stops the engine
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Stops the engine
''' </summary>
Public Sub StopEngine
On Error Resume Next
If Not oEngine Is Nothing Then
oRoot.Attributes.Append(oEngine.CreateAttribute("End"))
oRoot.Attributes.GetNamedItem("End").Value = CStr(Now)
oEngine.Save(oSettings("File"))
End If
On Error Goto 0
Set oRoot = Nothing
Set oEngine = Nothing
Set oSettings = Nothing
Set oFSO = Nothing
'More engine stop code here
End Sub
'*************************************************************'
' Sub Report (Public)
' Goal Reports an event
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params None
'*************************************************************'
''' <summary>
''' Reports an event to all possible reporters
''' </summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status</param>
''' <paramlist name="StatusType">
''' <item>"Fail"<description>The Step Failed</description></item>
''' <item>"Pass"<description>The Step Passed</description></item>
''' <item>"Warning"<description>A Warning</description></item>
''' <item>"General"<description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
Public Sub Report (sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="System.XML.XMLElement"/>
Dim oStep, oElement, oIteration
'Add new Iteration Node
If iCurrentIteration <> Int(Environment.Value("TestIteration")) Then
iCurrentIteration = Int(Environment.Value("TestIteration"))
Set oIteration = oEngine.CreateNode(iNodeType.Element, "Iteration", "")
Call oIteration.Attributes.Append(oEngine.CreateAttribute("Status"))
oIteration.Attributes.GetNamedItem("Status").Value = "Pass"
Call oIteration.Attributes.Append(oEngine.CreateAttribute("Number"))
oIteration.Attributes.GetNamedItem("Number").Value = CStr(iCurrentIteration)
Call oIteration.Attributes.Append(oEngine.CreateAttribute("Start"))
oIteration.Attributes.GetNamedItem("Start").Value = CStr(Now)
Call oRoot.AppendChild(oIteration)
Else
Set oIteration = oRoot.LastChild
End If
'Update iteration status. Only way to go is Pass -> Warning -> Fail
If oIteration.Attributes.GetNamedItem("Status").Value <> "Fail" Then
If sStatus <> "Pass" Then oIteration.Attributes.GetNamedItem("Status").Value = sStatus
End If
'Update test status. Only way to go is Pass -> Warning -> Fail
If oRoot.Attributes.GetNamedItem("Status").Value <> "Fail" Then
If sStatus <> "Pass" Then oRoot.Attributes.GetNamedItem("Status").Value = sStatus
End If
'Create Step node
Set oStep = oEngine.CreateNode(iNodeType.Element, "Step", "")
'Add childnodes for each report-property
Set oElement = oEngine.CreateNode(iNodeType.Element, "Status", "")
Call oElement.AppendChild(oEngine.CreateNode(iNodeType.CDATA, "Status", ""))
oElement.ChildNodes.Item(0).Value = sStatus
oStep.AppendChild(oElement)
Set oElement = oEngine.CreateNode(iNodeType.Element, "StepName", "")
Call oElement.AppendChild(oEngine.CreateNode(iNodeType.CDATA, "StepName", ""))
oElement.ChildNodes.Item(0).Value = sStepName
oStep.AppendChild(oElement)
Set oElement = oEngine.CreateNode(iNodeType.Element, "Expected", "")
Call oElement.AppendChild(oEngine.CreateNode(iNodeType.CDATA, "Expected", ""))
oElement.ChildNodes.Item(0).Value = sExpected
oStep.AppendChild(oElement)
Set oElement = oEngine.CreateNode(iNodeType.Element, "Actual", "")
Call oElement.AppendChild(oEngine.CreateNode(iNodeType.CDATA, "Actual", ""))
oElement.ChildNodes.Item(0).Value = sActual
oStep.AppendChild(oElement)
Set oElement = oEngine.CreateNode(iNodeType.Element, "Details", "")
Call oElement.AppendChild(oEngine.CreateNode(iNodeType.CDATA, "Details", ""))
oElement.ChildNodes.Item(0).Value = sDetails
oStep.AppendChild(oElement)
Set oElement = oEngine.CreateNode(iNodeType.Element, "Time", "")
Call oElement.AppendChild(oEngine.CreateNode(iNodeType.CDATA, "Time", ""))
oElement.ChildNodes.Item(0).Value = CStr(Now)
oStep.AppendChild(oElement)
Call oIteration.AppendChild(oStep)
'Check if we need to write the log to the external file
If Abs(Timer-iTimer)/60 > CDbl(oSettings("AutoSave")) Then
oEngine.Save(oSettings("File"))
iTimer = Timer
End If
End Sub
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
''' <remarks>
''' <para> File = "C:\QTPLog.xml" </para>
''' <para> AutoSave = 0 </para>
''' <para> ClearExisting = True </para>
''' <para> StyleSheet = "C:\QTPLog.XSL" </para>
''' </remarks>
Private Sub Init_Settings
Set oSettings = CreateObject("Scripting.Dictionary")
oSettings.Add "File", "C:\QTPLog.XML"
oSettings.Add "AutoSave", 0
oSettings.Add "ClearExisting", True
oSettings.Add "StyleSheet", "C:\QTPLog.XSL"
End Sub
'**********************************************************************************************************************************
'Function Name: MakePath
'Description: This Function creates the result file in XLS format and formats the Header section
'Parameter: This function takes the following parameters
' sPath - Required path (must be fully qualified)
' Returns: True - Path now exists
' False - Path does not exist
'Created By: Sameer Girolkar
'Creation Date: 07-Dec-2005
'**********************************************************************************************************************************
''' <summary>
''' This Function creates the result file
''' </summary>
''' <author>Sameer Girolkar</author>
''' <param name="sPath" type="String">Required path (must be fully qualified)</param>
''' <returns type="Boolean">True if the path now exists, False otherwise</returns>
Private Function MakePath(sPath)
' Default result
MakePath = False
' Fail if drive is not valid
If Not oFso.DriveExists(oFso.GetDriveName(sPath)) Then Exit Function
' Succeed if folder exists
If oFso.FolderExists(sPath) Then
MakePath = True
Exit Function
End If
' Call self to ensure parent path exists
If Not MakePath(oFso.GetParentFolderName(sPath)) Then Exit Function
' Create folder
On Error Resume Next
oFso.CreateFolder sPath
MakePath = oFso.FolderExists(sPath)
End Function
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the engine, False otherwise</returns>
Private Function AllowCreate
''' <value type="Boolean"/>
Dim bResult
bResult = CheckVersion
'Add more pass/fail conditions here
AllowCreate = bResult
End Function
'*************************************************************'
' Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the engine passes the version check, False otherwise</returns>
Function CheckVersion
''' <value type="Integer"/>
Dim iDiff
''' <value type="String"/>
Dim sEngineVersion
''' <value type="String"/>
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(iDiff, "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize()
Set oFSO = CreateObject("Scripting.FileSystemObject")
iCurrentIteration = 0 'Make sure there will be a node for the first iteration
Init_Settings
'Add Initialization events here
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate
StopEngine
'Add Terminate Events Here
End Sub
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Engine's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
''' <value type="Array"/>
Dim ReplaceArray
''' <value type="Array"/>
Dim arrData, arrSettingData
''' <value type="Integer"/>
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
End Class
------------------------------------------------------------------------------------------Filters.VBS------------------------------------------------------------------------------------------
'''<summary>This file holds all the different filter classes</summary>
''' <datecreated>01/09/2007</datecreated>
'''<version>0.9</version>
Option Explicit
'**********************************************************************'
' Filters
'**********************************************************************'
''' <summary>
''' This filter performs Regular Expressions searches within the event's data
''' </summary>
''' <remarks>
''' Possible Settings :
''' <para>
''' Include = True/False. A success is finding the RegEx (True) or NOT finding it (False)<br/>
''' Default = True
''' </para>
''' <para>
''' WhatToSearch = "Value1,Value2,....", where ValueX = one of Status/StepName/Expected/Actual/Details<br/>
''' In what parts of the event to report should we search for the RegEx<br/>
''' Default = "Status, StepName, Expected, Actual, Details" (all of them)
''' </para>
''' <para>
''' IgnoreCase = True/False. Should we ignore String Case In our searchs<br/>
''' Default = True (ignore case)
''' </para>
''' <para>
''' Pattern = String. The RegEx pattern to seach (e.g. ".*Error.*")<br/>
''' Default = ".*" (Success = any string)<br/>
''' Remember to use || instead of | if your patten includes this char. e.g. use "Pattern>Fail||Warning|IgnoreCase>True"
''' </para>
''' See settings details at <see cref="RegExFilter.StartFilter"/>
''' </remarks>
''' <example><c>"Include>False|WhatToSearch>Status|Pattern>.*Warning.*"</c>- his will filter OUT all events with status = Warning (because Include = False)</example>
Class RegExFilter
'Written by Yaron Assa, 1/8/07. Project home at www.AdvancedQTP.com
'This filter performs Regular Expressions searches within the event's data
'Possible Settings :
'Include = True/False. A success is finding the RegEx (True) or NOT finding it (False)
' Default = True
'WhatToSearch = "Value1, Value2, ....", where ValueX = one of Status/StepName/Expected/Actual/Details
' In what parts of the event to report should we search for the RegEx
' Default = "Status, StepName, Expected, Actual, Details" (all of them)
'IgnoreCase = True/False. Should we ignore string case in our searchs
' Default = True (ignore case)
'Pattern = String. The RegEx pattern to seach (e.g. ".*Error.*")
' Default = ".*" (Success = any string)
' Remember to use || instead of | if your patten includes this char. e.g. use "Pattern>Fail||Warning|IgnoreCase>True"
'
'E.g. : "Include>False|WhatToSearch>Status|Pattern>.*Warning.*"
'This will filter OUT all events with status = Warning (because Include = False)
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings 'Will hold the settings dictionary
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
''' <seealso cref="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' Holds a link to the relevant engine
''' </summary>
''' <value type="XEngine"/>
Public Engine 'Holds a link to the relevant engine
''' <summary>
''' The Filter's Version
''' </summary>
''' <value type="String"/>
Public Property Get Version
Version = "0.9"
End Property
''' <summary>
''' The minimum version of the manager, required for this filter to work
''' </summary>
''' <value type="String"/>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.8"
End Property
''' <summary>
''' ID for the ''' Type of the Filter
''' </summary>
''' <value type="String"/>
Public Property Get FilterType 'For ID
FilterType = "RegEx"
End Property
'*************************************************************'
' Function StartFilter (Public)
' Goal Makes the filter ready for use
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Makes the filter ready for use
''' </summary>
''' <param name="sSettings" type="String">The Filter's init settings as "Field1>Value1|Field2>Value2|...
''' <list type="table">
''' <item><term>Include</term>
''' <description>True/False. A success is finding the RegEx (True) or NOT finding it (False)<br/>
''' Default = True
''' </description></item>
''' <item><term>WhatToSearch</term>
''' <description>"Value1, Value2, ....", where ValueX = one of Status/StepName/Expected/Actual/Details<br/>
''' In what parts of the event to report should we search for the RegEx<br/>
''' Default = "Status, StepName, Expected, Actual, Details" (all of them)
''' </description></item>
''' <item><term>IgnoreCase</term>
''' <description>True/False. Should we ignore string case in our searchs<br/>
''' Default = True (ignore case)
''' </description></item>
''' <item><term>Pattern</term>
''' <description>String. The RegEx pattern to seach (e.g. ".*Error.*")<br/>
''' Default = ".*" (everything)<br/>
''' Remember to use || instead of | if your patten includes this char. e.g. use "Pattern>Fail||Warning|IgnoreCase>True"
''' </description></item>
''' </list></param>
''' <returns type="Boolean">True if succeeded to start the filter, False if failed</returns>
''' <example><c>"Include>False|WhatToSearch>Status|Pattern>.*Warning.*"</c>- his will filter OUT all events with status = Warning (because Include = False)</example>
Public Function StartFilter(sSettings)
Load_Settings(sSettings)
StartFilter = AllowCreate
End Function
'*************************************************************'
' Function Check (Public)
' Goal Checks if an event matches the filter's criteria
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params Boolean - Does it match the criteria? If = True means the event will be reported
'*************************************************************'
''' <summary>Checks if an event matches the filter's criteria</summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status</param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
''' <returns type="Boolean">Returns True if the event matches, otherwise False</returns>
Public Function Check(sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="Boolean"/>
Dim bResult
''' <value type="Array"/>
Dim arrWhatToSearch
''' <value type="Boolean"/>
Dim bInclude
''' <value type="String"/>
Dim sPattern
''' <value type="Integer"/>
Dim iMatches
''' <value type="Integer"/>
Dim i
''' <value type="String"/>
Dim sSearch
'In what parts of the event should the RegEx Search
arrWhatToSearch = Split(oSettings("WhatToSearch"), ",")
'Include = True -> A success is finding the RegEx.
'Include = False -> A success is NOT finding the RegEx.
bInclude = CBool(oSettings("Include"))
'What RegEx to search
sPattern = oSettings("Pattern")
For i = 0 To UBound(arrWhatToSearch)
Execute "sSearch = s" & Trim(arrWhatToSearch(i)) 'Get the name of the part's variable
iMatches = DoRegEx(sPattern, sSearch) 'Do RegEx Search
bResult = iMatches > 0 'DId we find anything?
If bInclude = False Then bResult = Not bResult 'Include = False reverses the success criteria
If (bResult = False) And (bInclude=False) Then Exit For 'One wrong find is enough to fail the filter
If (bResult = True) And (bInclude=True) Then Exit For 'One find is enough to pass the filter
Next
Check = bResult
End Function
'*************************************************************'
' Function DoRegEx (Private)
' Goal Does the actual RegEx search
' In Params patrn - The RegEx pattern (e.g. ".*Error,*")
' strng - What to search in
' Out Params Integer - The number of matches
'*************************************************************'
''' <summary>
''' Does the actual RegEx search
''' </summary>
''' <param name="patrn" type="String">The RegEx pattern (e.g. ".*Error,*")</param>
''' <param name="strng" type="String">The string to be searched</param>
''' <returns type="Integer">The number of matches</returns>
Private Function DoRegEx(patrn, strng)
'A helper function for Check
''' <value type="RegExp"/>
Dim regEx
''' <value type="Matches"/>
Dim oMatches
Set regEx = New RegExp
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = CBool(oSettings("IgnoreCase"))
regEx.Global = False '
Set oMatches = regEx.Execute(strng) ' Execute search.
DoRegEx = oMatches.Count
End Function
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
''' <remarks><para>Include = True</para>
''' <para>IgnoreCase = True</para>
''' <para>WhatToSearch = "Status,StepName,Expected,Actual,Details"</para>
''' <para>Pattern = ".*" </para>
''' </remarks>
Private Sub Init_Settings 'Inits the filter's default settings
Set oSettings = CreateObject("Scripting.Dictionary")
oSettings.Add "Include", "True" 'Success is when the string is found (positive search)
oSettings.Add "IgnoreCase", "True" 'Ignore string case (e.g. "Name" is a match for "name")
oSettings.Add "WhatToSearch", "Status,StepName,Expected,Actual,Details" 'Seach evety part of the event
oSettings.Add "Pattern", ".*" 'The RegEx pattern to seach
End Sub
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the filter, False otherwise</returns>
Private Function AllowCreate
''' <value type="Boolean"/>
Dim bResult
bResult = CheckVersion
AllowCreate = bResult
End Function
'*************************************************************'
' Private Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the filter passes the version check, False otherwise</returns>
Private Function CheckVersion
''' <value type="Integer"/>
Dim iDiff
''' <value type="String"/>
Dim sEngineVersion
''' <value type="String"/>
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(Abs(iDiff), "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(Abs(iDiff), "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Filter's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
''' <value type="Array"/>
Dim ReplaceArray
''' <value type="Array"/>
Dim arrData, arrSettingData
''' <value type="Integer"/>
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize() ' Setup Initialize event.
Init_Settings
Set Manager = Nothing
Set Engine = Nothing
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate ' Setup Terminate event.
Set oSettings = Nothing
Set Manager = Nothing
Set Engine = Nothing
End Sub
''' <summary>
''' Stops the current filter and clears it
''' </summary>
Public Sub ClearFilter
Class_Terminate
End Sub
End Class
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
'**************************************************************************************************************************************************************************************
''' <summary>
''' This filter screens event according to an object's condition
''' </summary>
''' <remarks>
''' Possible Settings :
''' <para>
''' ObjectProperty = String. A REPRESENTATION of an object property (QTP or other). e.g. " VBWindow(""vbname:=Something"").Exist "<br/>
''' For negative conditions use NOT. e.g. : " Not VBWindow(""vbname:=Something"").Exist "<br/>
''' ONLY USE DP, not OR objects. You can use any VBScript command that can be properly represented. Access RO properties etc.<br/>
''' . e.g "Trim(VBWindow(""vbname:=Something"").Object.Date)"<br/>
''' Default = None
''' </para>
''' <para>
''' Value = String. The wanted property of the value<br/>
''' Default = None
''' </para>
''' <para>
''' Condition = Boolean. True -> a match is considered a success.<br/>
''' False -> a match is considered a failture<br/>
''' e.g. "ObjectProperty>Window(""name:=x"").getTOProperty(""text"")|Value>Notepad|Condition>False"<br/>
''' This will FAIL if the window's text = "Notepad", and will PASS if it's anything else
''' </para>
''' See settings details at <see cref="ObjectPropertyFilter.StartFilter"/>
''' </remarks>
''' <example><c>"ObjectProperty>VBWindow(""vbname:=Something"").Exist|Value>True"</c> - This will only report events when the window does exist </example>
Class ObjectPropertyFilter
'Written by Yaron Assa, 1/8/07. Project home at www.AdvancedQTP.com
'This filter screens event according to an object's condition
'Please Notice – When using this filter, make sure your QTP object sync timeout is LOW (i.e. 1 / 2 sec.)
'(Otherwise the script execution time will increase significantly)
'Possible Settings :
'ObjectProperty = String. A REPRESENTATION of an object property (QTP or other). e.g. " VBWindow(""vbname:=Something"").Exist "
' For negative conditions use NOT. e.g. : " Not VBWindow(""vbname:=Something"").Exist "
' ONLY USE DP, not OR objects. You can use any VBScript command that can be properly represented. Access RO properties etc.
' . e.g "Trim(VBWindow(""vbname:=Something"").Object.Date)"
' Default = None.
'Value = String. The wanted property of the value
' Default = None
'Condition = Boolean. True -> a match is considered a success.
' False -> a match is considered a failture
' e.g. "ObjectProperty>Window(""name:=x"").getTOProperty(""text"")|Value>Notepad|Condition>False"
' This will FAIL if the window's text = "Notepad", and will PASS if it's anything else
' Default = True
'
'E.g. : "ObjectProperty>VBWindow(""vbname:=Something"").Exist|Value>True"
'This will only report events when the window does exist
''' <value type="Scripting.Dictionary"/>
''' <summary>Will hold the settings dictionary</summary>
Private oSettings 'Will hold the settings dictionary
''' <summary>
''' Holds a link to the reporter manager
''' </summary>
''' <value type="ReporterManagerClass"/>
''' <seealso cref="ReporterManagerClass"/>
Public Manager 'Holds a link to the reporter manager
''' <summary>
''' Holds a link to the relevant engine
''' </summary>
''' <value type="XEngine"/>
Public Engine 'Holds a link to the relevant engine
''' <summary>
''' ID for the type of the filter
''' </summary>
''' <value type="String"/>
''' <example>"DB"</example>
Public Property Get FilterType 'For ID
FilterType = "ObjectProperty"
End Property
''' <summary>
''' The Engine's Version
''' </summary>
''' <value type="String"/>
''' <example>"0.8"</example>
Public Property Get Version
Version = "0.9"
End Property
''' <summary>
''' The minimum version of the manager, required for this filter to work
''' </summary>
''' <value type="String"/>
''' <example>"0.8"</example>
Public Property Get MinimunManagerVersion
MinimunManagerVersion = "0.8"
End Property
'*************************************************************'
' Function StartFilter (Public)
' Goal Makes the filter ready for use
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Makes the filter ready for use
''' </summary>
''' <param name="sSettings" type="String">The Filter's init settings as "Field1>Value1|Field2>Value2|...
''' <list type="table">
''' <item><term>ObjectProperty</term>
''' <description>String. A REPRESENTATION of an object property (QTP or other). e.g. " VBWindow(""vbname:=Something"").Exist "<br/>
''' For negative conditions use NOT. e.g. : " Not VBWindow(""vbname:=Something"").Exist "<br/>
''' ONLY USE DP, not OR objects. You can use any VBScript command that can be properly represented. Access RO properties etc.<br/>
''' . e.g "Trim(VBWindow(""vbname:=Something"").Object.Date)"<br/>
''' Default = None
''' </description></item>
''' <item><term>Value</term>
''' <description>String. The wanted property of the value<br/>
''' Default = None
''' </description></item>
''' <item><term>Condition</term>
''' <description>Boolean. True -> a match is considered a success.<br/>
''' False -> a match is considered a failture <br/>
''' e.g. "ObjectProperty>Window(""name:=x"").getTOProperty(""text"")|Value>Notepad|Condition>False" <br/>
''' Default = True
''' </description></item>
''' </list></param>
''' <returns type="Boolean">True if succeeded to start the Filter, False if failed</returns>
''' <example><c>"ObjectProperty>VBWindow(""vbname:=Something"").Exist|Value>True"</c> - This will only report events when the window does exist </example>
Public Function StartFilter(sSettings)
Load_Settings(sSettings)
StartFilter = AllowCreate
End Function
'*************************************************************'
' Function Check (Public)
' Goal Checks if an event matches the filter's criteria
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params Boolean - Does it match the criteria? If = True means the event will be reported
'*************************************************************'
''' <summary>Checks if an event matches the filter's criteria</summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status</param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
''' <returns type="Boolean">Returns True if the event matches, otherwise False</returns>
Public Function Check(sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="Boolean"/>
Dim bResult
''' <value type="String"/>
Dim PropertyValue
''' <value type="Boolean"/>
Dim bCondition
If oSettings("ObjectProperty") ="" Or oSettings("Value") = "" Then
Check = True
Exit Function
End If
bCondition = CBool(oSettings("Condition"))
bResult = True
On Error Resume Next
Execute "PropertyValue = " & oSettings("ObjectProperty")
If err.Number <> 0 Then
bResult = False
End If
On Error Goto 0
If bResult = False Then
Check = bResult
Exit Function
End If
If CStr(PropertyValue) = CStr(oSettings("Value")) Then
If bCondition = True Then 'Was ment to match
Check = True
Else
Check = False
End If
Else
If bCondition = False Then 'Was ment NOT to match
Check = True
Else
Check = False
End If
End If
End Function
'*************************************************************'
' Sub Init_Settings (Private)
' Goal Specifies default values of the settings object
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Specifies default values of the settings object
''' </summary>
''' <remarks><para>ObjectProperty = ""</para>
''' <para>Value = ""</para>
''' <para>Condition = True</para>
''' </remarks>
Private Sub Init_Settings 'Inits the filter's default settings
Set oSettings = CreateObject("Scripting.Dictionary")
oSettings.Add "ObjectProperty", ""
oSettings.Add "Value", ""
oSettings.Add "Condition", "True"
End Sub
'*************************************************************'
' Function AllowCreate (Private)
' Goal Checks if there would be a problem to create the reporter engine
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if there would be a problem to create the reporter engine
''' </summary>
''' <returns type="Boolean">True if it's OK to create the filter, False otherwise</returns>
Private Function AllowCreate
Dim bResult
bResult = CheckVersion
AllowCreate = bResult
End Function
'*************************************************************'
' Private Function CheckVersion (Private)
' Goal Checks if the manager and engine versions are ok
' In Params None
' Out Params Boolean - Yes/No (Yes = OK to create)
'*************************************************************'
''' <summary>
''' Checks if the manager and engine versions are ok
''' </summary>
''' <returns type="Boolean">True if the filter passes the version check, False otherwise</returns>
Private Function CheckVersion
''' <value type="Integer"/>
Dim iDiff
''' <value type="String"/>
Dim sEngineVersion
''' <value type="String"/>
Dim sManagerVersion
'Check the manager version is good enough
sEngineVersion = Replace(CStr(Me.MinimunManagerVersion), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.Version), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(Abs(iDiff), "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) > CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Engine Expected " & Me.MinimunManagerVersion & _
vbCrLf & "But manager was actually " & Me.Manager.Version
CheckVersion = False
Exit Function
End If
'Check the engine version is good enough
sEngineVersion = Replace(CStr(Me.Version), ".", "")
sManagerVersion = Replace(CStr(Me.Manager.MinimumEngineVersion), ".","")
iDiff = Len(sEngineVersion) - Len(sManagerVersion)
If iDiff > 0 Then
sManagerVersion = sManagerVersion & String(Abs(iDiff), "0")
Else
sEngineVersion = sEngineVersion & String(Abs(iDiff), "0")
End If
If CLng(sEngineVersion) < CLng(sManagerVersion) Then
Reporter.ReportEvent MicFail, "Start Engine", "Failed Version Check" & vbCrLf & "Manager expected " & Me.Manager.MinimumEngineVersion &_
vbCrLf & "But engine actually was " & Me.Version
CheckVersion = False
Exit Function
End If
CheckVersion = True
End Function
'*************************************************************'
' Sub Load_Settings (Private)
' Goal Loads sSettings into the oSettings object
' In Params sSettings - The Filters init settings as "Field1>Value1|Field2>Value2|...
' Out Params None
'*************************************************************'
''' <summary>
''' Loads sSettings into the oSettings object
''' </summary>
''' <param name="sSettings" type="String">The Filter's init settings as "Field1>Value1|Field2>Value2|...</param>
Private Sub Load_Settings(sSettings)
'***************************' No Need to change this sub! ***************************'
Dim ReplaceArray
Dim arrData, arrSettingData
Dim i
'Protect >> and || chars
ReplaceArray = Array ("ABCDEFGHIJKLMNOP1", "ABCDEFGHIJKLMNOP2")
sSettings = Replace(sSettings, "||", ReplaceArray(0))
sSettings = Replace(sSettings, ">>", ReplaceArray(1))
arrData = Split(sSettings, "|") 'Split to individual fields
For i = 0 To UBound(arrData) 'Loop through fields
If arrData(i) <> "" Then
arrSettingData = Split(arrData(i), ">") 'Break to Field and to Value
'Protect | char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(0), "|")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(0), "|")
'Protect > char
arrSettingData(0) = Replace(arrSettingData(0), ReplaceArray(1), ">")
arrSettingData(1) = Replace(arrSettingData(1), ReplaceArray(1), ">")
If oSettings.Exists(arrSettingData(0)) Then 'There's a default value for this field
oSettings(arrSettingData(0)) = arrSettingData(1) 'Change it to the user's value
Else
oSettings.Add arrSettingData(0), arrSettingData(1) 'Create new setting
End If
End If
Next
End Sub
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Initialize event
''' </summary>
Private Sub Class_Initialize() ' Setup Initialize event.
Init_Settings
Set Manager = Nothing
Set Engine = Nothing
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary>
''' Setup Terminate event
''' </summary>
Private Sub Class_Terminate ' Setup Terminate event.
Set oSettings = Nothing
Set Manager = Nothing
Set Engine = Nothing
End Sub
''' <summary>
''' Stops the current filter and clears it
''' </summary>
Public Sub ClearFilter
Class_Terminate
End Sub
End Class
---------------------------------------------------------------------------------------ReporterManager.VBS-------------------------------------------------------------------------------------
'''<summary>This file holds the core class and global variable of the reporter manager</summary>
''' <datecreated>20/01/2008</datecreated>
'''<version>0.9.2</version>
Option Explicit
'**********************************************************************'
' Global Variable
'**********************************************************************'
''' <summary>
''' Holds the manager's global variable
''' </summary>
''' <value type="ReporterManagerClass"/>
Dim oReporterManager
Set oReporterManager = New ReporterManagerClass
'**********************************************************************'
' Manager
'**********************************************************************'
''' <summary>
''' The manager class core
''' </summary>
''' <author>Yaron Assa</author>
''' <datecreated>20/01/2008</datecreated>
Class ReporterManagerClass
'Written by Yaron Assa, 1/9/07. Project home at www.AdvancedQTP.com
''' <value type="Scripting.Dictionary"/>
''' <summary>Holds the reporters collection</summary>
Private oReporters 'Holds the reporters collection
'The oReporters Data structure is :
'oReporters (DIctionary)
' |--> Reporter Item (DIctionary)
' |--> Filters (DIctionary)
' | |--> Filter Item (Class)
' |--> Engine (Class)
''' <summary>
''' Only init engine in the first test iteration
''' </summary>
''' <value type="Boolean"/>
Public OnlyInitOnce
''' <value type="String"/>
''' <summary>The Manager's version</summary>
Public Property Get Version
Version = "0.9.2"
End Property
''' <value type="String"/>
''' <summary>The minimal version an engine must have in order to be operated</summary>
Public Property Get MinimumEngineVersion
MinimumEngineVersion = "0.8"
End Property
''' <value type="String"/>
''' <summary>The minimal version a filter must have in order to be operated</summary>
Public Property Get MinimumFilterVersion
MinimumFilterVersion = "0.8"
End Property
''' <value type="Scripting.Dictionary"/>
''' <summary>Exposes the reporters collection of the reporter manager</summary>
''' <remarks>Each reporter is a Scripting.Dictionary with two values : "Engine" and "Filters"</remarks>
Public Property Get Reporters
Set Reporters = oReporters
End Property
'*************************************************************'
' Function StartEngine (Public)
' Goal Starts engine sName of type sType.
' In Params sType - The Class of the engine (e.g. "Excel")
' sName - The name of the relevant reporter (e.g. "My Log")
' sSettings - The settings to send the engine as "Field1>Value1|Field2>Value2". Can be empty
' Depends on the specific engine (e.g. "ClearExisting>True|File>c:\log.txt")
' Out Params Boolean - Success/Failure
'*************************************************************'
''' <summary>
''' Starts engine sName of type sType
''' </summary>
''' <param name="sType" type="String" paramlist="EngineType">The engine type</param>
''' <paramlist name="EngineType">
''' <item><text>"QTP"</text><description>This Engine is the native QTP reporter.Reportevent engine <see cref="QTPEngine"/></description></item>
''' <item><text>"User"</text><description>This Engine pops-up messages for the used, that disappear after a few seconds <see cref="UserEngine"/></description></item>
''' <item><text>"Text"</text><description>This Engine is a simple text file logger, with template support <see cref="TextEngine"/></description></item>
''' <item><text>"Excel"</text><description>This Engine is a an Excel logger, built upon Sameer Girolkar's ResultToXL <see cref="ExcelEngine"/></description></item>
''' <item><text>"Winlog"</text><description>This engine reports to the windows event log <see cref="WinlogEngine"/></description></item>
''' <item><text>"ScreenCapture"</text><description>This Engine captures screenshots and saves them <see cref="ScreenCaptureEngine"/></description></item>
''' <item><text>"DB"</text><description>This Engine reports to any database ADODB can access <see cref="DBEngine"/></description></item>
''' <item><text>"XML"</text><description>This Engine reports to an XML file, which can later be viewed via a stylesheet<see cref="XMLEngine"/></description></item>
''' </paramlist>
''' <param name="sName" type="String">The user logical name of the engine</param>
''' <param name="sSettings" type="String">The settings string to be passed to the engine</param>
''' <returns type="Boolean">Returns True if successful, otherwise False</returns>
''' <remarks>Please note that by default, engines are allowed to be <b>Re</b>started only in the first test iteration<hr/>
''' In order to start engines in other iterations, change the <see cref="ReporterManagerClass.OnlyInitOnce"/> parameter</remarks>
Public Function StartEngine(sType, sName, sSettings)
''' <value type="xEngine"/>
Dim oReporter
''' <value type="Boolean"/>
Dim bResult
''' <value type="Integer"/>
Dim i
bResult = True
'Don't do anything if the engine exists and it's the second iteration
If (OnlyInitOnce = True) And oReporters.Exists(sName) Then
If Environment.Value("TestIteration") <> 1 Then
StartEngine = True
Exit Function
End If
End If
On Error Resume Next
'Try to create an instanse of the reporter engine's class
Execute "Set oReporter = New " & sType & "Engine"
If Err.Number <> 0 Then
bResult = False
Reporter.ReportEvent micFail, "ReporterManagerClass StartEngine", "Failed to create instance : " & sType
End If
On Error Goto 0
If bResult = True Then
On Error Resume Next 'Allow legacy support with 0.8 engines
Set oReporter.Manager = Me
oReporter.Name = sName
Err.Clear
On Error Goto 0
On Error Resume Next
bResult = oReporter.StartEngine(sSettings) 'Try to start the engine
If Err.Number <> 0 Then 'We might need to stop a duplicate engine
If oReporters.Exists(sName) Then 'The name is unique
Err.Clear
StopEngine(sName)
bResult = oReporter.StartEngine(sSettings) 'Try to start the engine
End If
End If
If Err.Number <> 0 Then bResult = False
On Error Goto 0
If bResult = True Then
'Build Object Structure
If oReporters.Exists(sName) Then 'The name is unique
StopEngine(sName)
Else
oReporters.Add sName, BuildReporter
End If
Set oReporters(sName)("Engine") = oReporter
End If 'Engine Started
End If 'Instance Created
If bResult = False Then
Reporter.ReportEvent micFail, "ReporterManagerClass StartEngine", "Failed to start engine " & sName & " Of Type " & sType
On Error Resume Next
oReporter.StopEngine
On Error Goto 0
End If
Set oReporter = Nothing
StartEngine = bResult
End Function
'*************************************************************'
' Sub StopEngine (Public)
' Goal Stops the relevant reporting engine
' In Params sName - The name of the relevant reporter (e.g. "My Log")
' Out Params None
'*************************************************************'
''' <summary>
''' Stops the relevant reporting engine
''' </summary>
''' <param name="sName" type="String">The user logical name of the engine</param>
Public Sub StopEngine(sName)
If oReporters.Exists(sName) Then
If Not oReporters(sName)("Engine") Is Nothing Then
oReporters(sName)("Engine").StopEngine
Set oReporters(sName)("Engine") = Nothing
End If
End If
End Sub
'*************************************************************'
' Sub Report (Public)
' Goal Reports an event to all possible reporters
' In Params sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params None
'*************************************************************'
''' <summary>
''' Reports an event to all possible reporters
''' </summary>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status</param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
Public Sub Report(sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="Integer"/>
Dim i
''' <value type="Array"/>
Dim arrKeys
arrKeys = oReporters.Keys 'Get all reporter names
For i = 0 To oReporters.Count-1
'For each event check if the event matches the reporter filters
If CheckFilters(oReporters(arrKeys(i)), sStatus, sStepName,sExpected,sActual, sDetails) = True Then _
Call oReporters(arrKeys(i))("Engine").Report (sStatus, sStepName,sExpected,sActual, sDetails)
'If so - report the event in this reporter
Next
End Sub
'*************************************************************'
' Sub ReportToLog (Public)
' Goal Reports an event directly to a single specific reporter
' In Params sReporterName - The name of the relevant reporter (e.g. "My Log")
' sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params None
'*************************************************************'
''' <summary>
''' Reports an event directly to a single specific reporter
''' </summary>
''' <param name="sReporterName" type="String">The name of the relevant reporter (e.g. "My Log")</param>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status</param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
Public Sub ReportToLog(sReporterName, sStatus, sStepName,sExpected,sActual, sDetails)'Report to a specific Log
If oReporters.Exists(sReporterName) Then _
Call oReporters(sReporterName)("Engine").Report (sStatus, sStepName,sExpected,sActual, sDetails)
End Sub
'*************************************************************'
' Function AddFilter (Public)
' Goal Adds a filter to different reporters
' In Params sReporterName - The names of the relevant reporters as "Reporter1>Reportet2>Reporter3..."
' sFilterType - The class of the filter (e,g, "RegEx")
' sFilterSettings - The settings to send the filter as "Field1>Value1|Field2>Value2". Can be empty
' Depends on the specific filter (e.g. "Incldue>True|Pattern>.*Error.*")
' Out Params Boolean - Success/Failure
'*************************************************************'
''' <summary>
''' Adds a filter to different reporters
''' </summary>
''' <param name="sFilterType" type="String" paramlist="FilterType">The filter's type</param>
''' <paramlist name="FilterType">
''' <item><text>"RegEx"</text><description>This filter performs Regular Expressions searches within the event's data <see cref="RegExFilter"/></description></item>
''' <item><text>"ObjectProperty"</text><description>This filter screens event according to an object's condition <see cref="ObjectPropertyFilter"/></description></item>
''' </paramlist>
''' <param name="sReporterNames" type="String">The names of the relevant reporter
''' (e.g. "My Log>My Second Log")</param>
''' <param name="sFilterSettings" type="String">The settings to be passed to the reporter</param>
''' ''' <returns type="Boolean">Returns True if successful, otherwise False</returns>
Public Function AddFilter(sFilterType, sReporterNames, sFilterSettings)
''' <value type="Integer"/>
Dim i
''' <value type="String"/>
Dim sProtectReporters
''' <value type="Array"/>
Dim arrReporters 'Holds the reporters array
''' <value type="String"/>
Dim sReplaceString
''' <value type="String"/>
Dim sReporterName 'Holds a single reporter name
sReplaceString = "ABCDEFGHIJKLMNOP1"
sProtectReporters = Replace(sReporterNames, ">>", sReplaceString)
arrReporters = Split(sProtectReporters, ">")
For i = 0 To UBound(arrReporters)
sReporterName = Replace(arrReporters(i), sReplaceString, ">")
Call AddFilterToReporter(sFilterType, sReporterName, sFilterSettings)
Next
End Function
'*************************************************************'
' Function AddFilterToReporter (Private)
' Goal Adds a filter to a specific log
' In Params sReporterName - The name of the relevant reporter (e.g. "My Log")
' sFilterType - The class of the filter (e,g, "RegEx")
' sFilterSettings - The settings to send the filter as "Field1>Value1|Field2>Value2". Can be empty
' Depends on the specific filter (e.g. "Incldue>True|Pattern>.*Error.*")
' Out Params Boolean - Success/Failure
'*************************************************************'
''' <summary>
''' Adds a filter to a single reporter
''' </summary>
''' <param name="sFilterType" type="String" paramlist="FilterType">The filter's type</param>
''' <paramlist name="FilterType">
''' <item><text>"RegEx"</text><description>This filter performs Regular Expressions searches within the event's data</description><see cref="RegExFilter"/></item>
''' <item><text>"ObjectState"</text><description>This filter screens event according to an object's condition</description><see cref="ObjectStateFilter"/></item>
''' </paramlist>
''' <param name="sReporterName" type="String">The name of the relevant reporter</param>
''' <param name="sFilterSettings" type="String">The settings to be passed to the reporter</param>
''' <returns type="Boolean">Returns True if successful, otherwise False</returns>
Private Function AddFilterToReporter(sFilterType, sReporterName, sFilterSettings)
''' <value type="Boolean"/>
Dim bResult
''' <value type="XFilter"/>
Dim oFilter
bResult = True
If Not oReporters.Exists(sReporterName) Then
AddFilterToReporter = False
Reporter.ReportEvent micFail, "ReporterManagerClass StartFilter", "Failed - No such engine: " & sReporterName
Exit Function
End If
On Error Resume Next
'Create a new instrance of the filter
Execute "Set oFilter = New " & sFilterType & "Filter"
If Err.Number <> 0 Then
bResult = False
End If
On Error Goto 0
If bResult = False Then 'Instance wasn't created
AddFilterToReporter = False
Reporter.ReportEvent micFail, "ReporterManagerClass StartFilter", "Failed to create instance : " & sFilterType
Set oFilter = Nothing
Exit Function
End If
On Error Resume Next 'Allow Legacy Support For 0.8 Filters
Set oFilter.Manager = Me
Set oFilter.Engine = oReporters(sReporterName)("Engine")
Err.Clear
On Error Goto 0
bResult = oFilter.StartFilter(sFilterSettings) 'Activates the filter
If bResult = False Then
Reporter.ReportEvent micFail, "ReporterManagerClass StartFilter", "Failed to start filter " & sFilterType
Else
'Add new filter to the filter dictionary by Key = filter index in the dictionary
oReporters(sReporterName)("Filters").Add oReporters(sReporterName)("Filters").Count, oFilter
End If
AddFilterToReporter = bResult
Set oFilter = Nothing
End Function
'*************************************************************'
' Sub ClearFilters (Private)
' Goal Removes all the filters within a filter collection
' In Params sReporterName - The name of the relevant reporter (e.g. "My Log")
' Out Params None
'*************************************************************'
''' <summary>
''' Removes all the filters within a filter collection
''' </summary>
''' <param name="sReporterName" type="String">The Reporter Name</param>
Private Sub ClearFilters(sReporterName)
''' <value type="Integer"/>
Dim i
''' <value type="Integer"/>
Dim iCount
If Not oReporters.Exists(sReporterName) Then Exit Sub
iCount = oReporters(sReporterName)("Filters").Count
For i = 0 To iCount-1
oReporters(sReporterName)("Filters")(i).ClearFilter
oReporters(sReporterName)("Filters").Remove i 'Clear Each Filter
Next
End Sub
'*************************************************************'
' Function BuildReporter (Private)
' Goal Builds a new reporter object structure
' In Params None
' Out Params Object - The reporter data structure (Dictionary)
'*************************************************************'
''' <summary>
''' Builds a new reporter object structure
''' </summary>
''' <returns type="Scripting.Dictionary">
''' <dictionarykeys>
''' <item><text>Engine</text><description>The reporter engine class</description></item>
''' <item><text>Filters</text><description>The reporter filters collection</description></item>
''' </dictionarykeys></returns>
Private Function BuildReporter
''' <value type="Scripting.Dictionary" dictionarykeys="ReporterDictionary"/>
''' <dictionarykeys name="ReporterDictionary">
''' <item><text>"Engine"</text><description>The reporter engine class</description></item>
''' <item><text>"Filters"</text><description>The reporter filters collection</description></item>
''' </dictionarykeys>
Dim oResult
''' <value type="Scripting.Dictionary"/>
Dim oFilters
Set oResult = CreateObject("Scripting.Dictionary")
Set oFilters = CreateObject("Scripting.Dictionary")
oResult.Add "Filters", oFilters
oResult.Add "Engine", Nothing
Set BuildReporter = oResult
End Function
'*************************************************************'
' Function CheckFilters (Private)
' Goal Checks if an event report matches the reporters filters
' In Params oReporter - The reporter dictionary object
' sStatus - The status of the event : "Fail", "Pass", "Warning" or custom
' sStepName - The name of the event (e.g. "Validate Field Value")
' sExpected - The expected result (e.g. "Value = Something")
' sActual - The actual result (e.g. "Value = Something Else")
' sDetauls - Possile details about the event
' Out Params Boolean - Does the event match the reporter filters
'*************************************************************'
''' <summary> Checks if an event report matches the reporters filters </summary>
''' <param name="oReporter" type="Scripting.Dictionary">The reporter dictionary</param>
''' <param name="sStatus" type="String" paramlist="StatusType">The event's status</param>
''' <paramlist name="StatusType">
''' <item><text>"Fail"</text><description>The Step Failed</description></item>
''' <item><text>"Pass"</text><description>The Step Passed</description></item>
''' <item><text>"Warning"</text><description>A Warning</description></item>
''' <item><text>"General"</text><description>Just report the event</description></item>
''' </paramlist>
''' <param name="sStepName" type="String">The event's step name</param>
''' <param name="sExpected" type="String">The event's expected result</param>
''' <param name="sActual" type="String">The event's actual result</param>
''' <param name="sDetails" type="String">The event's details</param>
''' <returns type="Boolean">Returns True if successful, otherwise False</returns>
Private Function CheckFilters(oReporter, sStatus, sStepName,sExpected,sActual, sDetails)
''' <value type="Boolean"/>
Dim bResult
''' <value type="Integer"/>
Dim i
bResult = True
'Loop through the filters
For i = 0 To oReporter("Filters").Count-1
'Send the event to each filter and check the result
bResult = oReporter("Filters")(i).Check(sStatus, sStepName,sExpected,sActual, sDetails)
If bResult = False Then Exit For
Next
CheckFilters = bResult
End Function
'*************************************************************'
' Sub Class_Initialize (Private)
' Goal Setup Initialize event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary> Setup Initialize event </summary>
Private Sub Class_Initialize
OnlyInitOnce = True
Set oReporters = CreateObject("Scripting.Dictionary")
End Sub
'*************************************************************'
' Sub Class_Terminate (Private)
' Goal Setup Terminate event.
' In Params None
' Out Params None
'*************************************************************'
''' <summary> Setup Terminate event </summary>
Private Sub Class_Terminate
''' <value type="Integer"/>
Dim i
''' <value type="Array"/>
Dim arrKeys
If oReporters Is Nothing Then Exit Sub
arrKeys = oReporters.Keys
'Stop all reporting engines and break the reporters data structure
For i = 0 To oReporters.Count -1
StopEngine arrKeys(i)
oReporters(arrKeys(i)).Remove "Engine"
ClearFilters arrKeys(i)
oReporters(arrKeys(i)).Remove "Filters"
Next
Set oReporters = Nothing
End Sub
''' <summary>
''' Stops all engines
''' </summary>
Public Sub StopAll
Dim arrKeys
arrKeys = oReporters.Keys
'Stop all reporting engines
For i = 0 To oReporters.Count -1
StopEngine arrKeys(i)
Next
End Sub
End Class