Friday 9 August 2013

QTP - Description Object

Description Object also do the same thing as static way do but there are some differences.
– Description Object stores the properties and values of a particular object in an instance of
that object. So it become easy to use it in the code.
– Description Object are used with ChildObjects property of QTP.
– It’s more useful if you are using multiple properties to identify object. As you will use only
instance name in your statement, your code looks more organized.
– It’s very handy if you are using index property for object identification
Example of a Description Object approach,
Browser(“name:=my”).page(“title:=myPage”).webbutton(“name:=Ok”,”type:=Submit”).click
We have used 3 different objects in above statement i.e. Browser, Page, webbutton.
Dim oBrowser, oPage, oButton ‘ declaration is not mandatory in vbscript, its a good programming approach
Set oBrowser = Description.Create
Set oPage = Description.Create
Set oButton = Description.Create
Now add identification properties & values to these objects.
oBrowser(”name”).value = “my”
oPage(”title”).value = “myPage”
oButton(”name”).value = “Ok”
oButton(”type”).value = “Submit”
oButton(”x”).value = “200″
Our objects are now ready to use now.
Browser(oBrowser).page(oPage).webbutton(oButton).click
You need to mention only instance name (oButton) instead of all properties and values in statement. This approach helps in writing neat & clean code.
Explore the following code to make the things clear…
1. Browser(”my”).page(“myPage”).webbutton(“Ok”).click – OR
approach
2. Browser(“name:=my”).page(“title:=myPage”).webbutton(“name:=Ok”,”type:=
Submit”).click – Static DP.
3. Browser(oBrowser).page(oPage).webbutton(oButton).click – Dynamic DP
First statement is written using OR approach. For this, objects must be stored in Object Repository.
Second statement is written using Static DP. All the properties are given directly in the code. Convenient!!
Third statement is written using Dynamic DP. You need to create a description for every object.
We can write statement that is mixture of above said all three ways. Example is as follows –
Browser(”my”).page(“title:=myPage”).webbutton(oButton).click
In Above written code, we have used all 3 ways..
Browser – Object Repository
Page – Static DP
webbutton – Dynamic DP

No comments:

Post a Comment