Showing posts with label DP. Show all posts
Showing posts with label DP. Show all posts

Saturday, 18 August 2012

Object Repository & Descriptive Programming

What is an Object Repository?
As the name Suggest Object Repository (OR in Short) is place where QTP Test Objects properties and its values are stored.

Conceptually if we want to perform a task on any Objects like WebButton, WebEdit, WinEdit etc. what we look for? Naturally the Object's available methods/functions/sub on which we need to perform the task!

Now, how do you know or how do you identify whether you are clicking the right button or entering string in right TextBox (WinEdit/WebEdit)? So, what do you look for the right Button or TextBox?

Your answer maybe like
-The look and feel of Object should be like button
-It should contain text on button
-And if their are two button with same name then in which context the button is present, I shall click that one. Example button name is "Submit" context may be
  1. Click Submit to update record 
  2. Click Submit to Add the record

So ultimately what were you doing? Identifying Objects by their properties, right? This is how QTP does the same to identify Objects.

For in depth understanding with illustrations on how QTP Identify Objects, click here.

Also have a look at Object Repository GUI in QTP and Descriptive Programming in QTP

Now, lets look at below screenshot of OR & DP Code, try to catch the difference

Look at the highlighted part. You will understand the commonality or what is the basic thing QTP works with, i.e. Properties.

I was just wondering how could OR based Code is associated with Object Repository, I just opened the Script.mts file in notepad and then. . .






See the highlighted part, now you can imagine how QTP IDE has been designed and how could QTP OR and DP based code works. ;-)
Hope you are able to understand OR and DP!

I don't know what these highlighted part are, otherwise I could have been in Mercury inc. ;-)



-Pankaj Dhapola
Think on it!!!

Sunday, 22 January 2012

Descriptive Programming in QTP

What do you mean by Descriptive Programming (DP in Short)?

In QTP, An Automation script developer can write script codes using Object Repository or Descriptive Programming. Descriptive Programming is nothing but working with Object's property name and property value. As we all know QTP identify objects on the basis of object properties which is ultimately known as Descriptions.

Now in QTP, How do we write scripts in DP to perform an action like entering string in text field, clicking button etc. . .?

Ummm . . .

To Identify object uniquely we need to find descriptions or properties of an Object. How do we find properties? It's Object Spy. Descriptive code can be written in two ways

  • Mention your Descriptions using QTP inbuilt programmed Description Object. (Note here Description object is different than the GUI objects like WebButton, WinButton etc, Description Object is programming concept.)
  • Another way is to mention your description in string format.

Let's take an example . . .

I have adjacent html WebPage that I developed during my college days when I first learned HTML ;)

I have to write a script to enter firstname, lastname and then click on Submit button.

Now, to write script using Description Object you would require to create a description object and use its add method to add "propertyname -propertyvalue" pair, for that write below code

Set objDesc = Description.Create
objDesc.add "propertyname1", "propertyvalue1"
objDesc.add "propertyname2", "propertyvalue2"


Use this code to write script for object
QTPObject(objDesc )



Wait this is not the end, I want to uniquely identify the TextBox besides "First Name" Label. so for this I need the properties of the "First Name" TextBox and for that naturally I will use QTP object spy.

Let's see what Object spy has to say. . .
Look at the 3 property and value pair for First Name WebEdit (or Text Box)
class = fntxtclass
html tag = INPUT
name = fntxt 

According to hierarchy of "First Name TextBox" Object, with little knowledge of DOM I realized that to reach this textbox I need to identify Browser(MyFirsthtmlcode) first and then Page(MyFirsthtmlcode) and then WebEdit(fntxt)

okay let me go with First Name Textbox or WebEdit(fntxt)


Can you relate things in browser, HTML source page and object spy? Try to understand how are WebObjects being interpreted in QTP environment.

Now I decide to use these 3 properties for identifying the "First Name" TextBox (or WebEdit) in our description object.
Let's see how do i do that . . .

Set objFirstNameTextBoxDescription = Description.Create
objFirstNameTextBoxDescription.add "class","fntxtclass"
objFirstNameTextBoxDescription.add "html tag","INPUT"
objFirstNameTextBoxDescription.add "name","fntxt"

now this object is mentioned in WebEdit object as

WebEdit(objFirstNameTextBoxDescription)


Lets use the same process to identify Browser and page, I figured out below code for both Browser and Page Object


Set objMyBrowserDescription = Description.Create
objMyBrowserDescription.add "name","MyFirsthtmlcode"

As

Browser(objMyBrowserDescription


Set objMyPageDescription = Description.Create
objMyPageDescription .add "class","fntxtclass"

As 

Page(objMyPageDescription)



Now lets see whether we have uniquely identify or not, for that I used highlight method for each objects.
Notice hierarchy in the code as well.

Browser(objMyBrowserDescription).highlight
Browser(objMyBrowserDescription).Page(objMyPageDescription).highlight
Browser(objMyBrowserDescription).
Page(objMyPageDescription).
 WebEdit(objFirstNameTextBoxDescription).highlight

guess what!!! "First Name" TextBox was highlighted

And then I used the most common method of WebEdit object i.e. set() method to enter value in our text box.

Browser(objMyBrowserDescription).Page(objMyPageDescription).
 WebEdit(objFirstNameTextBoxDescription).Set "Pankaj Dhapola"

Now Another way without using Description Object is to enter Description properties in String format like this
QTPObject("PropertyName1:=PropertyValue1","PropertyName2:=PropertyValue2", . . . .)

Above equivalent code in String format is



Browser("name:=MyFirsthtmlcode").Page("name:=MyFirsthtmlcode").
WebEdit("class:=fntxtclass","html tag:=INPUT","name:=fntxt").Set "Pankaj Dhapola"



Try it yourself friends.
But notice the case sensitivity inside the String and Description object where you provide the Descriptions or "PropertyName:=Value" pair.
-Pankaj Dhapola