QTP Functions

16

description

QTP Functions

Transcript of QTP Functions

Page 1: QTP Functions
Page 2: QTP Functions

Why User Defined Functions? Working with User Defined Functions

Associated to a test object Global

Functions Scope Private Public

Using the Function definition Generator Function Definition Registering Function Documenting function

Adding function to Expert View RegisterUserFunc Calling the registered function Session Wrap-Up

pgorantla.blogspot.com

QTP Functions

Page 3: QTP Functions

A user-defined function encapsulates activities or steps that require programming into operations (or keywords). These operations can then be used to enhance your test or component.

User defined functions helps in: maintaining the modularity of the code

Reusability

pgorantla.blogspot.com

Page 4: QTP Functions

QTP allows creating two types of user defined functions Associated to a test object

Global

Associated to a test object QTP allows to register a function and associate with a test object. It

is also possible to set that operation as the default operation for the selected test object.

Global When a function is not associated with any test object, then it is

termed as Global Functions. Global functions can be called by selecting the Functions category in the Step Generator (Can be invoked from Insert -> Step -> Step Generator)

pgorantla.blogspot.com

Page 5: QTP Functions

Public: Public functions are those which can be called

/accessed from multiple tests or components. To make a function public, the function should be defined and saved in the function library file.

Private: Private functions are those that are defined in

that action using the Expert View. Such functions cannot be called from another action.

pgorantla.blogspot.com

Page 6: QTP Functions

Quick Test provides a Function Definition Generator, which enables to generate definitions for new user-defined functions and add header information to them.

It also facilitates in the Function Definition Generator to register a function to a test object.

After filling the required information, the Function Definition Generator creates the basic function definition for the user.

The function definition can be then copied to a library file and associate it with the test or component of the definition can be directly copied to a test script.

The Function Definition Generator can be invoked from Start -> Programs -> QuickTest Professional -> Tools -> Function Definition Generator.

pgorantla.blogspot.com

Note:• If you are planning to register functions, before you open the Function Definition Generator for the first time, make

sure that you open QuickTest at least once. This enables the Function Definition Generator to access all of the test objects and their operations.

Page 7: QTP Functions

The Function Definition section allows to define the function name and arguments.

Parts of Function Definition Name

Name of the function to be specified Type

Function - returns value to the calling function Sub - Doesn’t return value to the calling function

Scope Either Public or Private

Arguments Click on icon to add a new argument Click on icon to delete an argument Click on the to change the order of the arguments

pgorantla.blogspot.com

Note:• If you create a user-defined function manually and do not define the scope as Public or Private, it will be treated as a

public function, by default.• Only public functions can be registered to a test object.

Page 8: QTP Functions

Parts of Registering Function

The Register to a test object frame allows the user to register the function with a test object. This option is available only for public functions.

Test Object includes all available test objects (i.e., ActiveX Object, Standard Windows Object, Web Objects etc.,

)

Operation contains the corresponding operations for the selected test object The user can either type in a new operation name in order to

create a new operation or select an existing operation to overwrite.

Check the option ‘Register as default operation’ to make the selected operation as default

pgorantla.blogspot.com

Page 9: QTP Functions

The below screen shows that a new function with name ‘verify’ has been created and it has been associated to a test object ‘WebEdit’ and with the operation ‘Verify’.

Since, the option ‘Register to a test object’ is selected, the RegisterUserFunc statement is added to the end of the Function line. pgorantla.blogspot.com

Page 10: QTP Functions

The Additional Information tab is used to enter some useful information about the function.

It is also possible to enter the test object name and type in the Documentation field.

The test object name and type can be selected by clicking on the arrow beside the documentation field.

pgorantla.blogspot.com

Clicking on this arrow will popup to add test object type and test object name

Page 11: QTP Functions

After entering the sufficient information in the Function Definition Generator, Click on the ‘Copy’ button to copy the syntax.

In the Expert view, choose paste to the paste the function definition.

The function looks like below when pasted to the Expert view.

pgorantla.blogspot.com

The function related code goes here

Page 12: QTP Functions

Syntax RegisterUserFunc TOClass, MethodName, FunctionName,

SetAsDefault

Description

For example: RegisterUserFunc “WebEdit”, “verify”, “verify”, true

Argument Type Description

TOClass String The tests object class for which you want to register

the method.

MethodName String The method you want to register.

FunctionName String

The name of your user-defined function. The function can be located in your action or component, or in any library file associated with your test or component.

SetAsDefault Boolean Indicates whether the registered function is used as

the default method for the test object.

pgorantla.blogspot.com

Function Name

Operation Name

Test Object Name

Page 13: QTP Functions

Invoke the Step Generator to add a new step.

Select the category as ‘Test Objects’

Select a WebEdit object as the function that is created is for the ‘WebEdit’ Objects. Here, in this window, the ‘PassFirst0’ web edit object is selected.

By default, the newly created operation ‘Verify’ is selected as the operation was set as the default operation at the time of creation.

If it is not set as the default operation, the user has to select from the list of operations

pgorantla.blogspot.com

Page 14: QTP Functions

pgorantla.blogspot.com

Prep Session Introduction

ATS Application Testing

Q & A….

Page 15: QTP Functions

User defined functions can be created using Function Definition Generator or by directly typing the function header in Expert View.

Scope of Functions are of two types: Public Private

Two types of user defined functions can be created: Associated to a test object Global

Only public functions can be registered to a test object.

Any number of arguments can be created for a function. pgorantla.blogspot.com

Page 16: QTP Functions

If a function is associated with a test object, then the first argument should be the test object name.

If a particular method is set as the default operation, then in keyword view, dropping down the operation combo shows the newly created method.

It is possible to register any method using RegisterUserFunc statement.

It is possible to enter function headers using Function Definition Generator.

pgorantla.blogspot.com