Managing Test Result
As the name itself indicates Reporter Object reports test results at the end of running the test.
The method of Reporter Object is ReportEvent
Reporter.ReportEvent StatusOfTest, TypeOfMessaege, Details
Example:
Reporter.ReportEvent micPass, "Alert", " The test performed here has succeed"
Reporter.ReportEvent micFail, "Failure", " The test performed here has succeed"
Reporter.ReportEvent micDone, "Done", " The test performed here has succeed"
Reporter.ReportEvent micWarning, "Warning", " The test performed here has succeed"
The Status of Test can be
micPass
micFail
micDone
micWarning
micInfo
micGeneral
micGeneral is also considered as micDone
Apart from these, any junk text entered in StatusOfTest is considered as micPass.
Note that, mic stands for Mercury Interactive Constant
The Type of Message will be displayed in the left panel of the test result. When the message type is selected, the corresponding details are displayed in right panel.
Filter:
If we want the test result should not display any of the pass or fail status, we can set the mode of the result window while running the script.These modes can be set in Filter property of Reporter Object
The different modes are
rfEnableAll
rfEnableErrorsAndWarnings
rfEnableErrorsOnly
rfDisableAll
When no filter mode is set,the default one is rfEnableAll, where all the pass, failed and warnings are displayed in the test result
To set any mode:
Reporter.Filter = AnyMode
To Display the current mode in the test
MsgBox Reporter.Filter
Other properties of Reporter Object are Reportpath and RunStatus
Customising the Test Result
The results of each QTP run session are saved in results.xml which is located in C:\Documents and Settings\...\Local Settings\Temp\TempResults\Report. This xml file stores information on each of the test result nodes. Each node in the run results tree is an element in the results.xml file. You can create a customized .xsl file that specifies the information to be included in the printed report, and the way it should appear from this xml file.
Few More on Datatable...
Adds a column to the sheet in the run-time Data Table, and sets the value of the first row.
GetParameter
Retrieves the specified parameter from the run-time Data Table sheet.
DeleteParamater
To delete a parameter from a sheet in datatable
Any changes made using these methods will effect the run-time DataTable only which can be seen on the test results window at the end of running the test. These changes will not effect the Design time datatable. These can be retrieved and used in the script too.
Example
' Create a column header UserName and password and sets the first value as CNR and prokarma
DataTable.GlobalSheet.AddParameter "Password", "prokarma"
'Here the row pointer will be pointing to the first row in the datatable and will be picking up the values existing there.
val2=DataTable.GetSheet(1).GetParameter("Password")
MsgBox Val1 & " " & Val2
val4=DataTable.GetSheet("dtGlobalSheet").GetParameter("Password")
MsgBox Val3 & " " & Val4
Datatable("userName",1)="pranav"
Datatable("Password",1)="newpwd"
val6=DataTable.GetSheet(1).GetParameter("Password")
MsgBox val5 & " " & val6
Operations on Datatable
There are Two Types of Data tables.
Design Time datatable: is the one which we find on the main screen, consisting of Global Data Sheet and Local Data Sheets
Run time datatable: is the one that is displayed in the test results window.
Multiple sets of test data is placed in the design time datatable in any of the sheets (either global or local datasheets)and is used by the script to parameterise it.
The methods used on datatable are:
Datatable.AddSheet: To add an extra sheet to the datatable. Datatable.AddSheet "SheetName"
Datatable.DeleteSheet: To delete a specified sheet from the datatable. Datatable.DeleteSheet "SheetName"
Datatable.ImportSheet: To Import data from a specified sheet in the excel file to a specified sheet in the datatable. Datatable.ImportSheet "Path of excel File", SourceSheetID, DestinationSheetID eg: Datatable.ImportSheet path.xls, 1, 3
Datatable.Import: To Import data present in all the sheets in an excel file to datatable. Datatable.Import "Path of excel File"
Datatable.ExportSheet : To Export the specified sheet of data in the runtime datatable to a specified location. Datatable.ExportSheet "Path of excel File", SourceSheetID, DestinationSheetID
eg: Datatable.ImportSheet path.xls, 1, 3
Datatable.Export: To Import All sheets of data from Run time datatable to a specified locaiton. Datatable.Export "Path of excel File"
SetCurrentRow: To set the QTPs pointer in the datatable on the current Row number given
eg: SetCurrentRow(4): sets the focus of QTP on the 4th row of the Datatable.
SetNextRow: To set the QTPs pointer in the datatable on the Next Row
eg: SetNextRow
SetPrevRow: To set the QTPs pointer in the datatable on the Previous Row
eg: SetPrevRow
GetSheet: To kae QTP focus on a specified Sheet
eg: Datatable.GetSheet(2)
GetSheetCount: To get the number of Sheets in the datatable.
eg: cnt=Datatable.GetSheetCount
GetRowCount: To get the number of rows in the give sheet. By default, GetRowCount will give number of rows in the Global Sheet
eg: Datatable.GetSheet(3).GetRowCount
Datatable.GetRowCount
GetParameterCount: To get the number of columns in a given sheet.
eg: Cnt = DataTable.GetSheet(1).GetParameterCount
Value: To Capture a value from specified Sheet, Specified Column and currently focussed row.
Eg: Datatable.Value("ColumnName",SheetID) OR Datatable.Value("ColumnName",SheetID)
The ColumnName is the column header in a given sheet of datatable. SheetID for the Global sheet is 1 and Second Sheet is 2, Third sheet is 3 and so on.
Datatable.ExportSheet "C:\Res.xls",2'
'Delete the sheet added in datatable
Smart Identification of Objects
1. Mandatory property
2. Assertive property
3. Base filter property
4. Optional Filter property
QTP will learn the object in the following way
BY NOT SELECTING SMART IDETIFICAITON
(Tools->object identification->uncheck smart identification)
QTP will learn the mandatory properties of an object and check if these properties are sufficient to identify object uniquely. If it is sufficient, then it will stop learning further. Othewise it will learn the first assertive property too and again check whether all these properties are sufficient to identify the objects uniquely. If sufficient, it stops learning. Othewise it learns the remaining assertive properties one by one and checks(after each property is added) whether these properties are enough to identify object uniquely. This process continues till QTP identifies object uniquely or up to the end of assertive properties list. At the end of Assertive properties also, if QTP is unable to identify the object uniquely, then finally it will learn the Ordinal identifier and stops learning.
BY SELECTING SMART IDENTIFICAITON
(Tools->object identification->check smart identification)
1. QTP will learn all the mandatory properties along with them it will also learn Base Filter and Optional Filter properties and store Base Filter Properties and Optional Filter Properties separately away from Object Repository and consider whether the Mandatory properties alone are sufficient to identify the object uniquely. If not sufficient it repeats the same process as above.
2. QTP will use all the properties (Mandatory properties, Assertive properties) present in Object Repository except Ordinal Identifier and try to identify the object uniquely. If it is unable to identify the object, then it will leave all the properties in Object Repository and use the Base Filter Properties, Optional Filter Properties. Consider all the Base Filter Properties at a time to identify the object uniquely (by matching these properties with the entire object present in application) If these properties are matched with more than one object, then it will form a list of all the objects matched and then consider the first Optional Filter Properties. It checks whether these properties are matching with objects present in the list. If this property also is matching with more than one object in the list, then it will form a new list of objects that are matched.Then, it will consider the second Optional Filter Property and check whether this property is matching with the objects present in the new list. If the property is matching with more than one object then once again the new list of objects is formed with all the objects that are matched, This process is continued till the new list contains one object or up to the end of Optional Filter Properties list. If still QTP fails to identify the object, then finally it will check whether Ordinal Identifier is available. If it is available, using that roughly object is identified.
If QTP successfully uses Smart Identification to find an object, the step is assigned a Warning status in the Test Results, and the result details for the step indicate that the Smart Identification mechanism was used. The step still receives a passed status.
If QTP cannot identify the object, then it stops the run session and displays run error message.
When multiple objects in an application have the same property?
This can be done using Description Object and ChildObjects. Description object creates a Properties collection object. It has a method 'Create'. This method creates an empty description object in which you can add collection of properties and values in order to specify the description object in place of a test object.
ChildObjects returns the collection of child objects within the object.
If in the above example if the five List boxes have the same name, html id and class. To identify each of the listbox uniquely,
obj("micclass").value = "WebList"
obj("class").value= "abc"
obj("name").value = "List1"
obj("html id").value = "htm1"
Set newObj = Browser("...").page("...").ChildObjects(obj)
Here instead of specifying each of the Listboxes by its properties, we identify them as newObj(0), newObj(1), newObj(2), newObj(3)
so, to select an item "abc' from third List box in this browser
To display the number of similar child Objects with the same description
Properties - to idetify Objects
- abs_x
- abs_y
- class
- name
- html tag
- html id
- index
- innertext
- outertext
- outerhtml
- value
- visible
These Object can be used in the object repository description, in programmatic descriptions, in checkpoint and output value steps, and as argument values for the GetTOProperty and GetROProperty methods.
What is Descriptive Programming?
For example: If a Text box in a web page has the property 'name' as 'UserName' defined in the application and no other text box in the application has the same name, and if we want to write name as ABC in the text box. then,
One need to be able to identify the objects uniquely in AUT with their properties and should have enough knowledge of VB Script to generate script.
Descriptive Programming is used when:
The object in the application are dynamic in nature and need special handling to identify the object.
When object repository is getting huge due to the no of objects being added. If the size of the object repository increases too much then it decreases the performance of QTP while recognizing the object.
If you want to take action on similar type of object i.e. suppose we have 20 Editboxes on the page and there names are in the form edt_1, edt_2, edt_3 and so on. Now adding all 20 edit boxes description in Object repository would not be a good programming approach.
Suppose, we have an application that has not been developed yet.Now QTP recording the script and adding the objects to the object repository needs the application to be up. That would mean waiting for the application to be deployed.But if we know the description of the objects that will be created then we can still start of with the script writing for testing.