Managing Test Result

Reporter Object
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"
R
eporter.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...

AddParameter
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 "UserName", "CNR"
DataTable.GlobalSheet.AddParameter "Password", "prokarma"

'Picking up the value from UserName and save it in val1, val2 to use it further

'Here the row pointer will be pointing to the first row in the datatable and will be picking up the values existing there.



val1=DataTable.GetSheet("dtGlobalSheet").GetParameter ("UserName")
val2=DataTable.GetSheet(1).GetParameter("Password")
MsgBox Val1 & " " & Val2

Datatable.SetNextRow ' Second row

'The row pointer will be pointing to the next row in the datatable and will be picking up the values existing there.

val3=DataTable.GetSheet(1).GetParameter ("UserName")
val4=DataTable.GetSheet("dtGlobalSheet").GetParameter("Password")
MsgBox Val3 & " " & Val4

' We can as well put the values back into the datatable

Datatable.SetNextRow ' Third row
Datatable("userName",1)="pranav"
Datatable("Password",1)="newpwd"
val5=DataTable.GetSheet(1).GetParameter ("userName").Name
val6=DataTable.GetSheet(1).GetParameter("Password")
MsgBox val5 & " " & val6

We can even create a new sheet into the data table and add few values in it

DataTable.AddSheet("MySheet").AddParameter("AccountNumber","047845")

The parameter from the MySheet can also be deleted.

DataTable.GetSheet("MySheet").DeleteParameter("AccountNumber")

Operations on Datatable

When running a GUI application, a script is run for a test data. Datatable is used to run the same script for multiple sets of data. DataTable parameterizes, so that your test runs multple times, each time using a different set of data.
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.


Example : To add two numbers A and B and compare them with the another column ExpectedVal in the datatable and the value Result from application.
' adding a new sheet to datatable
Datatable.AddSheet "Addition"
'importing from 1st sheet of add.xls to 2nd sheet of datatable
Datatable.ImportSheet "C:\Add.xls", 1,2
' get number of rows from second sheet of datatable
n=Datatable.GetSheet(2).GetRowCount
For 1= 1 to n
' set the current row as i
Datatable.SetCuttentRow(i)
Browser("...").Page("...").WebEdit("name:=a").Set Datatable(A,2)
Browser("...").Page("...").WebEdit("name:=b").Set Datatable(B,2)
Browser("...").Page("...").WebButton("name:=add").Click
' putting expected value under column AB of 2nd Sheet
ExpectedVal=Datatable(AB,2)
' getting the resuld of addition from the application
Result=Browser("...").Page("...").WebEdit("name:=result").GetROProperty("innertext")
If (ExpectedVal=Result) Then
' save Pass under Result column in 2nd Sheet
Datatable("Result",2)="Pass"
Else
' save Fail under Result column in 2nd Sheet
Datatable("Result",2)="Fail"
End IF
Next
' exporting sheet from 2nd sheet of datatabel to system drive C
Datatable.ExportSheet "C:\Res.xls",2'
'Delete the sheet added in datatable
Datatable.DeletSheet "Addition"

Smart Identification of Objects

When ever QTP is unable to idetify the object using the properties defined in the script or in Object Repository, the special machnism to identify the object using other properties is called Smart Identification. Object Idetiifcation concept is basd on 4 types of properties and a ordinal number.
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?

There might be situations when multiple objects in AUT have the same property and hence you will not be able to identity the objects uniquely. For example, there are five list boxes in a web page, which have identical properties. In such situation, QTP will not be identifying each of the list boxes uniquely.
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. T
o identify each of the listbox uniquely,

Set obj = Description.create()
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

Browser("...").page("...").newObj(2).Select "abc"

To display the number of similar child Objects with the same description

MsgBox newObj.Count

Properties - to idetify Objects

There are different properties to identify objects. All the properties available for an object can be obtained using Object Spy or Object Repository. Using object spy,select the hand icon on object spy and move the mouse over or click the object whose properties are needed. Using the object repository, add the objects into the repository to view the properties. The properties that are normally used to identify objects are:
  • abs_x
  • abs_y
  • class
  • name
  • html tag
  • html id
  • index
  • innertext
  • outertext
  • outerhtml
  • value
  • visible
Apart from the above, each of the Web Elements might have some additional properties. For example, WebList have a property 'select type'. It has values Single Selection, Combobox Select, Extended Selection depending on the type of ListBox. Similarly, WebEdit has the property 'max length' and WebButton has 'disabled' property.
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?

QTP cannot take action on an object unless its object description is in the Object Repository. But descriptive programming provides a way to perform action on the objects by identifying them by their properties. Few of the properties using which an object can be defined are name, text, innertext ..etc,. Each object should be identified uniquely by QTP either by using single property or multiple properties.
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,

Browser("..").page("...").WebEdit("name:=UserName").Set "ABC"
Here using the properties within the Brackets for 'Browser', the browser is identified uniquely. using similarly, using the properties within the Brackets for 'Page', the page is identified uniquely. Finally the edit box is identified using the property 'name' of the edit box and the value ABC is set in the text area.
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.

Record and Play

Record and playback will only work in the most trivial of circumstances. It is not a viable solution for any practical application. To make your scripts robust enough to run on any machine or environment requires a development effort in it own right. The skills required to write these scripts depend on the complexity of your applications as well.
If the properties of the objects in the AUT change over time, then you can use descriptive programming and regular expressions to make the scripts adaptable.

In recode and Play, all the properties of the objects recorded are stored in the object epository. When playing the recorded script, QTP identifies the objects in the application by looking for them back in the object repository. once identified, the corresponding action to be done is performed on those objects.

What is QTP?

QTP is an automated functional testing tool for different environments.You will use Quick Test Professional’s graphical point and click interface to record and play back tests, add synchronization points and verification steps, as well as create multiple action tests.