4 Dec 2012

Descriptive Programming

Descriptive Programming


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


 Static Programming
 Dynamic Programming

Static Programming

We provide the set of properties and values that describe the object directly in a VBScript statement

Example

'Login to gmail account  using  Static descriptive Programing

'Launch gmail application
Systemutil.Run "iexplore.exe","http:\\www.gmail.com" 

'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  "Username" 

'Enter password in Passowrd Field
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebEdit("name:=" & pwd).Set  "Password" 

'Cick on the Sign In Button
Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google").WebButton("name:=Sign in").Click

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

'Login to gmail account  using  Dynamic descriptive Programing 

'Launch gmail application
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

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

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

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

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

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.

'Login to gmail account using  Child Objects 

'Launch gmail application

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" 

When and Where to use Descriptive Programming with example?

Below are some of the situations when Descriptive Programming can be considered useful

1. One place where DP can be of significant importance is when you are creating functions in an external file. You can use these function in various actions directly , eliminating the need of adding object(s) in object repository for each action[If you are using per action object repository]

2. The objects in the application are dynamic in nature and need special handling to identify the object. The best example would be of clicking a link which changes according to the user of the application, Ex. “Logout <>”.

3. When object repository is getting huge due to the no. of objects being added. If the size of Object repository increases too much then it decreases the performance of QTP while recognizing a object.

4. When you don’t want to use object repository at all. Well the first question would be why not Object repository? Consider the following scenario which would help understand why not Object repository
Scenario 1: Suppose we have a web application that has not been developed yet.Now QTP for recording the script and adding the objects to repository needs the application to be up, that would mean waiting for the application to be deployed before we can start of with making QTP scripts. But if we know the descriptions of the objects that will be created then we can still start off with the script writing for testing
Scenario 2: Suppose an application has 3 navigation buttons on each and every page. Let the buttons be “Cancel”, “Back” and “Next”. Now recording action on these buttons would add 3 objects per page in the repository. For a 10 page flow this would mean 30 objects which could have been represented just by using 3 objects. So instead of adding these 30 objects to the repository we can just write 3 descriptions for the object and use it on any page.

5. Modification to a test case is needed but the Object repository for the same is Read only or in shared mode i.e. changes may affect other scripts as well.
6. When you want to take action on similar type of object i.e. suppose we have 20 textboxes on the page and there names are in the form txt_1, txt_2, txt_3 and so on. Now adding all 20 the Object repository would not be a good programming approach.

No comments:

Post a Comment