Académique Documents
Professionnel Documents
Culture Documents
code:
on error resume next
val=DataTable("ParamName",dtGlobalSheet)
if err.number<> 0 then
'Parameter does not exist
else
'Parameter exists
end if
Well QTP does not allow anything for saving the run time changes to the actual data sheet. The
only work around is to share the
SMART Identification
Smart Identification is nothing but an algorithm used by QTP when it is not able to recognize one of the
object. A very generic example as per the
QTP manual would be, A photograph of a 8 year old girl and boy and QTP records identification
properties of that girl when she was 8, now when
both are 10 years old then QTP would not be able to recognize the girl. But there is something that is
still the same, that is there is only one girl in
Something that people don't think about too much. But the thing is that you should disable SI
while creating your test cases. So that you
are able to recognize the objects that are dynamic or inconsistent in their properties. When the
script has been created, the SI should be enabled,
so that the script does not fail in case of small changes. But the developer of the script should
always check for the test results to verify if the SI
feature was used to identify a object or not. Sometimes SI needs to be disabled for particular
objects in the OR, this is advisable when you use
SetTOProperty to change any of the TO properties of an object and especially ordinal identifiers
like index, location and creationtime.
Descriptive Programming
Descriptive programming is nothing but a technique using which operations can be performed
on the AUT object which are not present in
Recovery scenario gives you an option to take some action for recovering from a fatal error in
the test. The error could range in from
occasional to typical errors. Occasional error would be like "Out of paper" popup error while
printing something and typical errors would be like
"object is disabled" or "object not found". A test case have more then one scenario associated
with it and also have the priority or order in which it
should be checked.
Trigger: Trigger is nothing but the cause for initiating the recovery scenario. It could be any
popup window, any test error, particular state
recovery function defined in library file or restart windows. You can have a series of all the
specified actions.
Post-recovery operation: Basically defined what need to be done after the recovery action has
been taken. It could be to repeat the step, move
Recovery scenarios are used when you cannot predict at what step the error can occur or when
you know that error won't occur in your
QTP script but could occur in the world outside QTP, again the example would be "out of paper",
as this error is caused by printer device driver. "On
error resume next" should be used when you know if an error is expected and dont want to
raise it, you may want to have different actions
depending upon the error that occurred. Use err.number & err.description to get more details
about the error.
Library files are files containing normal VBScript code. The file can contain function, sub
procedure, classes etc.... You can also use executefile
function to include a file at run-time also. To associate a library file with your script go to Test-
>Settings... and add your library file to resources
tab.
When to associate a library file with a test and when to use execute file?
When we associate a library file with the test, then all the functions within that library are
available to all the actions present in the test. But
when we use Executefile function to load a library file, then the function are available in the
action that called executefile. By associated a library to
a test we share variables across action (global variables basically), using association also makes
it possible to execute code as soon as the script
runs because while loading the script on startup QTP executes all the code on the global scope.
We can use executefile in a library file associated
with the test to load dynamic files and they will be available to all the actions in the test.
Add-ins
Test objects are basic and generic objects that QTP recognize. Run time object means the actual
object to which a test object maps.
Yes. You can use SetTOProperty to change the test object properties. It is recommended that
you switch off the Smart Identification for the
No (but Yes also). You can use GetROProperty("outerText") to get the outerText of a object but
there is no function like SetROProperty to
Action is a thing specific to QTP while functions are a generic thing which is a feature of VB
Scripting. Action can have a object repository
associated with it while a function can't. A function is just lines of code with some/none
parameters and a single return value while an action can
Well answer depends on the scenario. If you want to use the OR feature then you have to go for
Action only. If the functionality is not about any
automation script i.e. a function like getting a string between to specific characters, now this is
something not specific to QTP and can be done on
pure VB Script, so this should be done in a function and not an action. Code specific to QTP can
also be put into an function using DP. Decision of
using function/action depends on what any one would be comfortable using in a given situation.
Checkpoint is basically a point in the test which validates for truthfulness of a specific things in
the AUT. There are different types of
checkpoints depending on the type of data that needs to be tested in the AUT. It can be text,
image/bitmap, attributes, XML etc....
Checkpoint only checks for the specific attribute of an object in AUT while Output value can
output those attributes value to a column in data
table.
Environment.LoadFromFile "C:\Env.xml"
Environment.value("Param1") then QTP will create a new internal environment variable if it does
not exists already. So to be sure that variable exist
Well i am not explaining what to do in case of XMLs, but i am pasting two post that might help...
http://www.qaforums.com/ultimatebb.php?ubb=get_topic;f=20;t=004193#000004
http://www.qaforums.com/ultimatebb.php?ubb=get_topic;f=20;t=005111#000002
Function :
Function PressKeyboardEnterButton(sWindowTitle)
Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate sWindowTitle
wait(1)
WshShell.SendKeys "{ENTER}"
wait(3)
End Function
This function verifies that supplied database, uid and pwd are valid or not.
Code:
Function VerifyDatabaseNameUidPwd(sDatabaseName,sUID,sPWD)
Set strConn=nothing
Set oConn=nothing
ExitAction(0)
end if
Set strConn=nothing
Set oConn=nothing
End Function
Code:
Function VerifyItemExistsInWebList(vObject,sItem)
bFound=False
iTotalItem=vObject.GetROProperty("Items Count")
For i = 1 to iTotalItem
if vObject.GetItem(i) = sItem then
bFound=True
Exit for
end if
next
If bFound=False Then
Reporter.ReportEvent micFail,"Item NOT found:",sItem
VerifyItemExistsInWebList="False"
End If
End Function
Function :
Return Value: Boolean
' True = String split successfully
' False = Unable to split string at designated position
'
' Input Parameters: sInputString - string to be split
' iSplitPoint - number of characters to be splitted from the beginning of the sInputString
'
' Output Parameters: sFirstPortion - Substring of the original string
' prior to the split point
' sRemainingPortion - Remaining substing of the
' original string
'
' Note: Returns false if sInputString is empty or if iSplitPoint < 0.
Function SplitStringByIndex(ByVal sInputString, ByVal iSplitPoint, _
ByRef sFirstPortion, ByRef sRemainingPortion)
iInputStringLen = Len(sInputString)
SplitStringByIndex = bReturnValue
End Function 'SplitStringByIndex
'
'
Using:
If (SplitStringByIndex("1234", 2, sFirstPortion, sRemainingPortion)) Then
MsgBox sFirstPortion
MsgBox sRemainingPortion
Else
MsgBox "Unable to split string at designated position"
End If
'
'
Using in your case:
If (SplitStringByIndex("23345645", 2, sFirstPortion, sRemainingPortion)) Then
YourVariableForComparison = sFirstPortion & “-” & sRemainingPortion
Else
MsgBox "Unable to parse innitial string"
End If
Solution
Call below functions at the end of the each script.
Code:
________________________________________
sAppResultFilePath="C:\QTP\Test1\Res1\Report\Results.xml"
sFileName="Test-Result.txt"
sFilePath="C:\Temp\"
Call
CreateUserDefineResultFile(sFileName,sFilePath,GetPassFailStatusFromResultsXML(sAppResultFilePath)
)
Function GetPassFailStatusFromResultsXML(sAppResultFilePath)
Set doc = XMLUtil.CreateXML()
doc.LoadFile sAppResultFilePath
Function CreateUserDefineResultFile(sFileName,sFilePath,sTextToWrite)
flname = fso.GetAbsolutePathName(".") & "\log\" & year(date) & left(100 + month(date),2) &
left(100+day(date),2) & ".log"
Set fl = fso.OpenTextFile(flname, 8, True)
if bpopup then msgbox(date & ", " & time & ", " & scode & ", " & smessage)
End sub
writelog "TEST", "This is the message to output to the logfile and popup", TRUE
'Instructions
'1. Create a folder C:\Data
'2. Create an Excel file Client.xls (make this a shared workbook)
'Name the first sheet Client_Creation
'4. Run this script and view the created file.
'### These Input boxes are to demonstrate assigning the string values. These values could come from
a GET Text function.
strClientType = InputBox("Client Type")
strGivenName = InputBox("Enter your Given Name")
strSurname = InputBox("Enter your Surname")
'#### This line writes Data to sFileName. It will write data to a Column Called "ClientTypeS" it will
write the value strClientType
'#### On the Sheet called "Client_Creation". If the Column ClientTypeS doesnt exist it will be created.
If the sheet Client_Creation
'#### doesnt exist it will be created
Call WriteExcelDataSingle(sFileName, 2, "ClientTypeS", strClientType,"Client_Creation")
Call WriteExcelDataSingle(sFileName, 2, "Surname", strSurname,"Client_Creation")
Call WriteExcelDataSingle(sFileName, 2, "Given_Name1", strGivenName,"Client_Creation")
'#### This code will read the values created by the code above
Call OpenExcel(sFileName, vSheet)
strClientType1 = ReadExcelDataSingle(sFileName,Row,"ClientTypeS",vSheet)
strSurname1 = ReadExcelDataSingle(sFileName,Row,"Surname",vSheet)
strGivenName1 = ReadExcelDataSingle(sFileName,Row,"Given_Name1",vSheet)
Call CloseExcel(sFileName)
'###############################################################
###############################
'# The code below will read across columns
'#
'#
'###############################################################
###############################
iRow = 2
ControlVar_1 = 1
Call OpenExcel(sFileName, "Client_Creation") 'Open Data File for read
'TestVar = ReadExcelDataSingle(sFileName,iRow,ControlVar,"Client_Creation")
'******************************************************************************
'* ReadExcelDataSingle Developed by: Steve Morrin
'*
'*
'* Converted for QTP use by: Ian Fraser 01 Dec 2005
'* 20/06/03 Steve Morrin Add dictionery
'******************************************************************************
'* Example
'* strTest = ReadExcelDataSingle(sFileName,2,"PolicyNoHom","Global")
'*
Public Function ReadExcelDataSingle(sFileName,iRow,sFieldName,vSheet)
Dim sData
Dim iNoError
Dim sCurrentProc
Dim sWinDir
Dim lResult
Dim strMsgText
Dim iColNum
Dim sTestData
Dim ColHead
'Count Columns
ColCount = objWorkSheet.UsedRange.columns.count
ReadExcelDataSingle = sData
End Function
'******************************************************************************
'******************************************************************************
'* OpenExcel
'*
'* Open XL ready for read
'******************************************************************************
Public sub OpenExcel(sFileName, vSheet)
'See if a sheet was referenced in the call. If not, default to the first sheet
If vSheet = "" Then
vSheet = 1
End If
objWorkBook.WorkSheets.Add
'objWorkBook.WorkSheets.Select
newName = objWorkBook.ActiveSheet.Name
objWorkBook.WorkSheets(newName).Name = vSheet
'Save the changes
objWorkBook.Save
end if
End sub
'******************************************************************************
'******************************************************************************
'* CloseExcel
'*
'* Close XL
'******************************************************************************
Public sub CloseExcel(sFileName)
'Open up Excel
If fso Is Nothing Then
Set fso = CreateObject("Excel.Application")
End If
objWorkBook.WorkSheets(newName).Name = vSheet
'Save the changes
objWorkBook.Save
end if
'Count Columns
ColCount = objWorkSheet.UsedRange.columns.count
'write data to XL
objWorkSheet.Rows(iRow).Columns(iColNum).Value = vValue
objExcel.Quit
set objExcel = nothing
end if
End Function
'###############################################################
#############################
'###############################################################
#############################
'# Function to look up a stored check point and when detected optionaly provide for reposition.
'* Converted for QTP use by: Ian Fraser 14 Dec 2005
'* 20/06/03 Steve Morrin
'* Associated Scripts
'* OpenExcel.vbs
'*CloseExcel.vbs
'*GlobalVars.vbs
'###############################################################
#############################
'#Set Start Row (Check Re-Start Value in DataTable)
'#ChkCol = "Re-Start"
'#Row = GetCheckpoint(sFileName ,ChkCol, vSheet)
'###############################################################
#############################
Public Function GetCheckpoint (sFileName ,ChkCol, vSheet)
if vSheet = "" then vSheet = 1
'###############################################################
############
'******************************************************************************
'Used to end any remaining Excel processes
Public Sub KillExcel ()
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")