Search This Blog

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