Pages: << 1 ... 14 15 16 17 18 19 ...20 ...21 22 23 24 25
Metadata is similar to annotations in java or attributes in C#. Metadata can be used to mark an object with a value that can be queried at runtime. For example, you can mark all of the app objects in your application with a required field attribute so that a generic test can read the value to determine whether or not to include it in a ‘required field’ test.
Metadata is implemented in Zee as a class. All custom metadata derives from the built-in class Metadata. To add metadata to an AppObject, first create a class as in the example below:
class CustomData : Metadata
String System
Integer Version
Then apply the metadata to your AppObjects and assign values as in the example below. The order of the members inside the square brackets does not matter since field/value pairs are used:
WebPage MyPage
WebTextField MyTextField %CustomData[System="MySystem",Version=3]
In the previous example, each member of the metadata class was assigned using a field/value pair. An alternate way to assign metadata is to list the members in order as in the example below:
WebPage MyPage
WebTextField MyTextField %CustomData["MySystem",3]
To refer to metadata in functions and tests, use the % operator as in the example below:
String SystemName = MyPage.MyTextField.%CustomData.System
It is also possible to create a metadata class without member elements as in the example below. In this case the value of the metadata will be false if it is not assigned to an AppObject. Otherwise it will return true.
class ObsoleteIndicator : Metadata
WebPage MyPage
WebTextField MyTextField %ObsoleteIndicator
WebTextField MyTextField2
Print (MyPage.MyTextField.%ObsoleteIndicator)
//Prints true
Print (MyPage.MyTextField2.%ObsoleteIndicator)
//Prints false
Here are some notes to enhance your understanding of Metadata: