Professional Documents
Culture Documents
(Advanced)
Shanmugadas.C.S
Created On : 04-10-2005
• Parameterization
• DataConn = "C:\Das\tozip\lib\flight32.mdb"
• Set Conn = CreateObject("ADODB.Connection")
• ConStr = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & DataConn & ";"
• Conn.open(ConStr)
• recordset.close
• Conn.Close
• set f = CreateFile(FilePath)
•
• Fexist= CheckFileExists(FilePath)
• d = WriteToFile(f,"first line")
• d = WriteToFile(f,"second line")
• d = CloseFile(f)
• FileCopy "D:\temp\FSO\txt.txt","D:\temp\FSO\txt1.txt"
• FileDelete "D:\temp\FSO\txt1.txt"
• For i=1 to 3
• 'For j=1 to 2
• 'msgbox Trim(objSheet.Cells(i, j).Value)
• ' Next
• DataTable.SetCurrentRow i
• DataTable("SL_No", dtGlobalSheet)=Trim(objSheet.Cells(i, 1).Value)
• DataTable("Name", dtGlobalSheet)=Trim(objSheet.Cells(i,
2).Value)
•
• Next
• objExcel.Application.Quit
• Set objExcel=Nothing
October 15, 2008 14
QTP Utility Functions – Email
Operations
• SendMail "cssdas@hp.com","hi","how r u",""
• Set ol=CreateObject("Outlook.Application")
• Set Mail=ol.CreateItem(0)
• Mail.to=SendTo
• Mail.Subject=Subject
• Mail.Body=Body
• If (Attachment <> "") Then
• Mail.Attachments.Add(Attachment)
• End If
• Mail.Send
• ol.Quit
• Set Mail = Nothing
• Set ol = Nothing
• End Function
• Dim xmlFilePath
• Dim xmlDoc
• Dim nodeBook, nodeId, sIdXml, currNode
• '********************************************************************************
• ' Function UpdateXMLAttribute
• '********************************************************************************
• Public Function UpdateXMLAttribute(xmlFilePath, xmlElement, xmlAttribute,
NewXMLValue)
• LoadXMLFile(xmlFilePath)
• ReplaceAttributeValue xmlElement, xmlAttribute, NewXMLValue
• SaveXMLFile (xmlFilePath)
• Set xmlDoc = Nothing
• End Function
• '********************************************************************************
October 15, 2008 16
QTP Utility Functions - XML
• '****************************************************************************
****
• ' Function UpdateXMLElementData
• '****************************************************************************
****
• Public Function UpdateXMLElementData(xmlFilePath,
ElementPath,ElementName, ElementIndex, NewElementData)
•
• Dim CurrentNode, CurrentValue
• LoadXMLFile(xmlFilePath)
• Set CurrentNode = xmlDoc.selectSingleNode(ElementPath)
• Set CurrentValue =
CurrentNode.getElementsByTagName(ElementName)
• CurrentValue.item(ElementIndex).text = NewElementData
• SaveXMLFile (xmlFilePath)
• Set xmlDoc = Nothing
• End Function
• '****************************************************************************
****
• ' End15,of2008
October Function UpdateXMLElementData 17
QTP Utility Functions - XML
• ' Function GetXMLAttribute
• Public Function GetXMLAttribute(xmlFilePath, xmlElement, xmlAttribute)
• Dim AttributeValue
• LoadXMLFile(xmlFilePath)
• AttributeValue = GetAttributeValue(xmlElement, xmlAttribute)
• Set xmlDoc = Nothing
• GetXMLAttribute = AttributeValue
• End Function
• '********************************************************************************
• ' End of Function GetXMLAttribute
• '********************************************************************************
• ' Function LoadXMLFile
• '********************************************************************************
• Public Function LoadXMLFile(Path)
• Dim sIdValue
• Set nodeBook = xmlDoc.selectSingleNode(xmlElement)
• sIdValue = nodeBook.getAttribute(xmlAttribute)
• GetAttributeValue = sIdValue
•
• End Function
• '********************************************************************************
• ' End of Function GetAttributeValue
• '********************************************************************************
• '********************************************************************************
• ' Function ReplaceAttributeValue
• '********************************************************************************
• Public Function ReplaceAttributeValue (xmlElement, xmlAttribute, NewXMLValue)
• xmlDoc.save(SavePath)
• End FUnction
• '********************************************************************************
• ' End of Function SaveXMLFile
• '********************************************************************************
• '********************************************************************************
• ' Function XMLError
• '********************************************************************************
• Public Function XMLError()
• Dim myErr
• Set myErr = xmlDoc.parseError
• MsgBox("XML Error : " & myErr.reason)
• End Function
• '********************************************************************************
• ' End of Function XMLError
October 15, 2008 20
QTP Utility Functions - XML
• '********************************************************************
************
• ' Function GetXMLElement
• '********************************************************************
************
• Public Function GetXMLElement(xmlFilePath, xmlNode, xmlElement)
• Dim CurrentNode, CurrentValue
• LoadXMLFile(xmlFilePath)
• Set CurrentNode = xmldoc.selectSingleNode(xmlNode)
• Set CurrentValue =
CurrentNode.getElementsByTagName(xmlElement)
• GetXMLElement = CurrentValue.item(0).Text
• End Function
• '********************************************************************
************
• ' End of Function GetXMLElement
• '********************************************************************
************
October 15, 2008 21
QTP Utility Functions – MSDN
Integration
• extern.Declare
micLong,"GetForegroundWindow","user32.dll","GetForegroundW
indow"
• hwnd = extern.GetForegroundWindow()
• If hwnd = 0 Then
• Msgbox "Window Not Found"
• ExitRun
• Else
• Msgbox "Window Found with Handle ”&hwnd
• Succeeded = TextUtil.GetTextLocation("16",0,l,t,r,b)
• If Not Succeeded Then
• MsgBox "Text not found"
• else
• x = (l+r) / 2
• y = (t+b) / 2
• Set dr = CreateObject("Mercury.DeviceReplay")
• dr.MouseClick x, y, 0
• End If
• Window("Notepad").Activate
• obj.PressKey 63
• The RightMenuSelect function selects the menu item at index "idx" from the pop-up
menu that appears when right-clicking on an object.
• x_coord = Obj.GetROProperty("abs_x")
• y_coord = Obj.GetROProperty("abs_y")
• Set dr = CreateObject("Mercury.DeviceReplay")
• dr.MouseClick x_coord + Offset_x, y_coord +
Offset_y, 2
• Syntax:
• Browser(“Browser”).Page(“Page").Object.documen
tElement.innerHTML
• Example:
• htmlSrc = Browser("Welcome to HP-
GDIC").Page("Welcome: Mercury
Tours").Object.documentElement.innerHTML
• Msgbox htmlSrc
• Example:
• SystemUtil.Run “notepad.exe myfile.txt “