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

LoadLibrary files Folder Wise

***********************************************************
Load Library files Folder Wise
***********************************************************

Below is the function we can use to load functional lib on base on folder path

Function LoadLibraryFilesFromSubFolders(strFolderPath)
Set objFSO  = CreateObject("Scripting.FileSystemObject") Set objFolder = objFSO.GetFolder(strFolderPath)
    For Each Subfolder in objFolder.SubFolders
        Set objChildFolder = objFSO.GetFolder(Subfolder.Path)
        Set objColFiles = objChildFolder.Files
        For Each objFile In objColFiles
            If Right(objFile.Name,  3) = "vbs" Or Right(objFile.Name,  3) = "qfl"  Then             Print Subfolder.Path & "\" & objFile.Name
            LoadFunctionLibrary Subfolder.Path & "\" & objFile.Name                    
            End If
        Next
     
        Call LoadLibraryFilesFromSubFolders(Subfolder)
    Next

    Set objColFiles = Nothing
    Set objChildFolder = Nothing
    Set objFolder = Nothing
End Function

System Sleep code while running batch execuiton

******************************************
System Sleep code :
******************************************

As automation tester we have to run the automation scripts as Batch over night,usually system will get sleep by 5  min to avoid that we can use below sleep code to keep system running without sleep

set c=wscript.createobject("wscript.shell")
for j=1 to 100
c.sendkeys "^"
wscript.sleep 50000
j=j-1
next

take above code and save as VBS file, and just double click on same file so that system will not sleep


Note : If you have admin rights you can change system sleep settings, but above code will help us even you dont have admin rights


Automation script for scheduler Batch Run

As automation tester sometimes we have to run the scripts as scheduler, to run the automation scripts first we have to create one script like below and make as VBS file and we have to upload same file while creating scheduler in Windows


Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTest 'As QuickTest.Test ' Declare a Test object variable
Dim qtResultsOpt 'As QuickTest.RunResultsOptions ' Declare a Run Results Options object variable
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start QuickTest
qtApp.Visible = True ' Make the QuickTest application visible
' Set QuickTest run options
qtApp.Options.Run.ImageCaptureForTestResults = "OnError"
qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = True

qtApp.Open "C:\Users\Desktop\DriverFile_SAP BO",True ' Open the test in read-only mode

' set run settings for the test
Set qtTest = qtApp.Test
qtTest.Settings.Run.IterationMode = "rngIterations" ' Run only iterations 2 to 4
qtTest.Settings.Run.StartIteration = 1
qtTest.Settings.Run.EndIteration = 1
qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next step when error occurs

'For Viewing Results
Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object
qtResultsOpt.ResultsLocation = "C:\Users\w00620011\Desktop\DriverFile_SAP BO\Results\Res1" ' Set the results location
qtTest.Run qtResultsOpt ' Run the test
qtApp.Options.Run.ViewResults = True

'Close QTP
qtTest.Close ' Close the test

qtApp.Quit
'Set the options to nothing
Set qtResultsOpt = Nothing ' Release the Run Results Options object
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object