Introduction
The Zee language includes a multitude of app and non-app classes to support the building of manual and automated tests in AscentialTest. These classes provide properties and methods to interact with the application under test and carry out the requirements of software tests. Zee also provides the ability to extend the built-in classes to customize their usage. In this article, we’ll explore both extending and sub-classing of existing classes.
Extending Classes:
Extending a class provides a way to add methods and properties to an existing class. Both regular and app classes can be extended, but properties can only be added to app classes.
To extend a class use the keyword ‘extend’ as in the example below:
In this example, the built-in class ‘TreeView’ has been extended. Methods and/or properties can now be added. In the example below, a new method called ‘SelectPathWithMouse’ has been added to the class:
Any app object of the class ‘TreeView’ will automatically inherit the new method and it will display in the Actions Panel along with the built-in methods:
The new method can be used like any other members of the TreeView class.
Sub-classing:
Creating a sub-class of an existing class provides a way to limit the scope of new methods and properties to only members of the subclass, rather than all the members of the parent class. Sub-classing also provides a way to override methods and properties that are defined in the parent class.
To create a sub-class, use the syntax displayed in example below:
To add or override a method, simply define the method in the new sub-class as shown in the example below:
The Click method defined in the ‘POSButton’ class will get called instead of the one defined in the parent class. Note that the new method includes a call to the original Click method defined in the parent class by using the keyword ‘this’.
The new method will be available only to app objects that are members of the new class, ‘POSButton’, not to all of the members of the parent ‘PushButton’ class. The image below shows how to override the original class with the sub-class:
Members of the new class inherit methods and properties from the parent class except where overridden in the sub-class.
New methods will display in the Actions Panel as described above and can be used like any other members of the parent class.