Qtp Training Deepti 4 Of 4493
Embed Size (px)
DESCRIPTION
Text of Qtp Training Deepti 4 Of 4493
- 1. QTP Training (Advanced) Shanmugadas.C.S Created On: 04-10-2005
2. Agenda
- Summary of Day 3 QTP Advanced Training
- Continuation of Day 3 Demo
- AOM (Automation Object Model)
3. Summary of Day 3
- User Defined Objects & Virtual Objects
4. Continuation of Day 3 Demo
- Exception handling using function calls
- AOM (Automation Object Model)
5. Automation Object Model (Contd.,) 6. Automation Object Model (Contd.,) 7. QTP Utility Functions - Database
- Public Function My_dbquery(ord_no)
- DataConn = "C:Dasoziplibflight32.mdb"
- Set Conn = CreateObject("ADODB.Connection")
- ConStr = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & DataConn & ";"
- SQL = "SELECT Orders.Customer_Name FROM Orders Orders WHERE (Orders.Order_Number=" &ord_no &")"
- Set recordset = Conn.execute(SQL)
- My_Query = recordset("Customer_Name")
8. QTP Utility Functions File Operations
- CreateFile "C:","mytextfile.txt","hi how are you?"
- Public Function CreateFile(filpath,filname,filcontent)
- xml_file = filpath & "" & filname
- Set fileobject = CreateObject("Scripting.FileSystemObject")
- Set tf = fileobject.CreateTextFile(xml_file, True)
9. QTP Utility Functions File Operations
- ' creating the file system object
- set oFSO = CreateObject ("Scripting.FileSystemObject")
- ' *********************************************************************************************
- ' FilePath - location of the file and its name
- ' *********************************************************************************************
- Function CreateFile (FilePath)
- ' varibale that will hold the new file object
- ' create the new text ile
- set NewFile = oFSO.CreateTextFile(FilePath, True)
- ' *********************************************************************************************
- ' Check if a specific file exist
- ' FilePath - location of the file and its name
- ' *********************************************************************************************
10. QTP Utility Functions File Operations
- Function CheckFileExists (FilePath)
- CheckFileExists = oFSO.FileExists(FilePath)
- ' *********************************************************************************************
- ' FileRef - reference to the file
- ' str - data to be written to the file
- ' *********************************************************************************************
- Function WriteToFile (byref FileRef,str)
- ' write str to the text file
- ' *********************************************************************************************
- ' FileRef - reference to the file
- ' *********************************************************************************************
11. QTP Utility Functions File Operations
- Function ReadLineFromFile (byref FileRef)
- ' read line from text file
- ReadLineFromFile = FileRef.ReadLine
- ' *********************************************************************************************
- ' FileRef - reference to the file
- ' *********************************************************************************************
- Function CloseFile (byref FileRef)
- '*********************************************************************************************
- ' Opens a specified file and returns an object that can be used to
- ' read from, write to, or append to the file.
- ' FilePath - location of the file and its name
- ' *********************************************************************************************
12. QTP Utility Functions File Operations
- ' *********************************************************************************************
- Function OpenFile (FilePath,mode)
- ' open the txt file and retunr the File object
- set OpenFile = oFSO.OpenTextFile(FilePath, mode, True)
- ' *********************************************************************************************
- ' FilePathSource - location of the source file and its name
- ' FilePathDest - location of the destination file and its name
- ' *********************************************************************************************
- Sub FileCopy ( FilePathSource,FilePathDest)
- ' copy source file to destination file
- oFSO.CopyFile FilePathSource, FilePathDest
- ' *********************************************************************************************
- ' FilePath - location of the file to be deleted
- ' *********************************************************************************************
- Sub FileDelete ( FilePath)
- ' copy source file to destination file
- oFSO.DeleteFile ( FilePath)
13. QTP Utility Functions File Operations
- ' ************** Example of callingthe file functions **********************
- FilePath1 = "D:empFSOxt1.txt"
- FilePath2 = "D:empFSOxt2.txt"
- FilePathDiff = "D:empFSOxt_diff.txt"
- FilePath = "D:empFSOxt.txt"
- set fold = FolderCreate ( "D:empFSO ew")
- set f = OpenFile(FilePath,8)
- ' = WriteToFile(f,"test line")
- set f = CreateFile(FilePath)
- Fexist= CheckFileExists(FilePath)
- d = WriteToFile(f,"first line")
- d = WriteToFile(f,"second line")
- FileCopy "D:empFSOxt.txt","D:empFSOxt1.txt"
- FileDelete "D:empFSOxt1.txt"
14. QTP Utility Functions Excel Sheet Operations
- Set objExcel = CreateObject("Excel.Application")
- strPathExcel = "C:Documents and SettingsAnandanaDesktopQTPSamplesReading From Excel Sheetsest.xls"
- objExcel.Workbooks.open strPathExcel
- Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
- 'msgbox Trim(objSheet.Cells(i, j).Value)
- DataTable.SetCurrentRow i
- DataTable("SL_No", dtGlobalSheet)=Trim(objSheet.Cells(i, 1).Value)
- DataTable("Name", dtGlobalSheet)=Trim(objSheet.Cell