Hello guys!
In Part-1 of this post, we discussed about Static DP. Let's look into Dynamic DP in this part.
In Part-1 of this post, we discussed about Static DP. Let's look into Dynamic DP in this part.
Dynamic:
Second way to write DP is by using the Description object. This way also known as Programmatic Description. 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 statement.
- Description Object are used with ChildObjects (very useful method) 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 (we'll discuss later)
Look into following line. It is DP statement, written by Static approach (as we discussed Part-1 of this post)
Browser(“name:=myBro”).page(“title:=myPage”).webbutton(“name:=Enter”,”type:= Submit”).click
Now let's write the same using Dynamic approach. We see that there are 3 objects in above statement i.e. Browser, Page, webbutton.
Now, first we need to create empty description objects. We'll create 3 object (1 for each object)
Dim oBrowser, oPage, oButton ' declaration is not mandatory but good practice!
Set oBrowser = Description.Create
Set oPage = Description.Create
Set oButton = Description.Create
Now we'll add identification properties & values to these objects.
oBrowser("name").value = "myBro"
oPage("title").value = "myPage"
oButton("name").value = "Enter"
oButton("type").value = "Submit"
oButton("x").value = "301"
And that's it! Our objects are now ready to use now. So, here we go...
Browser(oBrowser).page(oPage).webbutton(oButton).click
As we can see, we will write only the instance name (oButton) instead of all properties and values in statement. If you need to use same object multiple times in your code, your code will not become very lengthy!
Tedious?? I know! :)
Explore the following code to make the things clear...
- Browser("myBro”).page(“myPage”).webbutton(“Enter”).click - OR approach
- Browser(“name:=myBro”).page(“title:=myPage”).webbutton(“name:=Enter”,”type:= Submit”).click - Static DP.
- 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.
Please note that any statement can be written by combining all three ways!! Really?? Yesss!
Lets see how...
Browser("myBro").page(“title:=myPage”).webbutton(oButton).click
In above statement, we have used all 3 ways..
Browser - Object Repository
Page - Static DP
webbutton - Dynamic DP
Ohhh I see!!
Only point to take care here is that OR can't be used after DP.
Okey guys.. In next part of post, we'll discuss pros & cons of each way and other good stuff about DP.
In case of any queries, please post your comments.