'' Name : fnVerifyDropDownItems(objDropdown, strItemsToSearch)
'' Description: This function is used to verify whether the Items exists in Dropdown box
'' Arguments :
''objDropdown: Dropdown box object in which the items are to be searched
''strItemsToSearch:Items that are to be searched separated by Comma (,)
''Example: "Domestic, Canada"
''Return: True/False
''Pre-Condition:The Dropdown box should be displayed
''Post-condition:
''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fnVerifyDropDownItems(objDropdown, strItemsToSearch)
Dim intItemsCount, intCounter, strItem, intItems, blnItemPresent
Dim arrItemsToSearch
fnVerifyDropDownItems=True
If (objDropdown.Exist = False) Then
reporter.report micFail,"The Dropdown box '" & objDropdown.GetROProperty("name") & "' should Exist", "The Dropdown Box does not exist", "FAIL")
fnVerifyDropDownItems=False
Exit Function
End If
'''''''' Get count of items in dropdown''''''''''''''''''
intItemsCount = objDropdown.GetTOProperty("items count")
''''''''Split the list items list based on comma(,)''''''
arrItemsToSearch = Split(strItemsToSearch, ",")
For intItems=0 to UBound(arrItemsToSearch)
blnItemPresent = False
''''''''''''Loop through all items''''''''''''''
For intCounter=1 to intItemsCount
strItem = ""
'''''''''' Get an item''''''''''''''''''
strItem = objDropdown.GetItem(intCounter)
'''''''''''''''If the search item is present'''''''''''''''''''''''
If (StrComp(Trim(strItem), Trim(arrItemsToSearch(intItems)), 1) = 0) Then
blnItemPresent = True
reporter.report micPass "The Item '" & arrItemsToSearch(intItems) & "' should be present in the dropdown box", "The specified Item exists in the dropdown box", "PASS")
Exit For
End If
Next
If (Not blnItemPresent) Then
reporter.report micFail , "The Item '" & arrItemsToSearch(intItems) & "' should be present in the dropdown box", "The specified Item does not exist in the dropdown box", "WARNING")
fnVerifyDropDownItems = False
End If
Next
End Function
This Blog has some used defined functions for QTP , which will be useful for all
Friday, July 6, 2007
Maximize the Browser
''Name : fnBrowserMaximize()
''Description: This function is used to Maximize the Browser
''Arguments:
''Example:
''Return True/False
'Pre-Condition: Chordiant Application
'Post-Condition:Chordiant Application
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fnBrowserMaximize()
fnBrowserMaximize=false
wait(2)
If Browser("Creationtime:=0").exist(1) then
If Browser("Creationtime:=0").Object.Top <> "-1" then
Browser("Creationtime:=0").Page("Creationtime:=0").sync
Browser("Creationtime:=0").FullScreen
fnBrowserMaximize=true
End If
End If
End Function
''Description: This function is used to Maximize the Browser
''Arguments:
''Example:
''Return True/False
'Pre-Condition: Chordiant Application
'Post-Condition:Chordiant Application
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fnBrowserMaximize()
fnBrowserMaximize=false
wait(2)
If Browser("Creationtime:=0").exist(1) then
If Browser("Creationtime:=0").Object.Top <> "-1" then
Browser("Creationtime:=0").Page("Creationtime:=0").sync
Browser("Creationtime:=0").FullScreen
fnBrowserMaximize=true
End If
End If
End Function
search for a Webobject in a webtable and to click the webobject
''Name : fnSearchAndClickTab(objTable,strSearchValue)
''Description: This function is used to search for a Webobject in a webtable and to click the webobject and returns true.If Webobject is not present then it return false.
''Arguments:: Web Table object
'': webElement that needs to be clicking in the screen
''Example:
'' Set objTable=Browser("Capital One").Page("ProphIT - 7560 - COF -").Frame("WorkFlowFrame").WebTable("Workflow")
'' strSearchValue="Add Notes"
''Return true/False
'Pre-Condition: nil
'Post-Condition:nil
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''Only for Tab order
Public Function fnSearchAndClickTab(objTable,strSearchValue)
fnSearchAndClickTab=False
Dim intRowCount
Dim intColumnCount
Dim strFromScreen
Dim objChild
Dim intRowLoop
Dim intColumnLoop
Dim intChildCount
Set objFrame=objTable
Set objPage=Browser("Chordiant").Page("Chordiant")
Call fnSynchroniseObjects(objPage,objFrame,20)
Browser("Chordiant").Page("Chordiant").sync
If isObject(objTable) and objTable.exist(0) Then' This will check for the object name
intRowCount = objTable.RowCount ' This will get the row count in that table
If not intRowCount=0 Then ' This will check whether the table is present or not
For intRowLoop =1 to intRowCount ' this navigates inside the table based on the row count
intColumnCount= objTable.ColumnCount(intRowLoop) ' this get the column count by giving the row number
For intColumnLoop = 1 to intColumnCount ' this navigates inside the table based on the column count
strFromScreen=objTable.GetCellData(intRowLoop,intColumnLoop) ' this get the value from the screen
If strcomp(trim(strFromScreen),trim(strSearchValue),1)=0 Then ' this compares the value from screen with value given
intChildCount=objTable.ChildItemCount( intRowLoop,int(intColumnLoop), "WebElement")' Verify for Webelement insite that table and gets count of it
If intChildCount<>0 Then
Set objChild=objTable.ChildItem (intRowLoop,int(intColumnLoop), "WebElement", 0)' Creates child element object
objChild.click ' selects the child element object
fnSearchAndClickTab=True
intRowLoop=intRowCount
intColumnLoop=intColumnCount
exit function
Else
Set objChild=objTable.ChildItem (intRowLoop,0, "WebElement", 0)' Creates child element object
objChild.click ' selects the child element object
fnSearchAndClickTab=True
intRowLoop=intRowCount
intColumnLoop=intColumnCount
exit function
End If
End If
Next
Next
End If
End If
Set objTable=nothing
End Function
''Description: This function is used to search for a Webobject in a webtable and to click the webobject and returns true.If Webobject is not present then it return false.
''Arguments:
''
''Example:
'' Set objTable=Browser("Capital One").Page("ProphIT - 7560 - COF -").Frame("WorkFlowFrame").WebTable("Workflow")
'' strSearchValue="Add Notes"
''Return true/False
'Pre-Condition: nil
'Post-Condition:nil
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''Only for Tab order
Public Function fnSearchAndClickTab(objTable,strSearchValue)
fnSearchAndClickTab=False
Dim intRowCount
Dim intColumnCount
Dim strFromScreen
Dim objChild
Dim intRowLoop
Dim intColumnLoop
Dim intChildCount
Set objFrame=objTable
Set objPage=Browser("Chordiant").Page("Chordiant")
Call fnSynchroniseObjects(objPage,objFrame,20)
Browser("Chordiant").Page("Chordiant").sync
If isObject(objTable) and objTable.exist(0) Then' This will check for the object name
intRowCount = objTable.RowCount ' This will get the row count in that table
If not intRowCount=0 Then ' This will check whether the table is present or not
For intRowLoop =1 to intRowCount ' this navigates inside the table based on the row count
intColumnCount= objTable.ColumnCount(intRowLoop) ' this get the column count by giving the row number
For intColumnLoop = 1 to intColumnCount ' this navigates inside the table based on the column count
strFromScreen=objTable.GetCellData(intRowLoop,intColumnLoop) ' this get the value from the screen
If strcomp(trim(strFromScreen),trim(strSearchValue),1)=0 Then ' this compares the value from screen with value given
intChildCount=objTable.ChildItemCount( intRowLoop,int(intColumnLoop), "WebElement")' Verify for Webelement insite that table and gets count of it
If intChildCount<>0 Then
Set objChild=objTable.ChildItem (intRowLoop,int(intColumnLoop), "WebElement", 0)' Creates child element object
objChild.click ' selects the child element object
fnSearchAndClickTab=True
intRowLoop=intRowCount
intColumnLoop=intColumnCount
exit function
Else
Set objChild=objTable.ChildItem (intRowLoop,0, "WebElement", 0)' Creates child element object
objChild.click ' selects the child element object
fnSearchAndClickTab=True
intRowLoop=intRowCount
intColumnLoop=intColumnCount
exit function
End If
End If
Next
Next
End If
End If
Set objTable=nothing
End Function
search for WebElement value in Webtable and to click the webElement
''Name : fnSearchAndClick(objTable,strSearchValue)
''Description: This function is used to search for WebElement value in Webtable and to click the webElement and returns true.If WebElement is not present then it return false.
''Arguments:: Web Table object
'': webElement that needs to be clicking in the screen
''Example:
'' Set objTable=Browser("Capital One").Page("ProphIT - 7560 - COF -").Frame("WorkFlowFrame").WebTable("Workflow")
'' strSearchValue="Add Notes"
''Return true/False
'Pre-Condition: Account Summary
'Post-Condition: Work Flow
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fnSearchAndClick(objTable,strSearchValue)
On Error Resume Next
fnSearchAndClick=False
Dim intRowCount
Dim intColumnCount
Dim strFromScreen
Dim objChild
Dim intRowLoop
Dim intColumnLoop
Dim intChildCount
Set objFrame=objTable
Set objPage=Browser("Chordiant").Page("Chordiant")
Call fnSynchroniseObjects(objPage,objFrame,20)
Browser("Chordiant").Page("Chordiant").sync
If isObject(objTable) and objTable.exist(0) Then' This will check for the object name
intRowCount = objTable.RowCount ' This will get the row count in that table
If not intRowCount=0 Then ' This will check whether the table is present or not
For intRowLoop =1 to intRowCount ' this navigates inside the table based on the row count
intColumnCount= objTable.ColumnCount(intRowLoop) ' this get the column count by giving the row number
For intColumnLoop = 1 to intColumnCount ' this navigates inside the table based on the column count
strFromScreen=objTable.GetCellData(intRowLoop,intColumnLoop) ' this get the value from the screen
If strcomp(trim(strFromScreen),trim(strSearchValue),1)=0 Then ' this compares the value from screen with value given
intChildCount=objTable.ChildItemCount( intRowLoop,int(intColumnLoop-1), "WebElement")' Verify for Webelement insite that table and gets count of it
If intChildCount<>0 Then
Set objChild=objTable.ChildItem (intRowLoop,int(intColumnLoop-1), "WebElement", 0)' Creates child element object
objChild.click ' selects the child element object
fnSearchAndClick=True
intRowLoop=intRowCount
intColumnLoop=intColumnCount
exit function
Else
Set objChild=objTable.ChildItem (intRowLoop,0, "WebElement", 0)' Creates child element object
objChild.click ' selects the child element object
fnSearchAndClick=True
intRowLoop=intRowCount
intColumnLoop=intColumnCount
exit function
End If
End If
Next
Next
End If
End If
End Function
''Description: This function is used to search for WebElement value in Webtable and to click the webElement and returns true.If WebElement is not present then it return false.
''Arguments:
''
''Example:
'' Set objTable=Browser("Capital One").Page("ProphIT - 7560 - COF -").Frame("WorkFlowFrame").WebTable("Workflow")
'' strSearchValue="Add Notes"
''Return true/False
'Pre-Condition: Account Summary
'Post-Condition:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fnSearchAndClick(objTable,strSearchValue)
On Error Resume Next
fnSearchAndClick=False
Dim intRowCount
Dim intColumnCount
Dim strFromScreen
Dim objChild
Dim intRowLoop
Dim intColumnLoop
Dim intChildCount
Set objFrame=objTable
Set objPage=Browser("Chordiant").Page("Chordiant")
Call fnSynchroniseObjects(objPage,objFrame,20)
Browser("Chordiant").Page("Chordiant").sync
If isObject(objTable) and objTable.exist(0) Then' This will check for the object name
intRowCount = objTable.RowCount ' This will get the row count in that table
If not intRowCount=0 Then ' This will check whether the table is present or not
For intRowLoop =1 to intRowCount ' this navigates inside the table based on the row count
intColumnCount= objTable.ColumnCount(intRowLoop) ' this get the column count by giving the row number
For intColumnLoop = 1 to intColumnCount ' this navigates inside the table based on the column count
strFromScreen=objTable.GetCellData(intRowLoop,intColumnLoop) ' this get the value from the screen
If strcomp(trim(strFromScreen),trim(strSearchValue),1)=0 Then ' this compares the value from screen with value given
intChildCount=objTable.ChildItemCount( intRowLoop,int(intColumnLoop-1), "WebElement")' Verify for Webelement insite that table and gets count of it
If intChildCount<>0 Then
Set objChild=objTable.ChildItem (intRowLoop,int(intColumnLoop-1), "WebElement", 0)' Creates child element object
objChild.click ' selects the child element object
fnSearchAndClick=True
intRowLoop=intRowCount
intColumnLoop=intColumnCount
exit function
Else
Set objChild=objTable.ChildItem (intRowLoop,0, "WebElement", 0)' Creates child element object
objChild.click ' selects the child element object
fnSearchAndClick=True
intRowLoop=intRowCount
intColumnLoop=intColumnCount
exit function
End If
End If
Next
Next
End If
End If
End Function
search for particular field in the table and to get the value in return
''Name : fnGetSearchData(objTable,intColumnCell,strSearchValue)
''Description: This function is used to search for particular field in the table and to get the value in return,
''for example on passing as "Primary:" it returns value like "abcd * efg", If that search value is not present
''then it returns "false" message
''Arguments:: Table object from where field name need to be searched
'': columns cell away from the Searched string
'': String need to be searched
''Example:
'' Set objTable=Browser("testing").Page("testing").Frame("WorkFlowFrame").WebTable("Primary:")
'' intColumnCell=1
'' strSearchValue="Primary:"
''Return Result Value/False
'Pre-Condition: NIL(Common)
'Post-Condition:NIL(Common)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public function fnGetSearchData(objTable,intColumnCell,strSearchValue)
On Error Resume Next
fnGetSearchData=false
'---------------Variable declaration-----------------------
Dim intRowCount
Dim intColumnCount
Dim strScreenValue
Dim intRowLoop
Dim intColLoop
'---------------Variable declaration-----------------------
Set objFrame=objTable
Set objPage=Browser("Chordiant").Page("Chordiant")
Call fnSynchroniseObjects(objPage,objFrame,20)
Browser("Chordiant").Page("Chordiant").sync
If IsObject(objTable) and objTable.Exist Then' Verify the Table object passed is an object and it exist or not
intRowCount=objTable.RowCount ' Gets the table row count
If not intRowCount ="" Then'Verify if the table row count is null or not
For intRowLoop=1 to intRowCount 'Loop navigates till row count ends
intColumnCount=objTable.ColumnCount(intRowLoop)' Get s the Table column count
For intColLoop =1 to intColumnCount' Loop navigates till column count ends
strScreenValue=objTable.GetCellData (intRowLoop,intColLoop)'Get the corresponding value from screen
If strcomp(trim(strScreenValue),trim(strSearchValue),1)=0 Then' compares the value from screen with value passed
intColumnCell=int(intColLoop+int(intColumnCell))
fnGetSearchData=objTable.GetCellData (intRowLoop,intColumnCell)' returns the value in function return value
Exit For ' After identifying the cell value it comes out of the loop
exit function
End If
Next
Next
End If
End If
End Function
''Description: This function is used to search for particular field in the table and to get the value in return,
''for example on passing
''then it returns "false" message
''Arguments:
''
''
''Example:
'' Set objTable=Browser("testing").Page("testing").Frame("WorkFlowFrame").WebTable("Primary:")
'' intColumnCell=1
'' strSearchValue="Primary:"
''Return Result Value/False
'Pre-Condition: NIL(Common)
'Post-Condition:NIL(Common)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public function fnGetSearchData(objTable,intColumnCell,strSearchValue)
On Error Resume Next
fnGetSearchData=false
'---------------Variable declaration-----------------------
Dim intRowCount
Dim intColumnCount
Dim strScreenValue
Dim intRowLoop
Dim intColLoop
'---------------Variable declaration-----------------------
Set objFrame=objTable
Set objPage=Browser("Chordiant").Page("Chordiant")
Call fnSynchroniseObjects(objPage,objFrame,20)
Browser("Chordiant").Page("Chordiant").sync
If IsObject(objTable) and objTable.Exist Then' Verify the Table object passed is an object and it exist or not
intRowCount=objTable.RowCount ' Gets the table row count
If not intRowCount ="" Then'Verify if the table row count is null or not
For intRowLoop=1 to intRowCount 'Loop navigates till row count ends
intColumnCount=objTable.ColumnCount(intRowLoop)' Get s the Table column count
For intColLoop =1 to intColumnCount' Loop navigates till column count ends
strScreenValue=objTable.GetCellData (intRowLoop,intColLoop)'Get the corresponding value from screen
If strcomp(trim(strScreenValue),trim(strSearchValue),1)=0 Then' compares the value from screen with value passed
intColumnCell=int(intColLoop+int(intColumnCell))
fnGetSearchData=objTable.GetCellData (intRowLoop,intColumnCell)' returns the value in function return value
Exit For ' After identifying the cell value it comes out of the loop
exit function
End If
Next
Next
End If
End If
End Function
Synchronize for a particular object
// function to Synchronize for a particular object
Public function fnSynchronization(objName)
fnSynchronization=false
Dim intLoopStart
Dim intLoopwait
intLoopStart=1
intLoopwait=10
Set objName=objName
'Waiting for the object to appear
Do while intLoopStart<=intLoopwait
'wait for exitance of that object
If objName.Exist(1) then
fnSynchronization=true
Exit do
Else
intLoopStart=intLoopStart+1
End if
Loop
End function
Public function fnSynchronization(objName)
fnSynchronization=false
Dim intLoopStart
Dim intLoopwait
intLoopStart=1
intLoopwait=10
Set objName=objName
'Waiting for the object to appear
Do while intLoopStart<=intLoopwait
'wait for exitance of that object
If objName.Exist(1) then
fnSynchronization=true
Exit do
Else
intLoopStart=intLoopStart+1
End if
Loop
End function
Get Record from database and display result
///this function is used to get the Record from the Database and display the result
Public Function fnGetRecord(strSQL,strConnectionString)
fnGetRecord=false
Dim dBRecSet,dBConnection
'Set the Database connection object
Set dBConnection=fnDBOpenConnection(strConnectionString)
'Verify for object exist or not
If isobject(dBConnection) Then
'Execute the SQL and get the recordset object
On error resume next
Set dBRecSet= dBConnection.execute(strSQL)
'Verify for the record set has reached EOF or not
If dBRecSet.EOF=false Then
blnResult=fnDisplayResult(dBRecSet,"dbo.fpac_acct_hedgeoverlay")
If blnResult Then
'return the recordset object back
'Set fnGetRecord=dBRecSet
fnGetRecord=true
End IF
'Check for the error number
If not err.number = 0 then
'fnInsertResult "Database Verification", "Verifying the Record from Database", "Error in either Table name or column name", "WARNING"
Reporter.ReportEvent micWarining, "Verifying the Record from Database", "Error in either Table name or column name"
fnGetRecord=false
Exit function
End If
On error goto 0
Else
'fnInsertResult "Database Verification", "Verifying the Record from Database", "No Record exist", "FAIL"
Reporter.ReportEvent micFail, "Verifying the Record from Database", "No Record Exist"
'Verify for the record set has reached EOF or not
End If
Else
fnGetRecord=false
'Verify for object exist or not
End If
'reinitialize the object to null
Set dBConnection=nothing
Set dBRecSet=nothing
End Function
''This function is used to display result from the record set object
Public function fnDisplayResult(dBRecSet,strTableName)
fnDisplayResult=false
Dim intLoop
If isobject(dBRecSet) Then
If dBRecSet.EOF = false Then
Do While Not dBRecSet.eof
For each intLoop in dBRecSet.fields
'fnInsertResult "Records form the database for Table Name"&strTableName, "Verifying the value for columns "&intLoop.name, " Value is : "&intLoop.value, "PASS"
Reporter.ReportEvent micPass, "Verifying the value for columns '"&intLoop.name&"' in Table '"&strTableName & "'", " Value is : '" &intLoop.value &"'"
fnDisplayResult=true
next
dBRecSet.MoveNext
Loop
Else
'fnInsertResult "Database Verification", "Verifying the Record from Database", "No Record exist", "FAIL"
Reporter.ReportEvent micFail, "Verifying the Record from Database", "No Record Exist"
End If
End If
Set dBRecSet = nothing
End Function
Public Function fnGetRecord(strSQL,strConnectionString)
fnGetRecord=false
Dim dBRecSet,dBConnection
'Set the Database connection object
Set dBConnection=fnDBOpenConnection(strConnectionString)
'Verify for object exist or not
If isobject(dBConnection) Then
'Execute the SQL and get the recordset object
On error resume next
Set dBRecSet= dBConnection.execute(strSQL)
'Verify for the record set has reached EOF or not
If dBRecSet.EOF=false Then
blnResult=fnDisplayResult(dBRecSet,"dbo.fpac_acct_hedgeoverlay")
If blnResult Then
'return the recordset object back
'Set fnGetRecord=dBRecSet
fnGetRecord=true
End IF
'Check for the error number
If not err.number = 0 then
'fnInsertResult "Database Verification", "Verifying the Record from Database", "Error in either Table name or column name", "WARNING"
Reporter.ReportEvent micWarining, "Verifying the Record from Database", "Error in either Table name or column name"
fnGetRecord=false
Exit function
End If
On error goto 0
Else
'fnInsertResult "Database Verification", "Verifying the Record from Database", "No Record exist", "FAIL"
Reporter.ReportEvent micFail, "Verifying the Record from Database", "No Record Exist"
'Verify for the record set has reached EOF or not
End If
Else
fnGetRecord=false
'Verify for object exist or not
End If
'reinitialize the object to null
Set dBConnection=nothing
Set dBRecSet=nothing
End Function
''This function is used to display result from the record set object
Public function fnDisplayResult(dBRecSet,strTableName)
fnDisplayResult=false
Dim intLoop
If isobject(dBRecSet) Then
If dBRecSet.EOF = false Then
Do While Not dBRecSet.eof
For each intLoop in dBRecSet.fields
'fnInsertResult "Records form the database for Table Name"&strTableName, "Verifying the value for columns "&intLoop.name, " Value is : "&intLoop.value, "PASS"
Reporter.ReportEvent micPass, "Verifying the value for columns '"&intLoop.name&"' in Table '"&strTableName & "'", " Value is : '" &intLoop.value &"'"
fnDisplayResult=true
next
dBRecSet.MoveNext
Loop
Else
'fnInsertResult "Database Verification", "Verifying the Record from Database", "No Record exist", "FAIL"
Reporter.ReportEvent micFail, "Verifying the Record from Database", "No Record Exist"
End If
End If
Set dBRecSet = nothing
End Function
Subscribe to:
Posts (Atom)