Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Descriptive programming examples and comparison with Object Repository

Comparing Descriptive Programming with Object Repository


Suppose we record on Google page for testing and then click back for Search button, steps will be recorded in QTP as shown below. An object reposiory stores all the objects used in the recording. Issue with Object repository is that we need to associate object repository with test for execution and if the project size increase, it becomes difficult to maintain the repository.

Browser("Google").Page("Google").WebEdit("q").Set "TESTING"
Browser("Google").Page("Google").WebButton("btnG").Click
Browser("Google").Page("testing - Google Search").Link("Search").Click

Suppose we do not want to use objects from object repository, we can use descriptive programming to describe the objects.


Descriptive programming can be implemented in following two ways:

1. Using Static description:

Suppose we have to define description for 
Browser("Google").Page("Google").WebEdit("q").Set "TESTING"

We need to do the following:


1. Use object spy to identify the object in the page, mostly for html pages, html id is unique for the object, so will use html Id as property for the object.




Browser("title:=Google").Page("title:=Google").WebEdit("html id:=gbqfq").Set "TESTING":

Also in case of multiple object with similar properties, for example, multiple instances of browser, we can use ordinal identifier to identify the object

the above code using ordinal identifier and using regular expressions can be written as:

Browser("title:=.*","index:=0").Page("title:=Goog.*").WebEdit("html id:=gbqfq","index:=0").Set "TESTING":


2. Using Description Object


In descriptive programming, we can create description object and define the description of the object. For above code, we can create description object for each of the following:

Set objdescBR = description.Create
objdescBR("title").value ="Google"
Set objdescPg = description.Create
objdescPg("title").value ="Google"
Set objdescEdit = description.Create
objdescEdit("html id").value ="gbqfq"
objdescEdit("index").value =0

Browser(objdescBR).Page(objdescPg).WebEdit(objdescEdit).Set "TESTING1"

Description object can be very useful if we want to perform similar actions of multiples, for e.g checking multiple checkbox, providing same text in multiple edit box and so on. 

We will describe some examples on Descriptive Programming


1. Getting total number of links in the page:


Set objdescBR = description.Create
objdescBR("title").value ="Google"
Set objdescPg = description.Create
objdescPg("title").value ="Google"
Set objdesc = description.Create
objdesc("micclass").value ="Link"
Set objLinks = Browser(objdescBR).Page(objdescPg).childobjects(objDesc)
Msgbox objLinks.count

Similar to this example, we can fine multiple objects type in the page based on class of the object, Please give it a try for Images, and checkbox in the page


2. We can also like clicking on a link with a particular name or entering value in a particular edit box with code similar to as  below:


Call clickLink("Orkut")

Public Function clickLink(LinkName)
Set objdescBR = description.Create
objdescBR("title").value ="Google"
Set objdescPg = description.Create
objdescPg("title").value ="Google"
Set objdesc = description.Create
objdesc("micclass").value ="Link"
Set objLinks = Browser(objdescBR).Page(objdescPg).childobjects(objDesc)
For i = 0 to objLinks.count - 1
If (objLinks(i).getroproperty("name") = LinkName) then
objLinks(i).click
End If
Next
End Function


2 comments:

  1. Really great information please keep it up..

    ReplyDelete
  2. The Aim of the #automation training is to prepare students with practical skills as per Industry norms and make them capable with the objective of getting a core industry job. Call for job 9310096831

    ReplyDelete