Descriptive Programming
Descriptive programming provides a means to perform interaction with runtime objects which are not in the Object
Repository.
The technique also proves, useful while developing test cases for applications which are not yet available for
working with objects.
When to use Descriptive Programming: -
Below are some of the examples when descriptive programming is considered a good alternative to using a
traditional object repository to define a test object.
1. When the objects in the application are dynamic in nature and need special handling to identify them at run
time
Example: - Clicking an object which changes according to the user navigation of the application.
2. When Object Repository is getting very large. If the size of OR increases too much then it decreases the
performance of QTP during runtime
3. When we do not want to use an OR at all.
4. When modification to an OR object is required, but the object repository in which the object is read only or
it is located in a shared OR and the changes may affect other scripts outside of our control.
5. When we want to take action on large number of similar/ uniform objects. For example we have 30 text
boxes on a page and their names are in form of txt_1, txt_2… txt_30. In this situation adding 30 entries to
OR would not be a good programming approach but using dynamically defined DP statements would be.
We can implement Descriptive Programming in below Approaches: -
1. By Using Description Objects (Dynamic)
2. By Using Description String (Static)
By Using Description Objects: - In this approach we create a description object and defined the properties and
values for recognizing the objects by QTP.
Description Objects: - Creating a user defined object without any properties.
Creating Description Object: -
Set = Description.Create
Assigning properties and Values: -
ObjName(“”).Value = “”
Example: - Set objDlg(“text”).Value = “Login”
Kill the object Process: - Set objName = Nothing
ScriptNo33: - Write a descriptive programming for login by using description objects
approach.
Descriptive programming provides a means to perform interaction with runtime objects which are not in the Object
Repository.
The technique also proves, useful while developing test cases for applications which are not yet available for
working with objects.
When to use Descriptive Programming: -
Below are some of the examples when descriptive programming is considered a good alternative to using a
traditional object repository to define a test object.
1. When the objects in the application are dynamic in nature and need special handling to identify them at run
time
Example: - Clicking an object which changes according to the user navigation of the application.
2. When Object Repository is getting very large. If the size of OR increases too much then it decreases the
performance of QTP during runtime
3. When we do not want to use an OR at all.
4. When modification to an OR object is required, but the object repository in which the object is read only or
it is located in a shared OR and the changes may affect other scripts outside of our control.
5. When we want to take action on large number of similar/ uniform objects. For example we have 30 text
boxes on a page and their names are in form of txt_1, txt_2… txt_30. In this situation adding 30 entries to
OR would not be a good programming approach but using dynamically defined DP statements would be.
We can implement Descriptive Programming in below Approaches: -
1. By Using Description Objects (Dynamic)
2. By Using Description String (Static)
By Using Description Objects: - In this approach we create a description object and defined the properties and
values for recognizing the objects by QTP.
Description Objects: - Creating a user defined object without any properties.
Creating Description Object: -
Set
Assigning properties and Values: -
ObjName(“
Example: - Set objDlg(“text”).Value = “Login”
Kill the object Process: - Set objName = Nothing
ScriptNo33: - Write a descriptive programming for login by using description objects
approach.
By Using Description String: - In this approach of description programming we don’t need to create a description object, instead we use Description String to recognize the objects. It means that we are maintaining object properties and their values in script itself.
Description String: - It is a property name and its value
Ex: - Dialog (“text: =Login”).WinButton (“text: =OK”).Click
ScriptNo34: - Write a descriptive programming for login by using Description String approach
Activating a Browser: -
iHwnd = Browser ("Gmail").GetROProperty("hwnd")
Window ("hwnd: ="&iHwnd).Activate
OR
ihwnd = Browser("name:=Google").GetROProperty("hwnd")
Window("hwnd:="&ihwnd ).Activate
MsgBox ihwnd
ScriptNo35: - Write a Descriptive Programming to create New Order
ScriptNo36: - Write a Descriptive Programming for g-mail.
SystemUtil.Run"iexplore","www.gmail.com"
Set obj = Browser ("name:= Gmail: Email from Google").Page("title:= Gmail: Email from Google")
If obj.Exist Then
obj.WebEdit("name:=Email").Set "abc@gmail.com"
obj.WebEdit("name:=Passwd").Set "password"
obj.WebButton("name:=signIn").Click
If Browser ("Name:= Microsoft Internet Explorer").page("title:= Gmail - Inbox").Link("innerText:=Sign
out").Exist Then
Reporter.ReportEvent micPass,"Login Validation","Logon validation Pass"
Browser ("Name:= Microsoft Internet Explorer").page("title:= Gmail -
Inbox").Link("innerText:=Sign out").Click
Browser ("Name:= Microsoft Internet Explorer").Close
Else
Reporter.ReportEvent micFail,"Login Validation","Logon validation Fail"
End If
End If
Set obj = Nothing
ScriptNo37: - Write a script to find number of buttons in Flight Reservation Window
Set obj = Window ("Flight Reservation")
Set objBtn = Description.Create
objBtn("Class Name").Value = "WinButton"
Set objLst = obj.ChildObjects (objBtn)
MsgBox objLst. Count
For index = 0 To objLst.Count -1
MsgBox objLst(index).GetROProperty("text")
Next
Set objBtn = Nothing
Set objLst = Nothing
Set obj = Nothing
ScriptNo38: - Write a script to retrieve WinButton, WinComboBox, WinList, WinEdit, WinRadioButton in Flight
Reservation window and write in excel file.
ScriptNo39: - Write a script to retrieve all names in a page
Set objlnk = Description.Create
objlnk("micClass").Value = "Link"
Set objlst = Browser("Google").Page("Google").ChildObjects(objlnk)
MsgBox objlst. Count
For index = 0 To objlst.Count-1
MsgBox objlst(index).GetROProperty("name")
Next
ScriptNo40: - Write a script to find number of browsers in desktop
Set objBrowser = Description.Create
objBrowser("application version").Value = "Internet explorer 7"
Set objLst = Desktop.ChildObjects(objBrowser)
MsgBox objLst.Count
For index = 0 To objLst.Count-1
MsgBox objLst(index).GetRoProperty("name")
Next Set objBrowser = Nothing
ScriptNo41: - Write a script to close all the browsers except required browser [like QC…]
Set objBrowser = Description.Create
objBrowser("application version").Value = "Internet explorer 7"
Set objLst = Desktop.ChildObjects(objBrowser)
For index = 0 To objLst.Count-1
If objLst(index).GetRoProperty("Name")<>"Goolge" Then
objLst(index).Close
End If
Next
Set objLst = Nothing
Set objBrowser = Nothing
________________________________________________________________________
Chapter XVII
Regular Expression
Regular Expressions are strings containing Special Meta characters used to, match patterns inside the scripting. Text
editors use this feature for doing color syntax highlighting and other operations. Whenever the object properties are
changing during run time then we are applying Regular Expression.
When to use SetToProperty method and Regular Expression?
1. Whenever we are using Object Repository
2. Whenever we are using Descriptive Programming then we have to use only Regular Expression
3. Whenever there is fixed change on properties, for an object and using OR then we can use SetToProperty
method
4. Whenever there is no fixed changes on properties, for an object with OR without OR then we can use RE
Applying Regular Expression through Object Repository: -
Open OR-->Select required object-->in test object details area select required property and click on configure the
value button-->enter RE string pattern-->check regular expression check box-->click on OK button.
Applying Regular Expression through Descriptive programming: -
Set objDlg = Description.Create
objDlg ("text").Value = "Fax Order No. *.*"
objDlg("text").RegularExpression = True
MsgBox Window("Flight Reservation").Dialog(objDlg).Exist
Regular Expression Characters: -
1. Match any Single Character (.): -
The “.” Character matches any single character for example,”...” will match
“12b”,”b3b”,”123”,”abc”,”$g#”etc…
2. Match any Single Character in List [xyz]: -
A character list inside square brackets matches any of the single characters in the list. For example”[abc][12]”
will match “a1”, “a2”, “b1”, “b2”, “c1”, “c2”etc…
3. Match any Single Character not in List [^xyz]: -
The “^” character is a negation character used to exclude a pattern from the Regular Expression. For example,
“[^a][12]” will not match “a1”, and “a2” but will match “11”, “12”, “c1” etc…
4. Match any Single Character in Within a Range[x-z]: -
The “[d-h]” construct will match any character ranging from d to h. for example, “[abcdef][123]” can also be
written as “[a-f][1-3]”
5. Match Zero or More Specific Characters (*): -
The “*” character is used to match Zero or more occurrences of regular expression that precedes the star. For
example, “a*” will match a blank string, “a”, “aa”, “aaa”, “aaaa”, etc…
“User.*” will match any string starting with text “User”
6. Match One or More Specific Characters (+): -
The “+” character is used to match one or more occurrences of a RE that precedes the plus sign. For example
“aa” can also be written as “a+”.
“123+” will match “123”, “1233”, “123333”, etc…
“[123]+” will match “1”, “2”, “3”, “12”, “23”, etc…
7. Match Zero or one Specific Character (?): -
A “?” character is used to match Zero or one occurrences of a proceeding RE. For example, “a[123]?” will
match “a”, “a1”, “a2” and “a3”
No comments :
Post a Comment