Qtp Training Deepti 4 Of 4493

  • Published on
    14-Jan-2015

  • View
    2.875

  • Download
    0

Embed Size (px)

DESCRIPTION

 

Transcript

  • 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
    • Exception handling
    • Descriptive programming
    • Check point
    • AOM (Automation Object Model)
  • QTP Utility Functions

3. Summary of Day 3

  • Object Identification
  • Synchronization Points
  • Exception Handling
  • User Defined Objects & Virtual Objects
  • Actions
  • Parameterization

4. Continuation of Day 3 Demo

  • Demo on
    • Exception handling using function calls
    • Descriptive Programming
    • Check points
    • AOM (Automation Object Model)

5. Automation Object Model (Contd.,) 6. Automation Object Model (Contd.,) 7. QTP Utility Functions - Database

  • msgbox My_dbquery(10)
  • Dim My_Query, MyDesc
  • Public Function My_dbquery(ord_no)
  • DataConn = "C:Dasoziplibflight32.mdb"
  • Set Conn = CreateObject("ADODB.Connection")
  • ConStr = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & DataConn & ";"
  • Conn.open(ConStr)
  • SQL = "SELECT Orders.Customer_Name FROM Orders Orders WHERE (Orders.Order_Number=" &ord_no &")"
  • Set recordset = Conn.execute(SQL)
  • while not recordset.EOF
  • My_Query = recordset("Customer_Name")
  • recordset.movenext
  • wend
  • recordset.close
  • Conn.Close
  • set recordset = Nothing
  • Set Conn = Nothing
  • My_dbquery = My_Query
  • End Function

8. QTP Utility Functions File Operations

  • File Creation
  • CreateFile "C:","mytextfile.txt","hi how are you?"
  • Public Function CreateFile(filpath,filname,filcontent)
  • xml_file = filpath & "" & filname
  • Dim fileobject, tf
  • Set fileobject = CreateObject("Scripting.FileSystemObject")
  • Set tf = fileobject.CreateTextFile(xml_file, True)
  • tf.Write (filcontent)
  • tf.Close
  • End Function

9. QTP Utility Functions File Operations

  • dim oFSO
  • ' creating the file system object
  • set oFSO = CreateObject ("Scripting.FileSystemObject")
  • 'Option Explicit
  • ' *********************************************************************************************
  • ' Create a new txt file
  • ' Parameters:
  • ' FilePath - location of the file and its name
  • ' *********************************************************************************************
  • Function CreateFile (FilePath)
  • ' varibale that will hold the new file object
  • dim NewFile
  • ' create the new text ile
  • set NewFile = oFSO.CreateTextFile(FilePath, True)
  • set CreateFile = NewFile
  • End Function
  • ' *********************************************************************************************
  • ' Check if a specific file exist
  • ' Parameters:
  • ' FilePath - location of the file and its name
  • ' *********************************************************************************************

10. QTP Utility Functions File Operations

  • Function CheckFileExists (FilePath)
  • ' check if file exist
  • CheckFileExists = oFSO.FileExists(FilePath)
  • End Function
  • ' *********************************************************************************************
  • ' Write data to file
  • ' Parameters:
  • ' 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.WriteLine(str)
  • End Function
  • ' *********************************************************************************************
  • ' Read line from file
  • ' Parameters:
  • ' FileRef - reference to the file
  • ' *********************************************************************************************

11. QTP Utility Functions File Operations

  • Function ReadLineFromFile (byref FileRef)
  • ' read line from text file
  • ReadLineFromFile = FileRef.ReadLine
  • End Function
  • ' *********************************************************************************************
  • ' Closes an open file.
  • ' Parameters:
  • ' FileRef - reference to the file
  • ' *********************************************************************************************
  • Function CloseFile (byref FileRef)
  • FileRef.close
  • End Function
  • '*********************************************************************************************
  • ' Opens a specified file and returns an object that can be used to
  • ' read from, write to, or append to the file.
  • ' Parameters:
  • ' FilePath - location of the file and its name
  • ' mode options are:
  • ' ForReading - 1
  • ' ForWriting - 2
  • ' ForAppending - 8
  • ' *********************************************************************************************

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)
  • End Function
  • ' *********************************************************************************************
  • ' Closes an open file.
  • ' Parameters:
  • ' 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
  • End Sub
  • ' *********************************************************************************************
  • ' Delete a file.
  • ' Parameters:
  • ' FilePath - location of the file to be deleted
  • ' *********************************************************************************************
  • Sub FileDelete ( FilePath)
  • ' copy source file to destination file
  • oFSO.DeleteFile ( FilePath)
  • End Sub

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")
  • d = CloseFile(f)
  • set f = CreateFile(FilePath)
  • Fexist= CheckFileExists(FilePath)
  • d = WriteToFile(f,"first line")
  • d = WriteToFile(f,"second line")
  • d = CloseFile(f)
  • 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)
  • 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.Cell