Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
doc
Table of Contents
Descriptive Programming....................................................2
Background......................................................................................................................2
Concept of Descriptive Programming.............................................................................2
Why Descriptive Programming based scripting framework...........................................2
Contents on a Web Page..................................................................................................3
Function Library..................................................................4
1.) Common Function......................................................................................................4
Use...............................................................................................................................4
Arguments....................................................................................................................4
Code and Explanation..................................................................................................4
2.) Search Function..........................................................................................................6
Use...............................................................................................................................6
Arguments....................................................................................................................6
Code and Explanation..................................................................................................7
3.) NextScreen Function................................................................................................10
Use:............................................................................................................................10
Arguments..................................................................................................................10
Code and Explanation................................................................................................10
4.) CommonTable Function...........................................................................................11
Use:............................................................................................................................11
Arguments..................................................................................................................11
Code...........................................................................................................................11
5.) SearchTable Function...............................................................................................12
Use.............................................................................................................................12
Arguments..................................................................................................................12
Code...........................................................................................................................13
6.) ClearCell Function...................................................................................................14
Use.............................................................................................................................14
Arguments..................................................................................................................14
Page 1
1/25/2015
258322243.doc
Descriptive Programming
Background
Quick Test Professional (QTP) while recording stores all the properties required to define
web objects in its object repository. When the script is run the object repository is used to
identify the objects in the application.
When an operation is recorded on an object, Quick Test Professional adds the appropriate
test object to the object repository along with its properties. Once the object along with its
property is added in the object repository, statements can be added in the Expert View of
the tool to perform additional methods/functions on the added object.
The statements are added usually by entering the name (not case sensitive) of each of the
objects in the object's hierarchy as the object description, and then add the appropriate
method.
Generic code can be used for any kind of Web Application which increases
reusability.
Single script is used for test case preparation : single script, multiple usage
Page 2
1/25/2015
258322243.doc
Condition based testing Captures hidden controls on the application which are
visible on the fulfillment of certain criteria thereby reducing the count of invalid
defects
Page 3
1/25/2015
258322243.doc
Function Library
1.) Common Function
Use
Common Function gets all the objects of a screen along with its properties in an Excel
sheet.
Arguments
Common Function has five arguments
1. excelSheet: The existing sheet in C drive
2. snameBrowser: The name of the Browser
3. stitlePage: The Title of the Page
4. val: The type of control
5. val2: The value of Property HTML tag in case of WebElement otherwise Blank
If the Class is WebElement, the object is defined by two properties, micclass and html
tag.
List will contain all the childobjects of type WebElement with the mentioned html tag.
objcount=List.count()
rowCount = excelSheet.UsedRange.Rows.count
Page 4
1/25/2015
258322243.doc
objcount contains the number of childobjects of type WebElement with the mentioned
html tag.
rowcount contains the number of filled (used) rows of the excel sheet.
For j=0 to objcount-1
excelSheet.Cells(rowCount + 1 , "A") = snameBrowser
excelSheet.Cells(rowCount + 1 , "B") = stitlePage
If val2 = "SPAN" Then
arr2=List(j).GetROProperty("html id")
excelSheet.Cells(rowCount + 1 , "F") = arr2
excelSheet.Cells(rowCount + 1 , "D") = arr2
'MyArray = Split(arr2, "_", -1, 1)
'No=Ubound(MyArray)
'excelSheet.Cells(rowCount + 1 , "D") = MyArray(No)
excelSheet.Cells(rowCount + 1 , "C") = val
arr1=List(j).GetROProperty("innerText")
excelSheet.Cells(rowCount + 1 , "G") = arr1
rowCount = rowCount + 1
Else
rr2=List(j).GetROProperty("innerhtml")
excelSheet.Cells(rowCount + 1 , "F") = arr2
excelSheet.Cells(rowCount + 1 , "D") = arr2
'MyArray = Split(arr2, ",", -1, 1)
'No=Ubound(MyArray)
'excelSheet.Cells(rowCount + 1 , "D") = MyArray(No)
excelSheet.Cells(rowCount + 1 , "C") = val
arr1=List(j).GetROProperty("innerText")
excelSheet.Cells(rowCount + 1 , "G") = arr1
rowCount = rowCount + 1
End if
Next
Page 5
1/25/2015
258322243.doc
Else
Obj("micclass").Value = val
Set List =Browser("name:="&snameBrowser).Page("title:="&stitlePage).ChildObjects(Obj)
objcount=List.count()
rowCount = excelSheet.UsedRange.Rows.count
For j=0 to objcount-1
arr1=List(j).GetROProperty("Name")
excelSheet.Cells(rowCount + 1 , "E") = arr1
MyArray = Split(arr1, "$", -1, 1)
No=Ubound(MyArray)
excelSheet.Cells(rowCount + 1 , "D") = MyArray(No)
excelSheet.Cells(rowCount + 1 , "A") = snameBrowser
excelSheet.Cells(rowCount + 1 , "B") = stitlePage
arr2=List(j).GetROProperty("html id")
excelSheet.Cells(rowCount + 1 , "F") = arr2
excelSheet.Cells(rowCount + 1 , "C") = val
arr3=List(j).GetROProperty("value")
excelSheet.Cells(rowCount + 1 , "G") = arr3
If val = "Image" Then
arr2=List(j).GetROProperty("html id")
excelSheet.Cells(rowCount + 1 , "F") = arr2
End If
If val = "WebRadioGroup" Then
arr2=List(j).GetROProperty("value")
excelSheet.Cells(rowCount + 1 , "G") = arr2
End If
rowCount = rowCount + 1
Next
End if
End Function
Page 6
1/25/2015
258322243.doc
Arguments
One argument is passed in this function.
excelSheet: The existing sheet in the C: drive
Variables
Dim X, XL, Row, iRow , xRow, T, Bname, Ptitle
Next is used for identifying the navigated screen and populating the excelSheet with all
the objects and its properties.
When T = Next, NextScreen(excelSheet) function is called.
NextScreen is used for identifying the navigated screen and populating the excelSheet
with all the objects and its properties.
Page 7
1/25/2015
258322243.doc
For T = Checkpoint, Otherinfo field in the datatable of the script provides the browser
name and the html tag of the Web Element which needs to be checked.
Browser Name and HTML Tag is retrieved using the split command where the
delimiter/splitter is ,
This browser name and HTML tag along with the Page Title* is passed in the common
function.
*Page Title is same as browser name in the current application. If it changes then
Otherinfo will have Browser Name, Page Title, HTML Tag. Arguments in the Common
Function will be changed to the following in the above case.
Call Common (excelSheet, oinf(0), oinf(1), "WebElement", oinf(2))
XL = excelSheet.Cells(iRow, "D")
Do Until (X = XL or iRow = Row)
iRow = iRow + 1
XL = excelSheet.Cells(iRow, "D")
Loop
Initially iRow=2
Keep iterating, until X=XL or iRow=Row ie keep iterating through the loop until the field
value from datatable is matched with that of the excelSheet or iRow is equal to the last
row count of the excel sheet.
Increment iRow value by one in each iteration.
Exit from the loop gives the row no containing the field
Datatable.Value("Browser", dtglobalSheet) = excelSheet.Cells(iRow, "A")
Page 8
1/25/2015
258322243.doc
If excelSheet.Cells(iRow, "C") = "WebEdit" Then
If DataTable.Value("Otherinfo", dtGlobalSheet) = "Check" Then
Prp = excelSheet.Cells(iRow, "G")
Else
Prp = excelSheet.Cells(iRow, "F")
End if
End If
Page 9
1/25/2015
258322243.doc
DataTable.Value("vRow", dtGlobalSheet) = vRow
Arguments
excelSheet: The existing excelsheet in C: drive
Page 10
1/25/2015
258322243.doc
Arguments
CommonTable Function has the following six arguments
1. excelSheet: The existing sheet in C drive
2. snameBrowser: The name of the Browser
3. stitlePage: The Title of the Page
4. val: The html id of WebTable
5. val2: micclass
6. val3:value of html tag
Code
Public Function CommonTable(excelSheet, snameBrowser, stitlePage, val, val2, val3)
Dim arr1, var2, tempValue,arr2, arr3
Set Obj=Description.create()
Dim MyString, MyArray, Msg,No
If val2 = "WebElement" Then
Obj("micclass").Value = val2
Obj("html tag").Value = val3
Set List=Browser("name:="&snameBrowser).Page("title:="&stitlePage).WebTable("html
id:="&val).ChildObjects(Obj)
objcount=List.count()
rowCount = excelSheet.UsedRange.Rows.count
For j=0 to objcount-1
excelSheet.Cells(rowCount + 1 , "A") = snameBrowser
excelSheet.Cells(rowCount + 1 , "B") = stitlePage
If val3 = "SPAN" Then
arr2=List(j).GetROProperty("html id")
excelSheet.Cells(rowCount + 1 , "F") = arr2
excelSheet.Cells(rowCount + 1 , "D") = arr2
excelSheet.Cells(rowCount + 1 , "C") = val2
arr1=List(j).GetROProperty("innerText")
excelSheet.Cells(rowCount + 1 , "G") = arr1
excelSheet.Cells(rowCount + 1 , "H") = "WebTable"
rowCount = rowCount + 1
Else
arr2=List(j).GetROProperty("innerhtml")
excelSheet.Cells(rowCount + 1 , "F") = arr2
excelSheet.Cells(rowCount + 1 , "D") = arr2
excelSheet.Cells(rowCount + 1 , "C") = val2
arr1=List(j).GetROProperty("innerText")
excelSheet.Cells(rowCount + 1 , "G") = arr1
excelSheet.Cells(rowCount + 1 , "H") = "WebTable"
rowCount = rowCount + 1
Page 11
1/25/2015
258322243.doc
End if
Next
Else
Obj("micclass").Value = val2
Set List=Browser("name:="&snameBrowser).Page("title:="&stitlePage).WebTable("html
id:="&val).ChildObjects(Obj)
objcount=List.count()
rowCount = excelSheet.UsedRange.Rows.count
For j=0 to objcount-1
arr1=List(j).GetROProperty("Name")
excelSheet.Cells(rowCount + 1 , "E") = arr1
MyArray = Split(arr1, "$", -1, 1)
No=Ubound(MyArray)
excelSheet.Cells(rowCount + 1 , "D") = MyArray(No)
excelSheet.Cells(rowCount + 1 , "A") = snameBrowser
excelSheet.Cells(rowCount + 1 , "B") = stitlePage
arr2=List(j).GetROProperty("html id")
excelSheet.Cells(rowCount + 1 , "F") = arr2
excelSheet.Cells(rowCount + 1 , "C") = val2
arr3=List(j).GetROProperty("value")
excelSheet.Cells(rowCount + 1 , "G") = arr3
excelSheet.Cells(rowCount + 1 , "H") = "WebTable"
If val2 = "Image" Then
arr2=List(j).GetROProperty("alt")
excelSheet.Cells(rowCount + 1 , "F") = arr2
End If
If val2 = "WebRadioGroup" Then
arr2=List(j).GetROProperty("value")
excelSheet.Cells(rowCount + 1 , "G") = arr2
End If
rowCount = rowCount + 1
Next
End if
End Function
Arguments
Search Table as 2 arguments namely
1. excelSheet: The existing Excelsheet in C:drive
2. htmlid_Table: The html id of the WebTable
Page 12
1/25/2015
258322243.doc
Code
Function SearchTable (excelSheet, htmlid_Table)
Dim X, XL, Row, iRow , xRow, T, Bname, Ptitle, YL
vRow = DataTable.Value("vRow", dtGlobalSheet)
DataTable.SetCurrentRow(vRow+1)
T = Datatable.Value("Type", dtglobalSheet)
X = Datatable.Value("Field", dtglobalSheet)
Row = excelSheet.UsedRange.Rows.Count
iRow = 2
If T = "CheckPoint" Then
Dim oinf, inf
inf = DataTable.Value("Otherinfo", dtglobalSheet)
oinf = Split(inf, ",", -1, 1)
Call CommonTable (excelSheet, oinf(0), oinf(0), htmlid_Table, "WebElement", oinf(1))
Row = excelSheet.UsedRange.Rows.Count
End If
XL = excelSheet.Cells(iRow, "D")
YL = excelSheet.Cells(iRow, "H")
Do Until ((X = XL and YL = "WebTable") or iRow = Row)
iRow = iRow + 1
XL = excelSheet.Cells(iRow, "D")
YL = excelSheet.Cells(iRow, "H")
Loop
Datatable.Value("Browser", dtglobalSheet) = excelSheet.Cells(iRow, "A")
If excelSheet.Cells(iRow, "C") = "WebList" Then
Prp = excelSheet.Cells(iRow, "F")
End If
If excelSheet.Cells(iRow, "C") = "WebEdit" Then
If DataTable.Value("Otherinfo", dtGlobalSheet) = "Check" Then
Prp = excelSheet.Cells(iRow, "G")
Else
Prp = excelSheet.Cells(iRow, "F")
End if
End If
If excelSheet.Cells(iRow, "C") = "Image" Then
Prp = excelSheet.Cells(iRow, "F")
End If
If excelSheet.Cells(iRow, "C") = "WebRadioGroup" Then
MyString = excelSheet.Cells(iRow, "F")
'Keeping the code for future use
'
'
'
'
'
'
'
'
'
'
'
'
'
Page 13
1/25/2015
258322243.doc
Prp = MyString
End If
If excelSheet.Cells(iRow, "C") = "Link" Then
Prp = excelSheet.Cells(iRow, "E")
End If
If excelSheet.Cells(iRow, "C") = "WebElement" Then
Prp = excelSheet.Cells(iRow, "G")
Call ClearCell(excelSheet, "WebElement")
End If
If excelSheet.Cells(iRow, "C") = "WebCheckBox" Then
Prp = excelSheet.Cells(iRow, "F")
End If
SearchTable = Prp
vRow = vRow + 1
DataTable.Value("vRow", dtGlobalSheet) = vRow
End Function
Arguments
excelSheet: The existing Excelsheet in C:drive
Code
Function ClearCell (excelSheet, val)
Dim Row, iRow
Row = excelSheet.UsedRange.Rows.Count
For iRow = Row to 2 Step -1
If excelSheet.Cells(iRow, "C") = val Then
excelSheet.Cells(iRow, "C").EntireRow.Delete
End If
Next
End Function
Page 14
1/25/2015
258322243.doc
Main Script
Dim excelSheet
Set ExcelApp = CreateObject("Excel.Application")
Set NewWorkbook = ExcelApp.Workbooks.Open("C:/CaptureProperties_page.xls")
Set OpenWorkbook = NewWorkbook
ExcelApp.Visible = True
Set excelSheet = ExcelApp.ActiveSheet
ExcelApp.Visible = True
Dim cnt, iter, i, bname, pname
cnt = DataTable.GetRowCount
For iter = 1 to cnt +1
If (DataTable.Value("Type", dtGlobalSheet) = "Static" or DataTable.Value("Type",
dtGlobalSheet) = "Capture") Then
If DataTable.Value("Type", dtGlobalSheet) = "Static" Then
bname = DataTable.Value("Browser", dtglobalSheet)
pname = DataTable.Value("Browser", dtglobalSheet)
DataTable.Value("vRow", dtGlobalSheet) = i
vRow = DataTable.Value("vRow", dtGlobalSheet)
DataTable.SetCurrentRow(vRow+1)
Datatable.Value("Value", dtglobalSheet) = Browser("name:=Home Insurance
Quote").Dialog("text:=Microsoft Internet
Explorer").WinRadioButton("text:=OK").GetROProperty("attached text")
Browser("name:="&bname).Dialog("text:=Microsoft Internet
Explorer").WinRadioButton("text:=OK").Click
vRow = vRow + 1
DataTable.Value("vRow", dtGlobalSheet) = vRow
DataTable.SetCurrentRow(vRow+1)
DataTable.Value("vRow", dtGlobalSheet) = vRow
End If
If DataTable.Value("Type", dtGlobalSheet) = "Capture" Then
DataTable.Value("vRow", dtGlobalSheet) = i
vRow = DataTable.Value("vRow", dtGlobalSheet)
DataTable.SetCurrentRow(vRow)
temp = DataTable.Value("Value", dtGlobalSheet)
DataTable.SetCurrentRow(1)
DataTable.Value("Value", dtGlobalSheet) = temp
vRow = vRow + 1
DataTable.Value("vRow", dtGlobalSheet) = vRow
DataTable.SetCurrentRow(vRow+1)
DataTable.Value("vRow", dtGlobalSheet) = vRow
End If
Else
i = Search(excelSheet)
bname = DataTable.Value("Browser", dtglobalSheet)
pname = DataTable.Value("Browser", dtglobalSheet)
If DataTable.Value("Type", dtGlobalSheet) = "CheckPoint" Then
Datatable.Value("Value", dtglobalSheet) = i
End if
If DataTable.Value("Type", dtGlobalSheet) = "WebList" Then
Page 15
1/25/2015
258322243.doc
Browser("name:="&bname).Page("title:="&pname).WebList("html id:="&i).Select
Datatable.Value("Value", dtGlobalSheet)
End If
If DataTable.Value("Type", dtGlobalSheet) = "WebEdit" Then
If DataTable.Value("Otherinfo", dtGlobalSheet) = "Check" Then
Datatable.Value("Value", dtGlobalSheet) = i
Else
Browser("name:="&bname).Page("title:="&pname).WebEdit("html id:="&i).Set
Datatable.Value("Value", dtGlobalSheet)
End if
End if
If DataTable.Value("Type", dtGlobalSheet) = "Image" Then
Browser("name:="&bname).Page("title:="&pname).Image("html id:="&i).click
wait 10
End if
If DataTable.Value("Type", dtGlobalSheet) = "WebRadioGroup" Then
Browser("name:="&bname).Page("title:="&pname).WebRadioGroup("html
id:="&i).Select Datatable.Value("Value", dtGlobalSheet)
End if
If DataTable.Value("Type", dtGlobalSheet) = "Link" Then
Browser("name:="&bname).Page("title:="&pname).Link("name:="&i).Click
End if
If DataTable.Value("Type", dtGlobalSheet) = "WebCheckBox" Then
Browser("name:="&bname).Page("title:="&pname).WebCheckBox("html id:="&i).Set
Datatable.Value("Value", dtGlobalSheet)
End if
If DataTable.Value("Type", dtGlobalSheet) = "WebTable" Then
Dim oinf1, inf1
inf1 = DataTable.Value("Otherinfo", dtglobalSheet)
oinf1 = Split(inf1, ",", -1, 1)
Call CommonTable(excelSheet, bname, pname, i, oinf1(0),oinf1(1))
j = SearchTable(excelSheet, i)
If DataTable.Value("Type", dtGlobalSheet) = "CheckPoint" Then
Datatable.Value("Value", dtglobalSheet) = j
End if
If DataTable.Value("Type", dtGlobalSheet) = "WebList" Then
Browser("name:="&bname).Page("title:="&pname).WebTable("html
id:="&i).WebList("html id:="&j).Select Datatable.Value("Value", dtGlobalSheet)
End If
If DataTable.Value("Type", dtGlobalSheet) = "WebEdit" Then
If DataTable.Value("Otherinfo", dtGlobalSheet) = "Check" Then
Datatable.Value("Value", dtGlobalSheet) = j
Else
Browser("name:="&bname).Page("title:="&pname).WebTable("html id:="&i).WebEdit("html
id:="&j).Set Datatable.Value("Value", dtGlobalSheet)
End if
End if
If DataTable.Value("Type", dtGlobalSheet) = "Image" Then
Browser("name:="&bname).Page("title:="&pname).WebTable("html
id:="&i).Image("alt:="&j).click
wait 10
Page 16
1/25/2015
258322243.doc
End if
If DataTable.Value("Type", dtGlobalSheet) = "WebRadioGroup" Then
Browser("name:="&bname).Page("title:="&pname).WebTable("html
id:="&i).WebRadioGroup("html id:="&j).Select Datatable.Value("Value", dtGlobalSheet)
End if
If DataTable.Value("Type", dtGlobalSheet) = "Link" Then
Browser("name:="&bname).Page("title:="&pname).Link("name:="&j).Click
End if
If DataTable.Value("Type", dtGlobalSheet) = "WebCheckBox" Then
Browser("name:="&bname).Page("title:="&pname).WebTable("html
id:="&i).WebCheckBox("html id:="&j).Set Datatable.Value("Value", dtGlobalSheet)
End if
End if
End if
Next
Page 17
1/25/2015