advanced qtp n.
Download
Skip this Video
Download Presentation
Advanced QTP

Loading in 2 Seconds...

play fullscreen
1 / 46

Advanced QTP - PowerPoint PPT Presentation


  • 218 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Advanced QTP' - shea


Download Now 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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
object model reference
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
what is quick test automation object model
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
example
Example
  • In Esupport, to access the user name box the hierarchy is

Browser(“satyam virtual universe”).page(“satyam virtual unirverse”).webedit(txtusername)

web objects
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
some examples on web objects
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
windows objects
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.
utility objects
Utility objects
  • QuickTest reserved objects can be used for testing and result reporting preferences during a run session.
utility objects1
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
description object
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.

example1
Example

set EditDesc = Description.Create()

EditDesc("Name").Value = "userName"

EditDesc("Index").Value = "0"

Browser("Welcome: Mercury").Page("Welcome: Mercury").WebEdit(EditDesc).Set "MyName”

crypt object
Crypt Object
  • Encrypts a string

Syntax

Crypt.Encrypt(value)

Example

x = "mercury"

msgbox Crypt.Encrypt(x)

dynamic objects
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
syntax
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
example2
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

file system objects
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.

creating file system object
Creating file system object

Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")

file operations
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"

copying file
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

methods
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
methods1
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
demo on file system
Demo on file system
  • Counting no of lines in a file
  • File existence check
  • Comparing text files
registeruserfunc utility
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.
syntax1
Syntax
  • RegisterUserFuncTOClass, MethodName, FunctionName, SetAsDefault
example3
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

working with api functions
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
syntax2
Syntax
  • Extern.Declare(RetType, MethodName, LibName, Alias [, ArgType(s)])
example4
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")

working with outlook express
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.
how to open outlook thru qtp
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

outlook methods
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

sending mails
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

displaying how many unread mails are there
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

working with excel
Working with Excel
  • Opening workbook
  • Opening worksheets
  • Reading data from Excel sheet
  • Writing data to Excel sheet
  • Saving data to Excel sheet
opening workbook
Opening workbook

Set xl = CreateObject("Excel.Application")

‘to create object for the excel object

xl.workbooks.open "c:\template.xls“

‘to open file

opening worksheets
Opening worksheets

Set xl = CreateObject("Excel.Application")

xl.workbooks.open "c:\template.xls“

xl.sheets("sheet1").activate

reading data from excel
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

writing data to excel
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"

saving file
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

working with xml object
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.

xmlutil
XMLUtil

The object used to access and return XML objects.

Syntax

Set Object = XMLUtil.CreateXML()

loading xml file
Loading XML file

Set XMLObj = XMLUtil.CreateXML()

XMLObj.LoadFile("C:\XML\BookStore.xml")

example5
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)

example6
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

summary
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