Page Object Root
Any page object that is unique inside the current browser view can be used as a root. A root page object can be loaded directly inside the browser.
Root Properties
The root of a page object can contain these properties:
elements
(Optional) Array. A nested tree of element objects. An element object can be one of these types:- Basic element—A UI element required for user interaction or to scope another element.
- Custom element—A nested page object.
- Container element—A
slot
ordiv
into which other components are injected.
methods
(Optional) Array. Each object declares a public method. The only supported method type iscompose
. A compose method combines several element actions, like clearing a text field (clear
) and entering a value (setText
).root
(Optional) Boolean. To load a page object from a test, setroot
totrue
and add aselector
element that points to its most outer (root) element. If a component can be loaded only inside its immediate parent (for example, a navigation item can be loaded only inside a navigation bar), don’t mark it asroot
.selector
(Optional) Object. Ifroot
istrue
, add aselector
that points to its most outer (root) element. The root selector must match the HTML tag name. See selector.shadow
(Optional) Object. A shadow boundary at the root of the page object. Contains only anelements
property, which is a nested tree of objects. A page object can haveelements
scoped both inside and outside its shadow root.exposeRootElement
(Optional) Boolean. See Actionable Root.type
(Optional) String. See Actionable Root.description
(Optional) String or Object. See Page Object Description.metadata
(Optional) Object. See Page Object Metadata.platform
(Optional) String. See Platform Context.beforeLoad
(Optional) Array. See beforeLoad.
Here's a sample outline of a page object.
{
"elements": [],
"methods": [],
"shadow": {
"elements": []
},
"root": true,
"selector": {
"css": "one-record-home"
}
}
Actionable Root Element
To make the root element actionable, expose it via a public method. Add these properties to the root element:
exposeRootElement
Boolean. If set totrue
, UTAM creates a public method that returns an instance of the element with the given type. The name of the getter isgetRoot
.type
(Optional) See basic element types.
{
"exposeRootElement": true,
"type": ["editable"],
"elements": [],
"methods": []
}
The UTAM generator converts this JSON into a public method. The method returns an instance of the page object root element for the test to interact with.
async getRoot() {
const driver = this.driver;
const root = await this.getRootElement();
return new _EditableUtamElement(driver, root);
}
Note: The word
root
is reserved and can't be used as an element name.