This is my personal blog for my software testing study purposes. The topics posted in this blog are mine and from some other sources (credits are given). I always add those topics which helps me. Hope these topics will help you guys also.
- Happy testing

Recent Posts

QTP & Keyword Driven Testing

Tricky Questions in QTP

Asset Upgrade tool in QTP

New Features in QTP 10

Nov 20, 2008

QTP Descriptive Programming - How to get number of objects.

Subscribe the QA and Software Testing Newsletter
Post Your Queries | QA and Testing - Table of Contents

SPONSORED LINKS Reading: QTP Descriptive Programming - How to get number of objects.Tweet this Post

(Source -Easy way to automate testing by Dmitri Motevich)

In this article, Dmitri Motevich explains QTP Descriptive Programming (DP) through Google Sets site:

(click image to enlarge it)

The goal of the present
QTP tutorial is to describe:
How to get number of controls (Links, Edits, Images, etc) with QTP DP.


Let's investigate Descriptive Programming on examples.
First of all, we should understand what Descriptive Programming means:
What is QuickTest Professional Descriptive Programming (QTP DP)?

Answer: QTP DP is a run-time processing of objects which are not located in QTP Object Repository.


I've created new QTP script which starts with http://labs.google.com/sets page.
This QTP script is simple enough:
Set Desc = Description.Create()
Desc("micclass").Value = "WebEdit"
Set Edits = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)

MsgBox "Number of Edits: " & Edits.Count

And its result is:
As you can see, it works correctly and returns correct number of Edits on a page.
I'm going to explain this QTP script and answer the following question:


How does QTP Descriptive Programming work?

First of all, I've created new Description object:
Set Desc = Description.Create()
Description object contains collection of properties, which identify any UI object such as a browser, a page, a dialog, a list, a button etc.

To specify that we want identify all Edits on browser's page I use "micclass" property:
Desc("micclass").Value = "WebEdit"
Note: the "mic" prefix in "micclass" stands for "Mercury Interactive Constant".


How do you know the class name ("micclass") of object?

Use Spy for that:
QTP Object Spy
Open QTP object Spy and check recorded properties of object.
For example, these are properties of Edit:
QTP Object Spy - recorded properties
As you can see, there is "Class Name" property and its value - "WebEdit". So, "WebEdit" is a value of Class Name of all Edits located on Web page.
Note: "Class Name" is a synonym of "micclass".

I gathered Class Names of Web objects in this table:
#
Type of Web object
Class Name(micclass)
1
Web Browser
Browser
2
Page
Page
3
Edit box
WebEdit
4
Image
Image
5
Link
Link
6
Web Element
WebElement
7
Button
WebButton
8
Checkbox
WebCheckBox
9
Combobox (DropDownList)
WebList
10
Table
WebTable


Since we created Description object for all edit boxes, we can use this description to get all specified objects ( = edit boxes).
The next step returns the collection of all child objects (i.e. edit boxes) contained within the page:
Set Links = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)

To get the number of found objects in a returned collection, we use Count property:
MsgBox "Number of Edits: " & Links.Count

And the result is 5 found Edits on Google Sets page:
Number of Edits
So, this is a mechanism of
QuickTest Professional Descriptive Programming.

Also, we can use the same code to get number of others objects - Links, Images, Buttons, etc.
For that I modified QTP script:
Function GetAllSpecificControls(Page, MicClass)
Set Desc = Description.Create()
Desc("micclass").Value =
MicClass
Set GetAllSpecificControls = Page.ChildObjects(Desc)
End Function

Function GetAllEdits(Page)
Set GetAllEdits = GetAllSpecificControls(Page, "WebEdit")
End Function

Function GetAllButtons(Page)
Set GetAllButtons = GetAllSpecificControls(Page, "WebButton")
End Function

Function GetAllLinks(Page)
Set GetAllLinks = GetAllSpecificControls(Page, "Link")
End Function

Function GetAllImages(Page)
Set GetAllImages = GetAllSpecificControls(Page, "Image")
End Function


Set oPage = Browser(
"Google Sets").Page("Google Sets")

MsgBox "Number of Edits: " & GetAllEdits(oPage).Count
MsgBox "Number of Buttons: " & GetAllButtons(oPage).Count
MsgBox "Number of Links: " & GetAllLinks(oPage).Count
MsgBox "Number of Images: " & GetAllImages(oPage).Count

The result of this QTP script is the following:
Results of QTP script
You can compare the result with the initial web page (see first image in the present article) and verify that QTP Descriptive programming works correctly - it returns correct numbers of objects.


Summary:
  • Dmitri has explained and shown the mechanism of QuickTest Professional Descriptive Programming (QTP DP).
  • The present QTP tutorial explains how to get number of different objects - Edits, Links, Images, Buttons, etc.

I hope, that this article has helped you to understand
QTP DP.
The future QTP tutorials will cover o
thers questions on QTP Descriptive Programming.

SPONSORED LINKS

Comments :

2 comments to “QTP Descriptive Programming - How to get number of objects.”

Thanks for detailed explanation
-Sachin Kaulgekar

sachin kaulgekar said...
on 

Hi
Could you please help me out.
My input data is 300 characters.I am using MsAccess.As the field type text has a limitation of 255 charactes i used the field type"Memo".Now when i tried to retrieve the value in QTP,it says "Null".
Is there any way to convert data of type "MEMO" to type text??Pls help

revaraghavan said...
on 

Software testing Metrices-Test Case Review

Metrics are the means by which the software quality can be measured; they give you confidence in the product.

 

Energize your test team

You're waist deep in your third month of late nights, weekends, and shipping stress; you can see and feel your team's energy waning.

 

The Value of Positive Testing

There is a school of thought in software testing that debunks the value of positive testing. This school basically states that any test that does not produce a defect is not a good test.

Impact Analysis Checklist for Req. Changes
___    Implications of the Proposed Change* Identify any existing requirements in the baseline that

The Process of Test Process Improvement

Software testing is still a pain-in-the-neck for many organizations. Because it is only marginally addressed in software process improvement models like CMMi

 

Software Defect-bug Management Philosphy

Imperfect processes cause most of the software defects. Thus to prevent defects, the development process needs to be overhauled.

 

Software testing Metrices-Test Case Review

Metrics are the means by which the software quality can be measured; they give you confidence in the product.

 

Energize your test team

You're waist deep in your third month of late nights, weekends, and shipping stress; you can see and feel your team's energy waning.

 

The Value of Positive Testing

There is a school of thought in software testing that debunks the value of positive testing. This school basically states that any test that does not produce a defect is not a good test.

Blog Archive