Nov 15, 2012

Descriptive Programming-QTP

Object Repository:

♦  Object Repository(OR) stores the objects information in QTP.Object repository acts as a interface between the Test script
    and AUT in order to identify the objects during execution.

♦  QuickTest has two types of object repositories for storing object information:

    1. Shared object repository
    2. Local object Repository

Shared Object Repository:

 A Shared Object Repository(SOR) stores objects information in a file that can be accessed by multiple Test.Extension of file name is .tsr,This is the most familiar and efficient way to save objects.

Local Object Repository:

Local Object Repository stores objects information in a file that is associated with one specific action, so that only that action can access the stored objects.Extension of file name is .mtr.

Example:
'Username="start-testing.blogspot.in"
'Password="qtp" 
 
'***********************************Login to gmail account  using  Object Repository ***********************************
 
'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com"
 
'wait til browser Loads
Browser("Gmail: Email from Google").Page("Gmail: Email from Google").Sync
 
' Enter  Email id in Username Field
Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Set  "qtpworld.com"
 
'Enter password in Passowrd Field
Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Passwd").Set  "qtp"
 
'Cick on the Sign In Button 
Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebButton("Sign in").Click

Descriptive Programming(DP):

♦ Entering Objects Information directly into the test script is called descriptive programming.In DP, we will be "manually"
   specifying the properties and values by which the relevant object will be identified. This way QTP won’t search for the
   properties data in the Object Repository, but will take it from the DP statement.

♦ Object Spy is used to get the properties and their values to uniquely identify the objects in the application. If we know such
   properties and their unique values that can identify the required object without ambiguity, we need not use Object Spy.

 Two ways of descriptive programming:

 1. Static Programming
 2. Dynamic Programming


1.Static Programming: We provide the set of properties and values that describe the object directly in a VBScript statement.

    Example:

'Username="start-testing.blogspot.in"
'Password="qtp" 
 
'*****************************Login to gmail account  using  Static descriptive Programing ****************************** 
 
'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com" 
 
'Assign object property  value to a variable pwd
pwd="Passwd" 
 
'Wait till browser loads
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").Sync 
 
' Enter  Email id in Username Field
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=Email").Set  "qtpworld.com" 
 
'Enter password in Passowrd Field
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=" & pwd).Set  "qtp" 
 
'Cick on the Sign In Button
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebButton("name:=Sign in").Click

2. Dynamic Programming:
We add a collection of properties and values to a Description object, and then enter the
    Description object name in the statement.
 
     Example:


'Username="start-testing.blogspot.in"
'Password="qtp" 
 
'*****************************Login to gmail account  using  Dynamic descriptive Programing *************************************
 
'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com" 
 
'Descriptive object to identify  Browser  with a particular title
Set  Dbrowser=description.Create
Dbrowser("micclass").value="Browser"
Dbrowser("title").value="Gmail: Email from Google" 
 
'Descriptive object to identify  Web page with a particular title
Set  Dpage=description.Create
Dpage("micclass").value="Page"
Dpage("title").value="Gmail: Email from Google" 
 
'Descriptive object to identify a  particular Web Button
Set  Dbutton=description.Create
Dbutton("micclass").value="WebButton"
Dbutton("name").value="Sign in" 
 
'Descriptive object to identify  Web Text Box
Set Dedit=description.Create
Dedit("micclass").value="WebEdit"
Dedit("name").value="Email" 
 
'wait till browser loads
Browser(Dbrowser).Page(Dpage).Sync 
 
' Enter  Email id in Username Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set  "qtpworld.com" 
 
Dedit("name").value="Passwd" 
 
'Enter password in Passowrd Field
Browser(Dbrowser).Page(Dpage).WebEdit(Dedit).Set  "qtp" 
 
'Cick on the Sign In Button
Browser(Dbrowser).Page(Dpage).WebButton(Dbutton).Click

Which approach is best in QTP, Object Repository vs. Descriptive Programming  ?


♦ There really is no “best way”.

♦ Use the method that gives your company the best ROI(Return On Investment), whether that be Object Repository (OR),
   Descriptive Programming (DP) or a mixture of both.

When to use Descriptive Programming?

Following are some of the Scenarios where Descriptive programming is used:

Scenario #1:  Suppose we need to start Automation before Build Release.
                     OR:- There is no application to create Object Repository.

Scenario #2:   If the Application under test is having Dynamic Objects.
                     OR:- Difficult to handle Dynamic Objects using Object Repository.

Scenario #3:  When the application under Test is having objects that are adding in the Run Time.
                     OR:- We can’t add objects to Object Repository in run time.

Scenario #4:   If Application under test is having similar type of objects or similar name objects.
                     OR:- Object Repository will create multiple objects with same description unnecessarily.

Scenario #5:   When Application under test have more objects to perform operations.
                     OR:- The performance will decrease if object repository is having huge number of objects.

Advantages of Descriptive Programming:

1. Version Free: Script can be executed in any version of QTP without any changes.

2. Code Portability: Just code is enough to run script. We can copy and paste in other scripts for any other new requirement.

3. Reusability of Properties: We can assign properties to a global variable and reuse it for same type of objects.

4. Plug & Play: Any time scripts will be in ready to run state. No need to worry about any other settings or files.

5. Just Maintenance of variables: Store the object properties in the form of variables in a txt / vbs file, need to maintain the file.

Child Objects in QTP:

Child Objects in Excel:

The object model used by QTP reflects the way applications are implemented.

Example: Object model hierarch for MS Excel is Workbook>>Worsheets>>Cells

Child Objects in Webpage:

GUI controls (objects) are located in container objects, such as a WebEdit in a Web Page, which is in turn contained
within a Browser object.Hence, such a WebEdit is a child object of the Page object, which is in turn a child object of the
Browser object.


Example: Object model hierarchy for Gmail login Web page is Browser>>Page>>Webedit

Child Objects in Window:

Any of the object controls like a button, checkbox, radiobutton, combobox, frame etc of the application that can be referred
only from its parent object are called child objects.
Example:

A button may have been placed directly on a window. So, the window will be a parent object and the button will be a
child object. OR
Example:

A group of radiobuttons may have been placed under a frame and that frame is placed on a window. So, the window will
be a parent object of the frame and the frame will be the parent object of the radiobuttons. Radiobuttons will be the child objects.

Example:
Username="start-testing.blogspot.in"
'Password="qtp" 
 
'*****************************Login to gmail account  using  Child Objects *************************************
 
'Launch gmail
systemutil.Run "iexplore.exe","http:\\www.gmail.com" 
 
'Descriptive object to identify  Browser  with a particular title
Set  Dbrowser=description.Create
Dbrowser("micclass").value="Browser"
Dbrowser("title").value="Gmail: Email from Google" 
 
'Descriptive object to identify  Web page with a particular title
Set  Dpage=description.Create
Dpage("micclass").value="Page"
Dpage("title").value="Gmail: Email from Google" 
 
'Descriptive object to identify a  particular Web Button
Set  Dbutton=description.Create
Dbutton("micclass").value="WebButton"
Dbutton("name").value="Sign in" 
 
'Descriptive object to identify  Web Text Box
Set Dedit=description.Create
Dedit("micclass").value="WebEdit" 
 
'wait till browser loads
 Browser(Dbrowser).Page(Dpage).Sync 
 
'to find number of  webedit in gmail page
Set  Wtextbox = Browser(Dbrowser).Page(Dpage).ChildObjects(Dedit) 
 
NoOfTextbox = Wtextbox.Count
 
  For Counter=0 to NoOfTextbox-1 
 
     If Wtextbox(Counter).getroproperty("name")="Email" then
 
      ' Enter  Email id in Username Field
      Wtextbox(Counter).set   "qtpworld.com" 
 
    Elseif  Wtextbox(Counter).getroproperty("name")="Passwd" then
 
      'Enter password in Passowrd Field
      Wtextbox(Counter).set  "qtp"
 
      End If 
 
  Next 
 
'Cick on the Sign In Button 
Browser(Dbrowser).Page(Dpage).WebButton(Dbutton).Click
 
Resoure:QTPWORLD 

No comments:

Post a Comment