Thursday, 19 April 2012

Smart Identification In QTP

As we know that QTP is object based tool. QTP uses the learned object description to identify the objects. It searches for an object that matches with all of the property values in the description. In most of the cases the object description is the simplest way to identify the object, unless the main property values of the object change.

If QTP is unable to find any object that matches the learned object description, or if it finds more than a objects matches the learned description, and uses the Smart Identification mechanism to try to identify the object.

While Smart Identification(SI)  is more complex, it's more flexible. Therefore, the SI is configured logically, Smart Identification definition can probably help QTP to identify an object,if it present even the learned description fails.

Smart Identification mechanism use two types of properties.

Base Filter Properties: These are the fundamental properties of a particular object class.The values of the these properties can't be changed without changing the essence of the original object.
Example: Assume that the web link's tag is changed from {a} to some other value, you could no longer call it the same object.

Optional Filter Properties: Assume that the QTP is not able to identify the object with the help of Base Filter Properties. In that case QTP will use Optional Filter Properties to identify the object of a particular class.These properties are unlikely to changes on a regular basis, but can be ignored if they are no longer applicable.

Smart Identification Steps:
01. QTP forgets the learned test object description and creates a new object candidate list containing the objects that matches all of the properties defined in Base Filter properties.

02.QTP filters out the object in the object candidate list that does not match the first property listed in the Optional Filter Properties list. The remaining objects become the new object candidate list.
 
03.QTP evaluates the new object candidate list.
 
 03.00.If the new object candidate list still has more than one object, QTP uses the new object candidate list to repeat step 2 for the next optional filter property in the list.
 
 03.01.If the new candidate list is empty, QTP ignores this optional filter property, returns to the previous object candidate list, and repeats the step 2 for the next optional filter property in the list.
 
 03.02.If the candidate list contains only one object then QTP concludes that it has identified the object and performs the statement containing  the object.

04. QTP continues the process described in the step 2 and 3 until it either identifies one object, or runs out of Optional Filter Properties to use.

Assume that QTP is not able to identify the object even after Smart Identification elimination process.In such case QTP will use the learned description plus the ordinal identifier to identify the object.
 
If third combination is also not able to identify the object, QTP stops the run session and displays the error message.

Tuesday, 10 April 2012

Batch Testing In QTP

Batch Testing or Batch execution represents the execution of series or group of automated tests at a time.QTP provides a tool called "Test Batch Runner" to execute the group of Tests.

We can form a Test Batch by following the below mentioned steps.

01. Navigate to Start > All Programs > Quick Test Professional > Tools > Test Batch Runner
02. Observe that the Bach tool is launched
03. Then click on Batch> Add and Browse the Tests to be added
04. Select the Test and observe that the Test is added to Batch Tool
05. Repeat the above steps to add n-Number of Tests
06. Then the MTB(Module Test Batch with ".mtb" extension
07. Close the Test Batch Runner tool

We can execute the Test Batch by following the below mentioned Tests.

01. Launch the Test Batch Runner tool by navigating to "All Programs > Quick Test Professional > Tools > Test Batch Runner" path
02. Navigate to File> Open > Select the batch to be executed
03. Click on Run icon and observe that QTP is launched
04. QTP will run the Tests one by one

Note: We can execute the tests by using other Mercury tools. To do this we should configure Tools> Options> Run >Select "Allow Other Mercury Products" check box > Apply & OK.

We can also execute only Partial Test Batches by navigating to Test Batch Runner> Open Test Batch> Select or Deselect Tests and Run test.

We need to follow the below mentioned steps when doing Batch Testing.

01. Create individual Tests and execute once
02. Open "Test Batch Runner" Tool and Form Batches
03. Provide Permission to "Test Batch Runner" tool to run tests
04. Run the Tests from Test Batch Runner tool
05. View the Test wise results in Test Result viewer

QTP doesn't provide an option to view the result in Batch wise.

Wednesday, 4 April 2012

Parametrization In QTP

Parametrization is mainly useful when the functionality is tested with different sets/ types of data. This is mainly used in Data Driven Testing.

We have different ways to parametrize the tests.

Loop Statements: We can use the loop statements for passing sequential numbers and Logical Numbers.
Assume that we are going to enter numbers in a sequential manner in a text box.
Example: Flight Application
 
For i=0 to 20
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.').Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set i
Window("Flight Reservation").Dialog("Open Order").WinButton("OK').click
Next

We need to remember that strings can't be generated through Loop Statements. But the same can be achieved with the help of Dynamic Data Submission.

Dynamic Test Data Submission:
We can pass the strings thought loop statements. But the user interaction is required.

Example:
For i=0 to 20
uName=inputbox("Enter User Name:")
pwd = inputbox("Enter Password:")
'Use the following snippet
Dialog("Login').WinEdit("UserName").Set uName
Dialog("Login').WinEdit("UserName").Type micTab
Dialog("Login').WinEdit("Password").SetSecure pwd
Dialog("Login').WinEdit("Password").Type micTab
Next
 
Data Table:
As we know that QTP uses one data table for every test. We have the following types when using Data Table for parametrization.

01.Entering test data directly to data  table and use.
02.Importing test data from external spread sheets.
03.Importing test data from external flat files.

Entering Test Data Directly to Data Table and Use:
We need to follow the below mentioned steps when entering and using Test Data directly to Data Table.

01. Generate Test > Open Data Table
Note: The Data Table can be opened by navigating to View> Data Table
02.Click on the column header> Enter the name of the field(Ex:UserName)> Enter Data> Connect data to Test by using the following code snippet.

variable=datatable("column name",sheet id)
Ex: uName = datatable("UserName",1)
03.Run the test

Example:
uName= DataTable("UserName',1)
pwd = DataTable("Password",1)

Importing Test Data From External Spread Sheets:
We have to follow the below mentioned steps when using spread sheets for parametrization.
01. Open Data Table> Place the mouse pointer on Data Table and right click> File> Import From File>Click Ok>Browse the path of the excel sheet.
02.Then connect the data sheet to test by using the code snippet "
variable=datatable("column name",sheet id).
03.Execute the test.

Importing Test Data From External Files:
We can also import the data from external flat files by following the below mentioned steps.
01. Open Data Table> Place the mouse pointer on Data Table and right click> File> Import From File>Click Ok>Browse the path of the file sheet.
02.Then connect the data sheet to test
03.Execute the test.
Example:
Dim fso,ffile
Set fso=CreateObject("Scripting.FileSystemObject")
Set ffile = fso.opentextfile("D:\Automation\test.txt",1)
ffile.skipline
While ffile.atendofline<>true
a=ffile.readline
b=split(a,"@")
'Write code to launch application here...
'The following snippet is to set the data read from the file to 'variable.
Dialog("Login").WinEdit("UserName").Set b(0)
Dialog("Login").WinEdit("UserName").Type micTab
Dialog("Login").WinEdit("Password").SetSecure b(1)
Dialog("Login").WinEdit("Password").Type micTab

Apart from the above methods we can fetch the data directly from the database as well as we can use the Dictionary object for parametrization.

Using Dictionary Object:

Set inputdata= CreateObject("Scripting.Dictionary")
inputdata.add "Username", "stc"
inputdata.add "pwd", "hp123"
'Write code to launch application here...
'The following snippet is to set the data read from the file to 'variable.
Dialog("Login").WinEdit("UserName").Set inputdata("Username")
Dialog("Login").WinEdit("UserName").Set inputdata("pwd")

 
Back To Top