Search This Blog

Wednesday, December 29, 2010

Smart Identification Explained

When qtp fails to identify any object uniquely with help of learned description of the object it uses smart identification.Normally qtp uses its learned description for identifying an object & this learned description is sufficient to identify any object uniquely as it does not frequently but anyhow if any point of time qtp unable to identify object using its description or it finds more than one object, then it use smart identification techniques.

The Smart Identification Technique uses two properties :
  • Base Filter Properties. The most fundamental properties of a particular test object class; those whose values cannot be changed without changing the essence of the original object. For example, if a Web link’s tag was changed from <A> to any other value, you could no longer call it the same object.
  • Optional Filter Properties. Other properties that can help identify objects of a particular class. These properties are unlikely to change on a regular basis,but can be ignored if they are no longer applicable.
Smart Identification Process : 
QTP initiate smart identification Process when it is not able to identify any object during run session or more than one object with same description.Th following process is followed to identify object.
  1. As soon as smart identification initiate qtp forget all learned description based on mandatory & assistive properties & ordinal identifiers & create a new object candidate list containing the object which matches all of the defined base filter properties.
  2. QuickTest filters out any 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.
  3. QuickTest evaluates the new object candidate list:
    • If the new object candidate list still has more than one object, QuickTest uses the new (smaller) object candidate list to repeat step2 for the next optional filter property in the list.
    •  If the new object candidate list is empty, QuickTest ignores this optional filter property, returns to the previous object candidate list, and repeats step2 for the next optional filter property in the list.
    •  If the new object candidate list is empty, QuickTest ignores this optional filter property, returns to the previous object candidate list, and repeats step2 for the next optional filter property in the list.
  4. If the new object candidate list is empty, QuickTest ignores this optional filter property, returns to the previous object candidate list, and repeats step2 for the next optional filter property in the list.If the object candidate list contains exactly one object, then QuickTest concludes that it has identified the object and performs the statement containing the object QuickTest continues the process described in steps2 and3 until it either identifies one object, or runs out of optional filter properties to use.
    If, after completing the Smart Identification elimination process, QuickTest still cannot identify the object, then QuickTest uses the learned description plus the ordinal identifier to identify the object.If the combined learned description and ordinal identifier are not sufficient to identify the object, then QuickTest stops the run session and displays a Run Error message.
Reference : QTP help.




Tuesday, December 21, 2010

Object Identification Properties



In my last post i told you how qtp identify any object. Now we will discuss what all properties of an object qtp uses to uniquely identify it.

QTP uses following properties to uniquely identify any object 

1.    Mandatory Property 
2.    Assistive Property 
3.    Ordinal Identifier 
4.    Smart Identification

Before recording, these properties has to be defined for each object by a test engineer in QTP>Tools>Object Identification.

Let’s discuss these in detail.

1.    Mandatory Property :
As per qtp help “Quick Test has a list of mandatory properties that it always learns”. Whenever we record any object as Test Object QTP learns its specified mandatory properties which helps to uniquely identify any object. If QTP feel that these are more objects with same description it learns Assistive Properties.

2.    Assistive Properties :
As per qtp help are “Assistive Properties are properties that QuickTest learns only if the mandatory properties that QuickTest learns for a particular object in your application are not sufficient to create a unique description. If several assistive properties are defined for an object class, then Quick Test learns one assistive property at a time, and stops as soon as it creates a unique description for the object. If QuickTest does learn assistive properties, those properties are added to the test object description.”

3.    Ordinal Identifier :
As per qtp Help - The ordinal identifier assigns the object a numerical value that indicates its order relative to other objects with an otherwise identical description (objects that have the same values for all properties specified in the mandatory and assistive property lists). This ordered value enables QuickTest to create a unique description when the mandatory and assistive properties are not sufficient to do so.

The assigned ordinal property value is a relative value and is accurate only in relation to the other objects displayed when QuickTest learns an object. Therefore, changes in the layout or composition of your application page or screen can cause this value to change, even though the object itself has not changed in any way. For this reason, QuickTest learns a value for this backup ordinal identifier only when it cannot create a unique description using all available mandatory and assistive properties.

In addition, even if QuickTest learns an ordinal identifier, it will use the
identifier during the run session only if the learned description and the Smart Identification mechanism are not sufficient to identify the object in your application.

If QuickTest can use other identification properties to identify the object during a run session, the ordinal identifier is ignored.

QuickTest can use the following types of ordinal identifiers to identify an
object:
  • Index. Indicates the order in which the object appears in the application code relative to other objects with an otherwise identical description.
  • Location. Indicates the order in which the object appears within the parent window, frame, or dialog box relative to other objects with an otherwise identical description.
  • Creation Time. (Browser object only.) Indicates the order in which the browser was opened relative to other open browsers with an otherwise identical description.
When qtp identifies any object first, it learn all of its specified mandatory properties, if object is uniquely identified with these mandatory properties qtp stop learning its properties if qtp feel it is not able to identify object uniquely with help of all mandatory properties, it learns first assistive properties & verify if it is  ok to identify object uniquely, if still it feels that it need some more properties it learns second assistive property & this process continues till QTP identify the object uniquely.

Some time Mandatory & Assistive Properties are not sufficient for description of an object so it uses ordinal identifier to identify.

As last attempt to learn description the object if above all Properties fail to identify object uniquely it uses Smart Identification.

We will discuss Smart Identification later in detail.

Monday, December 20, 2010

How QTP identifies objects ???


How QTP identifies objects ???

QTP uses human like methods to identify any object. How we identify our friends/relatives????? Have you ever thought what process we follow to identify & remember any object in real world?....OK its rather simple as it seems when we see anything first time our mind remember some unique properties of this object….just like when I first saw Eiffel Tower I remember its design, Place,Colour,Height etc.So next time when I will see this my brain will use that information as repository of properties & check if any property of that building matches with same object…if both of the properties matches I will recognize this building as Eiffel Tower.

Some time you have experienced that you teach a kid A for Apple. How he remember Apple ? He identifies that apple is red colour fruit so when you show him some other red colour fruit look like apple he gets confused. Now later on when he retires & learns more properties of Apple on showing another fruit with same/different properties he identifies Apple successfully.

Now process of identifying objects might me clear in your mind same way QTP behaves like human when QTP records any object its captures its properties with its logical name & Physical description.i.e. Name, URL, html id etc & stores them in its object repository (Local/Shared), this object is save as Test Object. These properties are not dependent on location in AUT so even though in successive builds if your objects change location in AUT your test will not fail. When we run our test qtp checks for same objects which it stores in its repository in AUT & identify them using its properties stored in repository.

QTP uses following properties of Test Object to identify.

  1. Mandatory Property
  2. Assistive Property
  3. Ordinal Identifier
  4. Smart Identification
We will discuss these properties in detail in my next post….

Wednesday, November 24, 2010

QTP Automation Process 

Any automation process is similar in nature & independent on any tool used, topic which we are discussing here is based ion QTP but you can follow it with any Functional Tool. Automation process is nothing but a set of instructions or guidelines which needs to be followed strictly & sometime moderately :) as per our requirements. As we start automation we should take care of area which needs to be automated. Very well discussed with many internet forums we al know that automation of entire application is neither feasible nor advised though its possible to automate the entire application but normally stakeholders focus on area to automate which is more to regress.

There are 6 basic guidelines in automation process.
1. Planning
2. Prepare to Test
3. Record your script.
4. Enhancement to Script
5. Running & Debugging Test
6. Analyzing your Run Result

Lets explore it more in details:

1. Planning: Planning the most important part in any activity. When you think about automation of the application you start planning for this. First you have to analyze your application to determine for your testing needs. This includes understanding of platform & environment. Based on this you will load QTP Add-ins, for example if your application is developed in .net environment & some objects used are of Java then you should be having .net as well as Java Add-ins loaded in QTP. Now you have to look for the business process which you are going to test, you have to break these Business Process to modular & smaller units which will be used as actions. With help of these actions you will simulate user activity which he will perform in your application. Modular actions will help to maintain your automation.

2. Prepare to Test: Now you have to determine what resources you required to test your application. As per your requirement you will decide for Shared/ Per Action Repository. You will create shared repository & Function Libraries, if you have some test specific preferences you will set it, set your Run & Record Settings, Create recovery scenario (this you can do later as well if you find any scenario). Set folder options & associate your function libraries with your test & lastly associate your shared repository to actions.

3. Record your script : As you navigate or simulate user actions with your application QTP graphically displays each step you perform as a row in the keyword view, these steps are also displayed in expert view as VBScript steps.Complete your action & QTP displays each object you worked in Keyword View or you can drag/drop objects to create some user generated steps.

4. Enhancement to Script: Till now your basic structure is ready but you have do nothing as you have not test anything. If you run your script you will find that nothing has Passed/Fail. We just navigate to this application & logout. Ok Lets test something. For verifying or testing we enhance our script by inserting Checkpoint, Regular Expressions,OutPut Value, Parameterization.(We will discuss it later)

5. Running & Debugging Test : OK….you are grooming better :)…..now you have everything ready.You have done all Enhancement now its time to run your test.As you run your script, QTP connects to your application & simulate all steps as you created in actions. It checks for all strings, tables, objects etc which you deal while recording & verify for enhancement you made using checkpoints, Output alue, Parametrization etc. You can control you run session & debug your test if you want during run session apart from breakpoint you can use Step Into, Step Over,Step Out Commands to run your test step by step. You can run your test to update your script. 2 Modes are provided for this purpose a) Maintenance Run Mode : Used to update script if Application/Object has changed. b) Update Mode: Used to update changed object prosperities.

6. Analyzing your Run Result: Now you got some test which fail & some test which are pass. You get summary/detailed report of your test Run & cause if you capture Still Images/Movie for you test. You can log defects as per your test.

Friday, November 12, 2010

Send unlimited Free SMS with help of QTP

Sending sms on occasions like diwali,new year etc is very hectic & time taking process & consume lot of money too.It takes around 2-3 hours of my time & lot of money as most of the service providers raise there prices on these ocassions.But this time I save my money as well as time with help of qtp…how ???????????????

Answer is very simple there are lots of websites available which are providing free sms service you just have to create you login & register your mobile number with them & they offer you unlimited SMS’s.

I’ve used Indyarocks.com for this purpose.I have created a login & registered my mobile number with them.Then I record the message sending process using QTP in 3 steps

 Login

 Send Message

 Logout

1. Browser("Indyarocks - India's No.1").Page("Indyarocks - India's No.1").WebEdit("username").Set "abc”

2. Browser("Indyarocks - India's No.1").Page("Indyarocks - India's No.1").WebEdit("pass").SetSecure "fdkff34tl3k4l345tk5makhgsdf434j4ffddsfsaq"

3. Browser("Indyarocks - India's No.1").Page("Indyarocks - India's No.1").Image("but_home_login_rock").Click

4. Browser("Indyarocks - India's No.1").Page("My Life at Indyarocks").Link("Free SMS").Click

5. Browser("Indyarocks - India's No.1").Page("Free SMS to India, Free").WebEdit("frno").Set DataTable("Number", dtGlobalSheet)-------- (Parametrize number.)

6. Browser("Indyarocks - India's No.1").Page("Free SMS to India, Free").WebEdit("message3").Set "Happy Diwali" & vbNewLine & "XYZ"

7. Browser("Free SMS
Send free SMS").Page("Free SMS
Send free SMS").Image("Send Free SMS").Click

8. Browser("Indyarocks - India's No.1").Page("Free SMS to India, Free_2").Link("Logout").Click

9. Browser("Indyarocks - India's No.1").Page("Indyarocks - Login").Sync

Steps:
1. Create a user with http://www.indyarocks.com & register your mobile phone with this site.
2. Open QTP>Automation>Record&Run Settings
3. Set http://www.indyarocks.com as application.
4. Start recording.
5. Login to application
6. Goto Link “SMS” & select “Free SMS”
7. Goto Tab Free SMS to Non-Members & Enter Mobile number & Text message.
8. Click Send.
9. Logout

I have written this script using local object repository if you want to use DP you can use that.
After finishing this test goto keyword view & select where you have entered mobile number to send sms & parameterize it with datatable.

Now copy all your contact numbers to data table column.

Run this script sit back ,relax & enjoy. This will run for as many iterations as you defined numbers in your data table.…..now just enjoy n let qtp do messaging for you.

Happy messaging.

For any other help mail me…..

~Neeraj Bhatnagar

neeraj.engg@gmail.com




Monday, May 24, 2010

QTP Automation Test Process

1) Planning

o Analyzing the AUT
o Automation Test Plan Generation
o Automation Framework Implementation
o Generating/Selecting Test cases for Automation
o Collecting Test Data
o QTP Tool Settings Configuration

2) Generating Tests
o Recording
o Keyword driven methodology
o Descriptive Programming

3) Enhancing Tests
o Inserting Checkpoints
o Inserting Output values
o Adding Comments
o Synchronization
o Parameterization
o Inserting Flow Control Statements
o Calling User defined functions and/or Reusable Actions
o Generating Steps though Step Generator
o Inserting Transaction Points
o Regular Expressions

4) Debugging Tests
o Debug Commands & Break Points
o Step by step execution
o Watching Variables
o Changing values of variables

5) Running Tests
o Normal Execution
o Batch Execution
o Through AOM Scripting
o Tests Running through framework
o Scheduled Execution

6) Analyzing Results
o QTP Result window
o Defining our own Results
o Exporting Results
o Deleting Results

7) Reporting Defects
o Manual Defect Reporting
o Tool based Defect Reporting
o Working with Quality Center

Error Handling in QTP

Yet we know about Recovery Scenario & how to use them in our scripts, there is one more magic of qtp by which we can avoid errors in script.This is called error handling.


On Error statement enable or disable error handling.
Now we will discuss two of the error handling stamenst here

1) On Error Resume Next
2) On Error Goto 0

Write bellow mentioned code in notepad & save it as “A.vbs” now run it with command prompt or double click it.

msgbox "I am Good 1"
call one
msgbox "I am Good 2"
function one()
on error resume next
msgbox "Function One start"
happy
msgbox "Function one end"
end function
msgbox "I am Good 3"

This works fine,now do one thing comment “on error resume next” line now again run it what happen an error displayed Type Mismatch “Happy”, yes now I hope you got it what “on error resume next” does .
Actually it is ignoring any error commencing in code or in your script. As in above example when it reaches to line 7 it looks for “happy” which is not declared anwahere so it displays Type Mismatch error but as we use “on error resume next”

Whereas any error displayed in code it just ignores it & move forward for next line.
So with on error resume next error is not corrected it is just ignored & our test continues.

Moreover “on error resume next” is local to a function in which it is called, it will be in effect as long as function is executes and will be nullified when the function finishes execution.

For example :

msgbox "I am Good 1"
call one
msgbox "I am Good 2"
function one()
on error resume next
msgbox "Function One start"
happy
msgbox "Function one end"
end function

function two()
on error resume next
msgbox "Function two start"
happy
msgbox "Function two end"
end function

msgbox "I am Good 3"

so this way we see that this statement is private to each function.

Err Object :

Whenever there is a run time error in the program , the properties of an Err object is filled with information which help to identify & handle error.
After an “On error resume next” statement the Error objects properties are reset to zero or zero-length strings (“”).This error object is an intrinsic it means you need not to declare it in your code before you use it.

msgbox "I am Good 1"
call one
msgbox "I am Good 2"
function one()
on error resume next
msgbox "Function One start"
happy
msgbox "Error Number Is =" &err.number& "and" & "Error Description= " &err.description
msgbox "Function one end"
end function
msgbox "I am Good 3"

Monday, February 22, 2010

QTP, Quick Test, Quick Test Pro, QTP FAQ, QTP Tips

Introduction:
This document gives answer to some FAQ and also provides tips on certain aspects of QTP.

Data TableTwo Types of data tables
Global data sheet: Accessible to all the actions
Local data sheet: Accessible to the associated action only
Usage:
DataTable("Column Name",dtGlobalSheet) for Global data sheet
DataTable("Column Name",dtLocalSheet) for Local data sheet
If we change any thing in the Data Table at Run-Time the data is changed only in the run-time data table. The run-time data table is accessible only through then test result. The run-time data table can also be exported using DataTable.Export or DataTable.ExportSheetHow can i save the changes to my DataTable in the test itself?
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 spreadsheet and then access it using the Excel COM Api's.
How can i check if a parameter exists in DataTable or not?
The best way would be to use the below code:
code:
on error resume next
val=DataTable("ParamName",dtGlobalSheet)
if err.number<> 0 then
'Parameter does not exist
else
'Parameter exists
end if
How can i make some rows colored in the data table?
Well you can't do it normally but you can use Excel COM API's do the same. Below code will explain some expects of Excel COM APIs
code:
Set xlApp=Createobject("Excel.Application")
set xlWorkBook=xlApp.workbooks.add
set xlWorkSheet=xlWorkbook.worksheets.add
xlWorkSheet.Range("A1:B10").interior.colorindex = 34 'Change the color of the cells
xlWorkSheet.Range("A1:A10").value="text" 'Will set values of all 10 rows to "text"
xlWorkSheet.Cells(1,1).value="Text" 'Will set the value of first row and first col
rowsCount=xlWorkSheet.Evaluate("COUNTA(A:A)") 'Will count the # of rows which have non blank value in the column A
colsCount=xlWorkSheet.Evaluate("COUNTA(1:1)") 'Will count the # of non blank columns in 1st row
xlWorkbook.SaveAs "C:\Test.xls"
xlWorkBook.Close
Set xlWorkSheet=Nothing
Set xlWorkBook=Nothing
set xlApp=Nothing
SMART IdentificationSmart 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 the photograph. So it kind of PI (Programmed intelligence) not AI.When should i use SMART Identification?
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 the OR. For more details refer to my BOK on DP
Recovery ScenariosWhat is a Recovery Scenario?
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.
What does a Recovery Scenario consists of?
Trigger: Trigger is nothing but the cause for initiating the recovery scenario. It could be any popup window, any test error, particular state of an object or any application error.
Action: Action defines what needs to be done if scenario has been triggered. It can consist of a mouse/keyboard event, close application, call a 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 to next step etc....
When to use a Recovery Scenario and when to us on error resume next?
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 or VBScript Files
How do we associate a library file with a test ?
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.
Test and Run-time Object
What is the difference between Test Objects and Run Time Objects ?
Test objects are basic and generic objects that QTP recognize. Run time object means the actual object to which a test object maps.
Can i change properties of a test object
Yes. You can use SetTOProperty to change the test object properties. It is recommended that you switch off the Smart Identification for the object on which you use SetTOProperty function.
Can i change properties of a run time object?
No (but Yes also). You can use GetROProperty("outerText") to get the outerText of a object but there is no function like SetROProperty to change this property. But you can use WebElement().object.outerText="Something" to change the property.
Action & Functions
What is the difference between an Action and a function?
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 have more than one output parameters.
Where to use function or action?
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 & Output value
What is checkpoint?
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....
What's the difference between a checkpoint and output value?
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.
How can i check if a checkpoint passes or not?
code:
chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))
if chk_PassFail then
MsgBox "Check Point passed"
else
MsgBox "Check Point failed"
end if
My test fails due to checkpoint failing, Can i validate a checkpoint without my test failing due to checpoint failure?
code:
Reporter.Filter = rfDisableAll 'Disables all the reporting stuff
chk_PassFail = Browser(...).Page(...).WebEdit(...).Check (Checkpoint("Check1"))
Reporter.Filter = rfEnableAll 'Enable all the reporting stuff
if chk_PassFail then
MsgBox "Check Point passed"
else
MsgBox "Check Point failed"
end if

Environment
How can i import environment from a file on disk
Environment.LoadFromFile "C:\Env.xml"
How can i check if a environment variable exist or not?
When we use Environment("Param1").value then QTP expects the environment variable to be already defined. But when we use 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 in the environment try using Environment("Param1").value.
How to connect to a database?
code:
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DRIVER={Microsoft ODBC for Oracle};UID=;PWD="
objRecordset.CursorLocation = adUseClient
objRecordset.CursorType = adopenstatic
objRecordset.LockType = adlockoptimistic
ObjRecordset.Source="select field1,field2 from testTable"
ObjRecordset.ActiveConnection=ObjConnection
ObjRecordset.Open 'This will execute your Query
If ObjRecordset.recordcount>0 then
Field1 = ObjRecordset("Field1").Value
Field2 = ObjRecordset("Field2").Value
End if