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

Implementing a class


In this recipe, you will learn the following:

  • The basic concepts and the syntax required by VBScript to implement a class

  • The different components of a class and interoperation

  • How to implement a type of generic constructor function for VBScript classes

  • How to use a class during runtime

Getting ready

From the File menu, navigate to New | Function Library…, or use the Alt + Shift + N shortcut. Name the new function library cls.MyFirstClass.vbs and associate it with your test.

How to do it...

We will build our MyFirstClass class from the ground up. There are several steps one must follow to implement a class; they are follows:

  1. Define the class as follows:

    Class MyFirstClass
  2. Next, we define the class fields. Fields are like regular variables, but encapsulated within the namespace defined by the class. The fields can be private or public. A private field can be accessed only by class members. A public field can be accessed from any block of code. The code is as follows:

    Class MyFirstClass...