html5-img
1 / 46

Advanced QTP

Advanced QTP . Objectives. Object Model Reference. An object model is a structural representation of software objects (classes) that comprise the implementation of a system or application

shea
Download Presentation

Advanced QTP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced QTP

  2. Objectives

  3. Object Model Reference • An object model is a structural representation of software objects (classes) that comprise the implementation of a system or application • An object model defines a set of classes and interfaces, together with their properties, methods and events, and their relationships

  4. What is Quick test automation object model? • It is a model to represent a real time objects which are there in the application. • We can use the objects, its methods and properties to customize our testing needs

  5. Example • In Esupport, to access the user name box the hierarchy is Browser(“satyam virtual universe”).page(“satyam virtual unirverse”).webedit(txtusername)

  6. Web Objects • Browser- The Web browser. The name of the Browser test object is the same as the first recorded Page object • Page - An HTML page • Webedit - An edit box, usually contained inside a form • Webbutton - An HTML button. • Webcheckbox - A check box with an ON and OFF state. • WebTable - A table containing a variable number of rows and columns

  7. Some examples on web objects • Login to the esupport and viewing the leave balance • Login to the esupport and opening the power on to view the current status

  8. Windows objects • Dialog – A Windows dialog box • Window – A standard window. • WinEdit – A Windows edit box. • WinCheckBox - A Windows check box • WinEdit - A Windows edit box • WinButton - A Windows button.

  9. Utility objects • QuickTest reserved objects can be used for testing and result reporting preferences during a run session.

  10. Crypt Object DataTable Object Description Object DotNetFactory Object DTParameter Object DTSheet Object Environment Object Extern Object LocalParameter Object MercuryTimers Object (Collection) MercuryTimer Object Parameter Object PathFinder Object Properties Object (Collection) QCUtil Object RandomNumber Object Recovery Object Reporter Object Repository Object Services Object Setting Object TSLTest Object XMLUtil Object Utility objects

  11. Description object “Description” - Creates a new, empty description object in which you can add collection of properties and values in order to specify the description object in place of a test object name in a step.

  12. Example set EditDesc = Description.Create() EditDesc("Name").Value = "userName" EditDesc("Index").Value = "0" Browser("Welcome: Mercury").Page("Welcome: Mercury").WebEdit(EditDesc).Set "MyName”

  13. Crypt Object • Encrypts a string Syntax Crypt.Encrypt(value) Example x = "mercury" msgbox Crypt.Encrypt(x)

  14. Dynamic objects • Programmatic descriptions enable us to create temporary versions of test objects to represent objects from our application. • We can perform operations on those objects without referring to the object repository. • For example, suppose an edit box was added to a form on your Web site. You could use a programmatic description to add a statement in a user-defined function that enters a value in the new edit box, so that QuickTest can identify the object even though you never recorded on the object or added it to the object repository

  15. Syntax • TestObject("PropertyName1:=PropertyValue1", "..." , "PropertyNameX:=PropertyValueX") • TestObject—the test object class. • PropertyName:=PropertyValue—the test object property and its value. Each property:=value pair should be separated by commas and quotation marks

  16. Example • Browser("Mercury Tours").Page("Mercury Tours").WebEdit("Name:=Author", "Index:=3").Set "Mark Twain” • Window("Text:=Myfile.txt - Notepad").Move 50, 50 Window("Text:=Myfile.txt -Notepad").WinEdit("AttachedText:=Find what:").Set "hello" Window("Text:=Myfile.txt - Notepad").WinButton("Caption:=Find next").Click

  17. File system objects The FileSystemObject (FSO) object model allows us to use the familiar object.method syntax with a rich set of properties, methods, and events to process folders and files.

  18. Creating file system object Dim fso Set fso = CreateObject("Scripting.FileSystemObject")

  19. File operations Dim fso, f1 Set fso = CreateObject("Scripting.FileSystemObject") Set f1 = fso.CreateTextFile("c:\testfile.txt", True) Set f1 = fso.opentextfile("C:\test",2) ‘1 – Reading , 2 – Writing, 9 - Appending f1.writeline "hai you are good"

  20. Copying file Dim fso Set fso = createobject("Scripting.FileSystemObject") fso.copyfile "C:\test","C:\test1“ ‘copyfile source,destination,true or false ‘true – if file exists, overwrites ‘false – if file exists, does not copy

  21. Add Method (Dictionary) Add Method (Folders) BuildPath Method Close Method Copy Method CopyFile Method CopyFolder Method CreateFolder Method CreateTextFile Method Delete Method DeleteFile Method DeleteFolder Method DrivesExists Method Exists Method FileExists Method FolderExists Method GetAbsolutePathName Method GetBaseName Method GetDrive Method GetDriveName Method GetExtensionName Method GetFile Method GetFileName Method GetFileVersion Method GetFolder Method GetParentFolderName Method GetSpecialFolder Method Methods

  22. GetTempName Method Items Method Keys Method Move Method MoveFile Method MoveFolder Method OpenAsTextStream Method OpenTextFile Method Read Method ReadAll Method ReadLine Method Remove Method RemoveAll Method Skip Method SkipLine Write Method WriteBlankLines Method WriteLine Method Methods

  23. Demo on file system • Counting no of lines in a file • File existence check • Comparing text files

  24. RegisterUserFunc utility • Enables us to add new methods to test objects or change the behavior of an existing test object method during a run session • When we use this statement, QuickTest uses our user-defined function as a method of a specified test object class for the remainder of a run session, or until we unregister the method.

  25. Syntax • RegisterUserFuncTOClass, MethodName, FunctionName, SetAsDefault

  26. Example • The following example uses the RegisterUserFunc method to create a new Copy method for the WinEdit test object that copies all the text in an edit box to the Windows Clipboard. • Sub Copy (edit)        Edit.Click 3, 3        Edit.SetSelection 0, Len(Edit.GetROProperty("text"))        Edit.Type micCtrlDwn + "c" + micCtrlUp End Sub RegisterUserFunc "WinEdit", "Copy", "Copy" ' Now you can call the new method Dialog("Login").WinEdit("Agent Name:").Copy

  27. Working with API functions • Extern object – It enables us to declare calls to external procedures from an external dynamic-link library (DLL). • Declare Method - Declares references to external procedures in a dynamic-link library (DLL). • Once we use the Declare method for a method, we can use the Extern object to call the declared method

  28. Syntax • Extern.Declare(RetType, MethodName, LibName, Alias [, ArgType(s)])

  29. Example 'Declare FindWindow method Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString 'Declare SetWindowText method Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString 'Get HWND of the Notepad window hwnd = Extern.FindWindow("Notepad", vbNullString) if hwnd = 0 then MsgBox "Notepad window not found" end if 'Change the title of the notepad window res = Extern.SetWindowText(hwnd, "kuku")

  30. Working with outlook express • QuickTest Professional does not have special support for the Outlook application, so there is no built-in method that will locate an e-mail and allow you to view the attachments. • However, Microsoft does have an Object Model for Outlook that can be used to automate many of the features. • You can refer to "Microsoft Outlook 2000 Object Model" for a complete listing of Outlook methods and properties that can be used within a QuickTest Professional (QTP) script.

  31. How to open outlook thru QTP? Set myOlApp = CreateObject("Outlook.Application") ‘to create an object Set myNameSpace = myOlApp.GetNameSpace("MAPI") ‘to create an name space Set myFolder= myNameSpace.GetDefaultFolder(6) ‘to open inbox (inbox is the sixth folder) myFolder.Display

  32. Outlook methods • Items.count - To display the total mails in the Inbox Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNameSpace("MAPI") Set myFolder= _ myNameSpace.GetDefaultFolder(6) myFolder.Display msgbox myfolder.items.count

  33. Sending Mails Set myOlApp = CreateObject("Outlook.Application") ‘ to create object for outlook Set mail = myOlApp.CreateItem(0) ‘to click on the new message mail.to = "chandrasekar_venkata“ ‘to edit the mail id mail.body = "Hai user, Welcome“ ‘to edit the subject mail.display ‘to display the outlook mail.send ‘to send the mail

  34. Displaying how many unread mails are there Set myOlApp = CreateObject("Outlook.Application") Set myNameSpace = myOlApp.GetNameSpace("MAPI") Set myFolder= myNameSpace.GetDefaultFolder(6) myFolder.Display msgbox myFolder.UnReadItemCount ‘for displaying how many items are unread till now

  35. Working with Excel • Opening workbook • Opening worksheets • Reading data from Excel sheet • Writing data to Excel sheet • Saving data to Excel sheet

  36. Opening workbook Set xl = CreateObject("Excel.Application") ‘to create object for the excel object xl.workbooks.open "c:\template.xls“ ‘to open file

  37. Opening worksheets Set xl = CreateObject("Excel.Application") xl.workbooks.open "c:\template.xls“ xl.sheets("sheet1").activate

  38. Reading data from Excel Set xl = CreateObject("Excel.Application") xl.workbooks.open "c:\template.xls“ xl.sheets("sheet1").activate msgbox xl.sheets("sheet1").cells(2,2) xl.quit

  39. Writing data to Excel Set xl = CreateObject("Excel.Application") xl.workbooks.open "c:\template.xls“ xl.sheets("sheet1").activate xl.sheets("sheet1").cells(2,2) = "mercury123"

  40. Saving file Set xl = CreateObject("Excel.Application") xl.workbooks.open "c:\template.xls“ xl.sheets("sheet1").activate xl.sheets("sheet1").cells(2,2) = "mercury123“ xl.Save xl.quit

  41. Working with XML object QuickTest provides several scripting methods that we can use with XML data. We can use these scripting methods to retrieve data and return new XML objects from existing XML data.

  42. XMLUtil The object used to access and return XML objects. Syntax Set Object = XMLUtil.CreateXML()

  43. Loading XML file Set XMLObj = XMLUtil.CreateXML() XMLObj.LoadFile("C:\XML\BookStore.xml")

  44. Example Code for replacing the value in XML file using XML Object: Set doc = XMLUtil.CreateXML() doc.LoadFile "C:\Documents and Settings\ss21189\Desktop\mails.xml" Set root = doc.GetRootElement() Set children = root.ChildElements() if children.Count() <> 0 then Set firstChild = children.Item(1) firstChildName = firstChild.ElementName() Set sameNameChildren = children.AllItemsByName(firstChildName) msg = "My first child name is " + firstChildName + " and I have " + FormatNumber(sameNameChildren.Count(),0) + " of them." End If msgbox msg set firstChild=root.ChildElements().Item(2)

  45. Example Set child2 = firstChild.ChildElements().Item(2) Msgbox child2.Value() child2.SetValue("replacement") firstChild.AddChildElementByName "Value", "replacement" Dim fso, MyFile Set fso = CreateObject("Scripting.FileSystemObject") Set MyFile = fso.OpenTextFile("C:\Documents and Settings\ss21189\Desktop\mails.xml") MsgBox MyFile.ReadAll MyFile.Close

  46. Summary • Object Model Reference • Utility objects • Dynamic objects • File system • Registering user defined functions • Working with Win32 API functions • Working with outlook object • Working with Excel application • Working with XML application

More Related