Sunday, March 6, 2016

Mapping or laoding OR @ runtime

**************************************************************
Mapping or laoding OR @ runtime
**************************************************************

Below is the function to upload the OR's @ runtime on specified folders



Function MapObjectRepositories()
On Error Resume Next

strObjectRepositoryPath = Environment.Value("strMasterTestSuitePath") & "\ObjectRepository\"
RepositoriesCollection.RemoveAll

Set objFSO  = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strObjectRepositoryPath) Then
Set objFolder = objFSO.GetFolder(strObjectRepositoryPath)

For Each objFile In objFolder.Files
If Right(objFile.Name,  3) = "tsr" Then
RepositoriesCollection.Add strObjectRepositoryPath & objFile.Name
End If
Next
End If

Set objFSO = Nothing
End Function

Load recovery scenarios at Runtime

*****************************************************************
Load recovery scenarios at Runtime
*****************************************************************

Loading Recovery we can do in two ways

1)Static loading
2)Dynamic or Run time loading


********************************************************************
Static loading :
********************************************************************

Static loading we can do directly from QTP recovery scenario window



********************************************************************
Dynamic or Run time loadingFunction LoadRecoveryScenarios
********************************************************************
On Error Resume Next

strRecoveryScenarioPath = Environment.Value("strMasterTestSuitePath") & "\RecoveryScenario\"

' Create the Application object
Set objQTP = CreateObject("QuickTest.Application")
' Return the Recovery object for the current test
Set objQTPTestRecovery = objQTP.Test.Settings.Recovery

' Add the " Server Error " scenario as the first scenario
objQTPTestRecovery.RemoveAll
objQTPTestRecovery.Add strRecoveryScenarioPath & "\" & "RecoveryScenario.qrs",  "ServerError1",  1
objQTPTestRecovery.Add strRecoveryScenarioPath & "\" & "RecoveryScenario.qrs",  "ServerError2", 2
objQTPTestRecovery.Add strRecoveryScenarioPath & "\" & "RecoveryScenario.qrs",  "ServerError3",  3

' Iterate the scenarios
For intIndex = 1 To objQTPTestRecovery.Count
' Enable each Recovery Scenario (Note: the 'Item' property is default and can be omitted)
objQTPTestRecovery.Item(intIndex).Enabled = True
Next

' Enable the recovery mechanism (with default,  on errors,  setting)
objQTPTestRecovery.Enabled = True
'Ensure that the recovery mechanism is set to be activated only after errors
objQTPTestRecovery.SetActivationMode "OnEveryStep" '"OnError" OnEveryStep

Set objQTP = Nothing ' Release the Application object
Set objQTPTestRecovery = Nothing ' Release the Recovery object

End Function