Search This Blog

Saturday, March 24, 2012

Reterive Number from a string.

We will do this test using two examples of script.

Here is example 1.
You have an string "You have sucessfully saved your order and your order no is 110."
Now your task is to get order number out of this string i.e. 110.further more you can use this order number in you other scripts. To achieve this follwing steps need to be followed.

1. var1 = "You have sucessfully saved your order and your order no is 110."
' In order to reterive the order number you have to first  determine length of  the message box.

2. msgbox len(Var1)
' Gives length of the variable.In order to get  110 if you determine positon of  "is" you can easily determine position of 110. But  take care that "is" is not duplicated.

3. MyPos = instr (1, var1, "is")
'  Instr returns location of  "is" in string. Here 1 is location form where you want to start your search in string. if search start location is not given search will always start from 1st location of search string ,Var1 is string in which you have to search & "is" the string you are searching in var1.

4. msgbox mypos
' Returns location of "is". now using mid function you can get order number .'mid function is used to reterive specified number of  characters. Mid function is defined as mid (string,start,length)
'Here String is var1.MyPos is starting location where you want to reterieve characters.As we want to reterive whole string after "is" we will not define any length so it will capture complete string after "is". if you want to capture specified number of characters you can define number of charecter you want to reterive.

5. MyOrderNumber1= mid(var1,MyPos) 
 'Using this expression you will get order number but it will not be in integer form it will be "is 110."

6. msgbox MyOrderNumber1
'As you know the starting location of "is"  (MyPos) & you know that order number start after 3rd location from starting location of " is"  we add  +3 in MyOrderNumber so that it will give you 100, as order number start from 3rd location from "is"same way if there are more characters you can add them.

7. MyOrderNumber2=mid(var1,MyPos+3)
8. msgbox MyOrderNumber2

'In variable myordernumber you will get order number "110." but  you may required to reterive only 100 & remove this dot .As we have defined in line number11 for Mid function, we have not taken length after position of "is" . Lets say we take length as 3 so myordernumber=mid(var1,MyPos+3,3) will be used & it  will give you myordernumber = 100.

9. MyOrderNumber3=mid(var1,mypos+3,3)

10. msgbox MyOrderNumber3

Example 2 :

1. var1= "You have sucessfully saved your order, your order no is 2564359. You can edit your order details in future."

2. msgbox len (var1)

3. MyPos1 = instr(1,var1,"is")
'Reterive position of "is"
4. msgbox MyPos1

5. Str1=mid (var1,MyPos1+3)
'Reterive starting position of order number as order number is starting 3rd character from starting position of "is".
6. msgbox Str1

7. MyPos2=instr(1,str1,".")
'Reterive position of dot.as we already know starting position of order number if we know ending postion of order number we can extract using mid function which Returns a specified number of characters from a string.

8. msgbox MyPos2

9. Str2=mid (Str1,1,MyPos2-1)           
'  -1 have taken, to remove extra dot.You can use MyPos2 as well but it will show ordernumber with dot.
10. msgbox str2

Thursday, June 9, 2011

Flex 4_5 Plugin for testing flex aplication with QTP

As we know QTP does not support Flex application. To automate Flex application you have to install Adobe Flex plugin for QTP which is an additional plugin & provided by Adobe to enabled Flex application to be automated by QTP.

Requirements for Using the QTP Plug-in :

HP QuickTest Professional 10 with Internet Explorer 7 & Internet Explorer 8 or HP QuickTest Professional 9.5 with Internet Explorer 6 & Internet Explorer 7
• Adobe Flex 4 Plug-in for Mercury QuickTest Pro (This you have to download from Adobe site)
• Microsoft Internet Explorer, version 6 or later
• Flash Player ActiveX control – the version of Flash Player required is the same as that supported by the Flex SDK being used to compile the application for testing.

Installing the Plug-in :

To install QTP :

1. First Install Flash Player for Microsoft Internet Explorer. This is currently the only supported browser/player.
2. If you are using Mercury QTP on Microsoft Windows Vista you need to turn off the User Account Control (UAC) feature.
3. Restart your computer.

To install the Flex 4 Plug-in for Mercury QuickTest Pro :

1. To download QTP plugin for Flex application Goto (https://www.adobe.com/cfusion/entitlement/index.cfm?e=flex4_5_automation_plugin). Login to Adobe site with existing login or create new login & download this zip file.
2. After fetting the Adobe Flex 4 Plug-in for HP QuickTest Pro zip file , unzip it on the machine where you want to install the plug-in. 2. Double Click on the Install_QTP_Plugin.bat.
3. Restart your machine.

The plug-in installer will include the following in the installation directory:
• AIR folder which will have the AIR related dlls
• FLEX folder which will have the Flex related dlls
• Uninstall_QTP_Plugin.bat Double clicking on this bat file will uninstall the QTP Plug-in.
• ReadMe.txt file.

If you want to uninstall this plugin simply run Uninstall_QTP_Plugin.bat & restart your system. Always remember do not delete you plugin installer folder.
To check if you installation is sucessfull.Check TEAPluginIE.dll,TEAPluginQTP.dll files in registery.

Now Open QTP you should see Flex & AIR plaugin in you Add-IN Manager. 
You can test http://examples.adobe.com/flex2/inproduct/sdk/flexstore/flexstore.html application as this is sample application created by adobe for you to know if your plugin is working.

Some more links related to flex automation :
http://blogs.adobe.com/vikaschandran/2010/10/18/basic-flex-automation-work-flow/
http://blogs.adobe.com/vikaschandran/category/flex-automation/page/2/

Monday, June 6, 2011

Count number of checkboxes & set them ON.

Dim obj,AllObj

Set obj= description.Create()
obj("html tag").value = "input"
obj("type").value=("checkbox")
Set obj= browser(" Browser Name").Page("Page Name").ChildObjects(obj)
AllObj=obj.count
msgbox Allobj
For i = 0 to Allobj -1
Allobj(i).set"on"
Next

Working with files

Create text file & adding a line to it :

Dim f1, fso
Set fso= createobject ("scripting.filesystemobject")
Set f1= fso.createtextfile ("D:\QTP\QTP_FSO\file2.txt", true)
f1.writeline "Hello This is new file"

Open a Text file & read line :

Dim f1, fso,ReadLineTextFile,
forreading=1
Set fso= createobject ("scripting.filesystemobject")
Set f1= fso.opentextfile ("D:\QTP\QTP_FSO\file2.txt" ,ForReading)
ReadLineTextFile = f1.ReadLine
msgbox ReadLineTextFile

Check if file already exist :

Dim f1, fso,ReadLineTextFile,file1
forreading=1
Set fso= createobject ("scripting.filesystemobject")
If fso.FileExists("D:\QTP\QTP_FSO\file2.txt") Then
 msgbox "File Already Exists"
 else
msgbox "File does not exist"
Set f1= fso.createtextfile ("D:\QTP\QTP_FSO\file2.txt", true)
f1.writeline "Hello This is new file"
End If
Set f1= fso.opentextfile ("D:\QTP\QTP_FSO\file2.txt" ,ForReading)
ReadLineTextFile = f1.ReadLine
msgbox ReadLineTextFile
f1.Close
set file1= fso.GetFile("D:\QTP\QTP_FSO\file2.txt")
file1.delete

Appending a file :

Dim f1, fso,ReadLineTextFile,Readfile
forappending=8,forReading= 1
Set fso= createobject ("scripting.filesystemobject")
 If fso.FileExists("D:\QTP\QTP_FSO\file2.txt") Then
  msgbox "File Already Exists"
 else
msgbox "File does not exist"
 Set f1= fso.createtextfile ("D:\QTP\QTP_FSO\file2.txt",false)
f1.writeline "Hello This is new file"
 end if
 Set f1= fso.OpenTextFile("D:\QTP\QTP_FSO\file2.txt", 8)
f1.WriteLine" This line is appended as second"
 Set f1= fso.OpenTextFile("D:\QTP\QTP_FSO\file2.txt",1)
ReadFile = f1.readall
msgbox ReadFile
f1.close

Search a Specific String in a Text File :

Dim fso, f1, MyPos, SearchString, SearchChar
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f1 = fso.OpenTextFile("D:\QTP\QTP_FSO\file2.txt", 1,True)
 Do while f1.AtEndofStream <> True
     SearchString = f1.Readall
      SearchChar = "Hello"
msgbox SearchString
msgbox SearchChar
MyPos = Instr( 1, SearchString, SearchChar, 1)
   If MyPos >=0 Then
  msgbox "TextFound"
   Exit Do 
  else
msgbox "Text Not Found"
         End If
Loop
msgbox MyPos

Wednesday, June 1, 2011

FileSystemObject : Working with Folders

The FSO object model gives your server-side applications the ability to create, alter, move, and delete folders, or to detect if particular folders exist, and if so, where. You can also find out information about folders, such as their names, the date they were created or last modified, and so forth.
The FSO object model also makes it easy to process files. When processing files, the primary goal is to store data in a space- and resource-efficient, easy-to-access format. You need to be able to create files, insert and change the data, and output (read) the data.

FileSystemObject is main object. Contains methods and properties that allow you to create, delete, gain information about, and generally manipulate drives, folders, and files. Many of the methods associated with this object duplicate those in other FSO objects; they are provided for convenience.

Here I am presenting some basic scripts to Create Folder, Copy Folder,Delete Folder, Move Folder , See if Folder Exist or not.
working with this rich set of properties of FSO you need to firset cretae your FSO objec than use FileSystemObject methods provided.

Script to Create Folder :

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")  
Set ofolder= fso.createfolder ("C:\QTP_FSO")                                

Script to Delete Folder :

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")
fso.DeleteFolder (""C:\QTP_FSO")

Script To Copy Folder from One location to other:

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")
fso.CopyFolder "C:\QTP_FSO" , "D:\QTP\Functions\" ,True

Script To Move Folder from one location to other :

Dim fso , oFolder
Set fso = createobject ("scripting.filesystemobject")
fso.MoveFolder "C:\QTP_FSO" , "D:\QTP\Functions\"

Script to Check if folder already exist :

Dim fso , ofolder
Set fso = createobject ("scripting.filesystemobject")
If fso.FolderExists("C:\QTP_FSO") Then
MsgBox "Folder Already Exist"
else
msgbox "Folder does not exist"
Set ofolder= fso.createfolder ("C:\QTP_FSO")
End If

Friday, January 21, 2011

SetTo Property,GetToProperty & GetRoProperty

SetToProperty : SetToProperty change the value of test object during runtime. For example while testing a web application "name" property of web button was "Login" but in next release it changes to "Sign-In" but chnage is only for one build only & you got build very frequently so if you run your test , it will fail as in OR "name" is set as "Login" & in object it is "Sign-In". By using "SetToProperty" you can change its name property to "Login" to  again & pass you test.
This chnaged value is applicable for duration of test run only & does not affect OR,Active screen etc.Basic use of this property is when you dont want to add same type of multiple objects with different property description.

GetToProperty : GetToProperty is used to reterive the property value of test object during run time.

GetRoProperty : GetRoProperty methos is used to reterive runtime properties.

systemutil.Run "C:\Program Files\Internet Explorer\iexplore.exe" , "http://www.google.co.in/"
iname= browser("iGoogle").Page("iGoogle").GetROProperty("title")
'##############Using GetRoProperty method to reterive "name" property of Editbox.###########
iwebeditname= Browser("iGoogle").Page("iGoogle").WebEdit("q").GetROProperty("name")
msgbox iwebeditname
'##############Using SetRoProperty method to set "name" property of Editbox as Neeraj.###########
Browser("iGoogle").Page("iGoogle").WebEdit("q").SetToProperty  "name", "Neeraj"
igetro=Browser("iGoogle").Page("iGoogle").WebEdit("q").gettoproperty ("name")
msgbox igetro '######## Check if "name" Proerty value is changed or not.##########
Browser("iGoogle").Page("iGoogle").WebEdit("q").Set "neeraj"
Browser("iGoogle").Page("iGoogle").WebButton("Google Search").Click
Browser("iGoogle").Page("neeraj - Google Search").Sync

Friday, January 7, 2011

Count number of Links , display their names & URL on webpage

Dim obj,oAllLink_Page,Link_Count_Page,iName,iURL
Set obj=description.Create()
obj1("micclass").value="Link"
Set oAllLink_Page=browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").ChildObjects(obj1)
Link_Count_Page=oAllLink_Page.count
msgbox Link_Count_Page
For i = 0 to Link_Count_Page -1
 iName= oAllLink_Page(i).getroproperty("name")
 iURL= oAllLink_Page(i).getroproperty("url")
 msgbox " Name of Link - " &iName
 msgbox " URL - " &iURL

Count number of Links on a web page

SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe", "http://newtours.demoaut.com/"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "test"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").SetSecure "4cb4513bfbdc1da7fa533425cf4f"
Dim obj,AllLink
Set obj=description.Create
obj("micclass").value="link"
set AllLink=browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").ChildObjects(obj)
msgbox "Total Links : " & AllLink.count
iLinkCount=AllLink.count
msgbox iLinkCount

Script to Count No. of Items in a List Box & Display theie names.

This sample script uses mercury Flight Reservation site & count number of items in list box "From Day" & display their name one by one.

 
  • SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe", "http://newtours.demoaut.com/"
  • Dim list_count
  • Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "test"
  • Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").SetSecure "4cb4513bfbdc1da7fa533425cf4f"
  • Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click
  • list_count=Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromDay").getroproperty("items count")
  • msgbox list_count
  • For i = 1 to list_count
  • Item_Name = Browser("Find a Flight: Mercury").Page("Find a Flight: Mercury").WebList("fromDay").getitem(i)
  • msgbox Item_Name
  • Next

Checkpoints in QTP

Checkpoint is a verification point in you tests which compares existing value of a property of the object with an existing value. With the help of checkpoint you test that if a property of the object is same or changing.

When you add a checkpoint to your test QTP adds a checkpoint to the current row in keyword view and adds a Check Checkpoint statement to expert view. The name of the checkpoint is by default the name of the object on which checkpoint is applicable.

Why we use checkpoint. When you record a test in your application you simply record various objects & store them in repository but have you done any testing yet…No you haven’t….when you check that if the property of an object is not changing during run time you perform actual test. For this simple reason you insert checkpoints in your test. As application changes vey frequently & you want to keep your test unchanged you apply some checkpoints on object/properties which may change. When you run your test you can checks if Checkpoint Pass/Fail for baseline.

Checkpoints can be inserted using Menu>Insert>Checkpoint or you can use Descriptive Programming for inserting checkpoints in you test.

QTP uses following types of Checkpoints

  1. Standard Checkpoint:  Standard Checkpoints used to check properties of an object.You can apply standard checkpoint on an object & test if a property change during run time. This checkpoint is applicable on variety of objects i.e. List Box, Button, Link, Combo Box, Edit Box etc. With help of this checkpoint you can test if a CheckBox is checked, a radio button is enabled or you can check value of an edit box.
  2. Image Checkpoint: This check for the values of an image i.e. source of the image.Image checkpoint is supported in web environment only. You can create an Image Checkpoint by applying Standard Checkpoint on Image.
  3. Bitmap Checkpoint: Test area of an image as a bit map. This checkpoint is used to check if the image is right. You can use this checkpoint anywhere in you application for Button, Text Box etc.This checkpoint is supported in all add-in environment.
  4. Table Checkpoint: This checkpoint checks if data within a table is correct. You can create Table Checkpoint by adding standard checkpoint on table object.
  5. Text Checkpoint: Text Checkpoint checks that a string is placed at an appropriate place on application. For example in your application text displays as “Neeraj Kumar Bhatnagar”.you can use Text Checkpoint to check that if Kumar displayed between Neeraj & Bhatnagar
  6. Text Area Checkpoint: Enables you to check if the text string is appearing within a defined area in your application. Text Area Checkpoint is only applicable to windows environment such as Standard Windiw, ActiveX, and Visual Basic.
  7. Page Checkpoint: Checks for the characteristics of a web page, ie. Time Taken to web page, broken link etc.You can create a Page Checkpoint by inserting a standard checkpoint on page object.
  8. Database Checkpoint: Database Checkpoint checks the contents of a database accessed by your application. For example, you can use a database checkpoint to check the contents of a database containing flight information for your Web site.
  9. Accessibility Checkpoint: Accessibility Checkpoint identifies areas of your Web site that may not conform to the World Wide Web Consortium (W3C) Web Content Accessibility Guidelines. For example, guideline 1.1 of the W3C Web Content Accessibility Guidelines requires you to provide a text equivalent for every non-text element. You can add an Alt property check to check whether objects that require the Alt property under this guideline, do in fact have this tag.
  10. XML Checkpoint : checks the data content of XML documents in XML files or XML documents in Web pages and frames.The XML Checkpoint (Web Page/Frame) option is supported for the Web add-in environment. The XML Checkpoint option is supported for all add-in environments
Ref : QTP Help

Wednesday, January 5, 2011

Object Repositories in QTP


Object repository is a place where all objects are stored.QTP uses 2 types of object repository

  1. Per Action (Local)
  2. Shared
Per Action Repository:  By default qtp makes & uses Per Action repository .When qtp learned any object it create a local repository (for new test) within that test or action & stores description of the object in corresponding Action’s local repository automatically.
Objects stored in Per Action Repository will be available to corresponding actions only other actions can not access these objects. If you modify an object in the local object repository, your changes do not have any effect on any other action or any other test

When working with local object repositories:

  • QTP creates new object repositories for each action.
  • When QTP learns new objects it automatically add description of the objects in local object repository of corresponding action.QTP adds all new objects to local object repository even though one or multiple shared object repositories associated to that action.
  •  If a child object are added to local object repository & its parent is in associated shared object repository, its parent automatically moved to local object repository.
  •  Every time you create a new action its corresponding local object repository created automatically & as you learn object in you application these object are stored in local repository.
  • If QTP stores same object with in two different actions, its stores the object as separate object in both repository.
  • When you save your test local object repository save automatically.

Shared Object Repository: Objects are stored in one or multiple shared repository & other actions can also use them. By storing objects in shared object repositories and associating these repositories with your actions, you enable multiple actions to use the objects. For each action, you can use a combination of objects from your local and shared object repositories, according to your needs. You can also transfer local objects to a shared object repository, if required. This reduces maintenance and enhances the reusability of your tests because it enables you to maintain the objects in a single, shared location instead of multiple locations.

For the ease of use & access it’s always advised to use Shared Object repository as you can use same object repository for multiple actions if the actions include same object.
As all objects are stored at one central location at any point of time if object in application change you can update them in all the associated actions that used shared repository.

If the object with same name exists in both PerAction as well as shared repository for an action that action uses Per Action Repository.

When we open a test that was created in an earlier version of qtp a message displays that if you want to convert your test or view it as Read-Only. If the test previously using Per Action Repository the object of each Per Action Repository is transferred to the local object repository of each action.

If Object of previous test was using shared repository the same object repository is associated with each of the actions in the test & local object repository remains empty.

When working with a Shared Object Repository:

  • If QTP learns an object which is already existed in either shared or local object repository associated with that action it uses existing information & does not add that object to repository.
  •  If a child object are added to local object repository & its parent is in associated shared object repository, its parent automatically moved to local object repository.
  • When QTP learns a new object it adds to this object to corresponding action’s local object repository. You can export object from local object repository to shared object repository or you can export the entire local object repository & replace it with shared object repository & your local object now will be accessible to other actions as well. You can also merge objects from the local object repository to a shared object repository that is associated with the same action.


Ref : QTP Help

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"