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

Monday, October 28, 2013

Regular Expression Token in QTP









Token
Description
^Matches the beginning of a line. For instance, the ^a search pattern lets you find all lines that start with a.
$Matches the end of a line. For instance, the a$ search pattern lets you find all lines that end with a.
.Matches any single character. For example, a.c matches abc, adc, aec but not aaac or abbc.
*Indicates that the preceding character or group matches 0 or more times. For instance, the abc*d pattern matches abd, abcd, abccd, but not a or abcx. The .*pattern matches a string of any length (including the empty string) that does not contain the newline symbol.
Note that this token is “greedy”, that is, it matches the longest possible string. For example, when searching on the string abbbb, ab* matches abbbb rather than aab.
+Indicates that the preceding character or group matches 1 or more times. For instance, the ab+d pattern matches abbd or abbbd, but does not match abcd orabbcd.
Note that this token is “greedy”, that is, it matches the longest possible string. For example, when searching on the string abbbb, ab+ matches abbbb rather thanab or abb.
?Indicates that the preceding character or group is optional, that is, it should either match once or not to match at all. For example, abc?d will find abd and abcd, but not abccd.
Note that this token is “greedy”, that is, it matches the longest possible string. For example, when searching on the string abc, ab? matches ab rather than a.
??,+?, *?These tokens are “non-greedy” versions of ?, + and *. That is, they match the shortest possible string. For example, when searching on the string abbbb, ab*?matches a rather than ab or abbbb.
[ ]Matches any single character specified in brackets. For instance, d[ab]e matches dae or dbe and does not match dwe or dxe. To include the ] character into the search, make it either first, or last character in the range or use \]. For example, []abc], [abc]] or [ab\]cd].
[^ ]Matches any single character except for those in brackets. For instance, d[^bc]e matches dae or dxe, but not dbe or dce. d[^b-d]e matches dae, but not dbe, dceor dde.
[a-b]Matches any single character from a to b, inclusive. For instance d[k-x]e matches dke, dme and dxe, but not dze. To include the - character into the search, make it either first, or last character in the range or use \-. For example, [-ab], [abc-] or [a\-z].
[^a-b]Matches any single character not in the range a through b. For instance a[^k-x]z matches abz, aiz and ayz, but not akz.
a|bMatches either the a or b character or a group. For example, A|abc matches Abc and abc, but not A. The htm|(ml) pattern matches htm and html, but not htl or ml.
a!bMatches a not followed by b. For example, colo!ur matches color, but not colour.
( )Groups characters. For example, (ab)+ matches ab and abab but not acb.
To specify a round bracket that should be treated literally, precede it with a backslash: \( or \).
{ }Indicates a match group. You can use braces in regular expressions that retrieve values that match the expression in the braces. If you create the following regular expression: [0-9]+-[0-9]+, it will match 125-125, but not 125-abcd. However, you can use braces to reduce the size of a regular expression. For example, you may need to modify the expression above to make it find strings containing only similar numbers that are hyphenated. For this purpose, you can specify the first part as a group and then address the value that matches this part by a zero-based index of the match group. This is the index that is specified after the backslash, \n. For example, you can change the regular expression mentioned above in the following way {[0-9]+}-\0. This means that TestComplete will replace the \0 expression with the string returned by the first match group. It will match 168-168, but not 125-168.
To specify a brace that should be treated literally, precede it with a backslash: \{ or \}.
\A backslash indicates that the next character token (such as ?, !, *, - and others) should be treated literally. For example, \$10 matches the string $10. To match a backslash itself, use the double backslash pattern (\\).
When followed by a number (for example, \0), indicates the match group at the specified index (from 0).
In JScript, C++Script and C#Script, you should use double backslashes to interpret the subsequent special character literally: "\\?", "\\.", "\\2" and so on. To match a backslash character, use the "\\\\" pattern.
\aMatches any alphanumeric character. This token is equivalent to [A-Za-z0-9].
\bMatches a whitespace character.
\cMatches any alphabetic character. This token is equivalent to [A-Za-z].
\dMatches any decimal digit. This token is equivalent to [0-9].
\hMatches any hexadecimal digit. This token is equivalent to [0-9A-Fa-f].
\nMatches a new line character.
\qMatches a quoted string. This token is equivalent to ("[^"]*")|('[^']*').
\wMatches a word. This token is equivalent to [a-zA-Z]+ or \c+.
\zMatches an integer number. This token is equivalent to [0-9]+ or \d+.