You are on page 1of 8

Best-Practices & Learning’s ON

Descriptive Programming Approach AND Development of Re- usable components In QTP By Raghava Bhojegowda

Date of Creation: 24-10-2008

Senior Test Engineers and Test Leads.WebEdit("username").Introduction: This document Explains in understanding the Best Practices to be adhered while automating the script using QTP 9. Scripting with Object Repository: In the statement below.2 that helps for building a robust. innerhtml and innertext etc.Page("Login Page"). username is the name of an edit box. Scope This document is for Test Engineers. The following statement will instruct the QTP to perform Action on Login Page and sets the name as “George” Browser("SAMPLE").set “George” . for example Index. accurate and maintainable test scripts. Best-Practices/Learning • • • • When to use descriptive programming How to use object Identification tool Using object spy for descriptive programming How to Develop Re-usable components Parameters need to be considered to develop Re-usable components. The document helps to Avoid Repeatable codes and scripts failure due to Frequent changes in object repository properties. • When to use descriptive programming: Descriptive programming should be used for applications in which object properties will be changing very frequently. The edit box is located on a page with the name Login Page and the page was recorded in a browser with the name SAMPLE.

WebEdit(WebObjDesc). dIndex= Get the value from the data sheet(XL) set WebObjDesc = Description.Value = dIndex Browser("SAMPLE"). WebEdit(WebObjDesc). The index test object property identifies an object based on the order in which it appears within the code. so that if there are any index value changes comes tomorrow we just need to edit the Data sheet. "Index:=3").Scripting without Object Repository (bypassing of object Repository): You can describe an object directly in a statement by specifying property:=value pairs describing the object instead of specifying an object's name. Index property values are object-specific.Page("Login Page").Value = "UserName" WebObjDesc("Index").WebEdit("Name:= username". Browser("Title:= SAMPLE").Value = "3" Browser("SAMPLE").Create() WebObjDesc("Name"). where the first occurrence is taken as 0. Each property:=value pair should be separated by commas and quotation marks.Page("Login Page").Page("Title:= Login Page").Create() WebObjDesc("Name").Set "George" Or set WebObjDesc = Description.Value = "UserName" WebObjDesc("Index").Set "George" Using the Index Property in descriptive programming:The index property can be a useful for uniquely identifying an object.Set "George" . Parameterize of Index values: Normally index values should be parameterized from Data sheet.

The ordinal Identifier Drop down tells us to know which properties can used to uniquely identify a Test object. If you want to add/ Remove properties to the test objects click on Add/Remove button under the mandatory properties and select the properties.Object Identification tool: Tools -> Object Identification For web applications select web from Environment drop down. .

innerhtml and innertext.Using object spy for descriptive programming:Object spy is used to fetch the property values from a test object. Above values can be used in descriptive statements. . Tools -> object spy -> click on Hand pointer icon and place the pointer on the application test object. name. Using object spy we can note down the values of test objects properties like index.

1.list out all the controls in the application For web application typically will have the. Web Edit .Re-usable components:- Test script 1 Re-usable functions (qfl or vbs) Test script 2 Test Script 3 How to Develop Re-usable components: Before going for scripting we need to analyze the application and identify the following: 1) The controls used in the application 2) Common functionality in the application The controls used in the application: . Web Button 2.

"Button: '" & Button_NM & "' does not exist" Button_Exist = micFail End if End Function 2. Page Name. Web Element 4.ReportEvent micFail." if( browser(Browser_Name). Button_NM) obj_msg = "To check for existence of Button: '" & Button_NM & "'.WebButton(Button). Web List 5. Page_Name.Exist) then Reporter." if(Browser(Browser_Name).ReportEvent micPass. Parameters: Browser_Name. Button. Edit box name Function fEditBox_Exist(Browser_Name. obj_msg. Edit_NM) obj_msg = "To check for existence of Edit Field: '" & Edit_NM & "'. Link 1. Page_Name. Parameters: Browser Name. Function fButton_Exist(Browser_Name. Function Name: fButton_Exist Description: To validate existence of Button. Button Object. "Button: '" & Button_NM & "' exists" fButton_Exist = micPass else Reporter. obj_msg.Page(Page_Name). Below function help us to validate the Existence of web edit on the web page Function Name: fEditBox_Exist Description: To check for Existence of Edit Box. Below function help us to validate the Existence of web button on the web page.WebEdit(Edit). Page_Name. Button Name. Edit.Exist) then .Page(Page_Name). Edit object.3.

ReportEvent micFail."Edit Field: '" & Edit_NM & "' does not exist" fEditBox_Exist = micFail End if End Function Common functionality in the application:.ReportEvent micPass. Login() 2.Reporter. Syntax: FunctionName = 0 Example: fEditBox_Exist = 0 Conclusions All the above approach and components discussed will help to create stable and efficient code that is easy to maintain for successive releases of the application under test.list out all the common functions in the application typically will have. obj_msg. Logout() 3. which can be used In main script for reporting. obj_msg. It can be carried out by assigning the value to the function name. . They simplify the maintenance task of the user. Other common business logics. Returning value from function:- Each function should return a value saying pass or fail status. "Edit Field: '" & Edit_NM & "' exists" fEditBox_Exist = micPass else Reporter. 1.