Skip to main content

Descriptive Programming in QTP

Descriptive Programming


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="qtpworld.com"
'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="qtpworld.com"
'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="qtpworld.com"
'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="qtpworld.com"
'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

Comments

Popular posts from this blog

SSO with SAML login scenario in JMeter

SAML(Security Assertion Markup Language) is increasingly being used to perform single sign-on(SSO) operations. As WikiPedia puts it, SAML is an XML-based open standard data format for exchanging authentication and authorization data between parties, in particular, between an identity provider and a service provider. With the rise in use of SAML in web applications, we may need to handle this in JMeter. This step-by-step tutorial shows SAML JMeter scenario to perform login operation. First request from JMeter is a GET request to fetch Login page. We need to fetch two values ‘SAMLRequest’ and ‘RelayState’ from the Login page response data. We can do this by using  Regular Expression Extractor . These two values need to be sent in POST request to service provider. Refer below image to see how to do this. We will get an HTML login page as a response to the request sent in 1st step. We need to fetch values of some hidden elements to pass it in the next request. We can do this b

Reading data from text file in SoapUI using groovy script

How to read data from text file in SoapUI. SoapUI Pro has some advance feature which is not in SaopUI as data fetching from external sources so in SoapUI we use Groovy script for that. Following are the peace of groovy script code for reading data from text file. 1. Reading all data from text file. //reading all txt file at once File file = new File("E://TestData.txt") fileContent = file.getText()                  log.info fileContent 2. Reading data line by line from text file. //reading text line by line File file1 = new File(" E://TestData.txt ") List textLine = file1.readLines() log.info textLine 3. Reading data randomly of any line from text file. //reading text randon line number File file2 = new File(" E://TestData.txt ") List textLine2 = file2.readLines() rowIndex  =  Math.abs(new Random().nextInt() % 4 + 1) log.info textLine2[rowIndex]

VBScript Code - Function to convert CSV file into excel and viceversa in QTP using VBScript

We at times are required to convert excel files into csv to read as flat files and sometime require to convert a csv file into excel file to use excel features on the data.   Below function shows how to convert an csv file into excel file and vice versa. We can also convert to other formats based on constants Here constant value 23 is used to create a csv file and constant -4143 to save a file as xls file. Once the destination file is created, we can delete the source file as shown below.  In case of any issue in understanding the code, please add in comment section Call func_ConversionCSVExcel("E:\Test.csv", "E:\Test_converted.xls", "csvtoexcel") Public Function func_ConversionCSVExcel(strSrcFile, strDestFile, Conversion) on error resume next Set objExcel = CreateObject("Excel.application") set objExcelBook = objExcel.Workbooks.Open(strSrcFile) objExcel.application.visible=false objExcel.application.displayalerts=