2011 11 11 Descriptive Programming in Qtp

2011 11 11 Descriptive Programming in Qtp

Title: Mastering Descriptive Programming in QTP (QuickTest Professional) author: Shafiq Alibhai date: 2011-11-11T05:00:05+00:00 categories:

  • Development

Download the Complete Guide

Overview #

Today, let’s delve into Descriptive Programming in QTP version 8.20. This guide will walk you through the ins and outs of Descriptive Programming, including the situations where it becomes the go-to method. With Descriptive Programming, you can start building automation scripts even if the application under test is still in the development stage.

What is Descriptive Programming? #

In a nutshell, QuickTest Professional (QTP) records your actions on an application’s objects and stores those objects in a library known as the Object Repository. The challenge arises when you need to interact with objects that are not in this repository. Descriptive Programming swoops in here as your knight in shining armor.

Object Identification Essentials #

QTP recognizes objects through specific properties like name or HTML tag. For example, if there’s a radio button on a web page, QTP will store its name and HTML tag for future interactions.

Object Repository

Here, the name in the left tree view is the logical name given by QTP for the object. Keep in mind that the logical name must be unique at each level of the object hierarchy. In our example, you can see two distinct objects under the Browser->Page node: WebTable and testPath.

Below are some example operations that can be performed:

Browser("Browser").Page("Page").WebRadioGroup("testPath").Select "2"
cellData = Browser("Browser").Page("Page").WebTable("WebTable").GetCellData(1, 1)
Browser("Example2").Page("Page").WebEdit("testPath").Set "Test text"

Scenarios for Using Descriptive Programming #

Here are some common scenarios where Descriptive Programming comes in handy:

  1. Dynamic Objects: If you’re dealing with objects that change depending on user behavior or other variables, Descriptive Programming is your ally.
  2. Large Object Repositories: A bulky Object Repository can slow down QTP’s performance. Using Descriptive Programming can help alleviate this.
  3. Bypassing the Object Repository: In some cases, you might want to avoid using the Object Repository altogether.
    • For instance, you may have an application that’s not yet deployed. With Descriptive Programming, you can still prepare your QTP scripts if you know the object descriptions.
    • If your application contains repetitive objects across multiple pages, Descriptive Programming can reduce the number of objects stored in the repository.
  4. Read-only or Shared Repositories: When the Object Repository is not editable or shared among multiple test cases, Descriptive Programming is a practical solution.
  5. Batch Actions on Similar Objects: If you have objects with similar properties, Descriptive Programming can streamline your operations.

How to Use Descriptive Programming #

Descriptive Programming can be implemented in two ways:

  1. By Creating Property Collection Objects: Here, you first create an empty description and then add properties to it.
  2. By Using String Arguments: You directly specify the object properties and values within your code.

Using Property Collection Objects #

First, create an empty description like this:

Dim obj_Desc
Set obj_Desc = Description.Create

You can then add properties to this description as needed:

obj_Desc("html tag").value = "INPUT"
obj_Desc("name").value = "txt.*"
obj_Desc("name").regularexpression = "txt.*"

You can now employ this description in your script:

Browser("Browser").Page("Page").WebEdit(obj_Desc).Set "Test text"

Using String Arguments #

In this method, you specify properties directly in your script as follows:

Browser("Browser").Page("Page").WebEdit("Name:=txt_Name","html tag:=INPUT").Set "Test"

Key Takeaways and Best Practices #

  1. Hierarchy in Descriptions: Once you start using programmatic descriptions in a statement, you should consistently use them for all objects within that statement.
  2. Getting Child Objects: You can use Descriptive Programming to identify and manipulate multiple child objects within a page.
  3. Object Property Manipulation: With Descriptive Programming, you can easily add, remove, or modify object properties on the fly.

That’s a wrap for this guide on mastering Descriptive Programming in QTP. It’s a powerful technique that can greatly streamline your automated testing efforts, offering flexibility and control that is not easily achieved otherwise.

Reference:

  1. Mercury QuickTest Professional, User’s Guide.