Book Image

Advanced UFT 12 for Test Engineers Cookbook

Book Image

Advanced UFT 12 for Test Engineers Cookbook

Overview of this book

Table of Contents (18 chapters)
Advanced UFT 12 for Test Engineers Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Adding a new method to a class


You can also override an existing TO method and we could actually extend a TO class with new methods. Such custom methods will be registered in the same fashion as those which override the existing ones. For example, if you wish to retrieve the comment property of a TO, use the following code:

Print "username: " & Browser("AdvancedQTP - Overriding").Page("AdvancedQTP - Overriding").WebEdit("username").GetTOProperty("miccommentproperty")

Instead of writing this every time, the best practice would be to create a new method, which passes in the properties of the TO and returns the retrieved value.

How to do it...

Proceed with the following steps:

  1. Open Object Repository in which we previously added the objects from our HTML sample page. Enter the following values (or whichever you choose) to their respective comment fields in the Properties pane:

    WebEdit("username"): Username
    WebEdit("password"): Password123
    WebEdit("email"): [email protected]
    WebEdit("tel"): (01)...