22
33### Table of Contents
44
5- - [ PageObject] [ 1 ]
6- - [ Parameters] [ 2 ]
7- - [ Examples] [ 3 ]
8- - [ element] [ 4 ]
9- - [ elements] [ 5 ]
10- - [ selector] [ 6 ]
11- - [ Parameters] [ 7 ]
12- - [ Examples] [ 8 ]
13- - [ globalSelector] [ 9 ]
14- - [ Parameters] [ 10 ]
15- - [ Examples] [ 11 ]
16- - [ setRoot] [ 12 ]
17- - [ Parameters] [ 13 ]
5+ * [ PageObject] [ 1 ]
6+ * [ Parameters] [ 2 ]
7+ * [ Examples] [ 3 ]
8+ * [ element] [ 4 ]
9+ * [ elements] [ 5 ]
10+ * [ selector] [ 6 ]
11+ * [ Parameters] [ 7 ]
12+ * [ Examples] [ 8 ]
13+ * [ globalSelector] [ 9 ]
14+ * [ Parameters] [ 10 ]
15+ * [ Examples] [ 11 ]
16+ * [ setRoot] [ 12 ]
17+ * [ Parameters] [ 13 ]
18+ * [ assertExists] [ 14 ]
19+ * [ Parameters] [ 15 ]
20+ * [ Examples] [ 16 ]
21+ * [ getDescription] [ 17 ]
22+ * [ Parameters] [ 18 ]
1823
1924## PageObject
2025
26+ ** Extends ArrayStub**
27+
2128This class implements all the basic page object functionality, and all page
2229objects must inherit from it. It can host [ selector] [ 6 ] and
2330[ globalSelector] [ 9 ] fields, and will properly instantiate them as nested
2431[ PageObject] [ 1 ] s when accessed. Each page object represents a DOM query
25- that matches zero or more [ Element] [ 14 ] s.
32+ that matches zero or more [ Element] [ 19 ] s.
2633
2734[ PageObject] [ 1 ] s exist in a tree where each [ PageObject] [ 1 ] 's elements
2835are descendants of its parent's elements. The root of the tree is a top-level
@@ -53,13 +60,13 @@ they are constructed, but is evaluated and re-evaluated each time a property
5360that depends on it is accessed.
5461
5562[ PageObject] [ 1 ] s expose an API for interacting with their matching
56- elements that comprises [ PageObject#element] [ 15 ] ,
57- [ PageObject#elements] [ 16 ] , and an [ Array] [ 17 ] API that exposes the page
58- object's matching [ Element] [ 14 ] s wrapped in indexed [ PageObject] [ 1 ] s.
63+ elements that comprises [ PageObject#element] [ 20 ] ,
64+ [ PageObject#elements] [ 21 ] , and an [ Array] [ 22 ] API that exposes the page
65+ object's matching [ Element] [ 19 ] s wrapped in indexed [ PageObject] [ 1 ] s.
5966The index operator will return an indexed [ PageObject] [ 1 ] that may or may
6067not match an element (similar to how you can index off the end of a native
6168array and get ` undefined ` ), while various array iteration methods like
62- [ PageObject#map] [ 18 ] generate a range of [ PageObject] [ 1 ] s that reflect
69+ [ PageObject#map] [ 23 ] generate a range of [ PageObject] [ 1 ] s that reflect
6370only the indices that actually match an element.
6471
6572Descendant [ PageObject] [ 1 ] s are defined by subclassing [ PageObject] [ 1 ]
@@ -70,10 +77,10 @@ will match the root element (the body element or whatever was )
7077
7178### Parameters
7279
73- - ` selector ` ** [ string] [ 19 ] ?** the selector to use for this page object's query (optional, default ` '' ` )
74- - ` parent ` (for internal use only) (optional, default ` null ` )
75- - ` index ` (for internal use only) (optional, default ` null ` )
76- - ` rootElement ` (for internal use only) (optional, default ` null ` )
80+ * ` selector ` ** [ string] [ 24 ] ?** the selector to use for this page object's query (optional, default ` '' ` )
81+ * ` parent ` (for internal use only) (optional, default ` null ` )
82+ * ` index ` (for internal use only) (optional, default ` null ` )
83+ * ` rootElement ` (for internal use only) (optional, default ` null ` )
7784
7885### Examples
7986
@@ -110,14 +117,14 @@ matching this page object's query if this page object does not have an
110117index, or the ` index ` th matching DOM element if it does have an index
111118specified.
112119
113- Type: ([ Element] [ 20 ] | null)
120+ Type: ([ Element] [ 25 ] | null)
114121
115122### elements
116123
117124This page object's list of matching DOM elements. If this page object has
118125an index, this property will always have a length of 0 or 1.
119126
120- Type: [ Array] [ 21 ] & lt ; [ Element] [ 20 ] >
127+ Type: [ Array] [ 26 ] < [ Element] [ 25 ] >
121128
122129## selector
123130
@@ -128,8 +135,8 @@ properties and functions.
128135
129136### Parameters
130137
131- - ` selector ` ** [ string] [ 19 ] ** the selector relative to the parent node
132- - ` Class ` ** [ Function] [ 22 ] & lt ; [ PageObject] [ 23 ] >?** optional [ PageObject] [ 1 ] subclass that
138+ * ` selector ` ** [ string] [ 24 ] ** the selector relative to the parent node
139+ * ` Class ` ** [ Function] [ 27 ] < [ PageObject] [ 28 ] >?** optional [ PageObject] [ 1 ] subclass that
133140 can be used to extend the functionality of this page object
134141
135142### Examples
@@ -147,7 +154,7 @@ page.list.elements; // document.body.querySelectorAll('.list')
147154page .list .items .elements ; // document.body.querySelectorAll('.list li')
148155```
149156
150- Returns ** [ PageObject] [ 23 ] ** a [ PageObject] [ 1 ] or [ PageObject] [ 1 ] subclass
157+ Returns ** [ PageObject] [ 28 ] ** a [ PageObject] [ 1 ] or [ PageObject] [ 1 ] subclass
151158instance
152159
153160## globalSelector
@@ -157,7 +164,7 @@ parent page object. Useful for cases like popovers and dropdowns, where the
157164UI control is logically inside a given component, but all or part of it
158165renders elsewhere in the DOM, such as directly under the body.
159166[ globalSelector] [ 9 ] accepts a selector and optional custom class like
160- [ selector()] [ 24 ] , but the queries of the page objects it generates will be
167+ [ selector()] [ 29 ] , but the queries of the page objects it generates will be
161168executed from the root (` document.body ` or whatever was passed to
162169[ setRoot] [ 12 ] ) rather than the parent page object's elements.
163170
@@ -169,9 +176,9 @@ generates.
169176
170177### Parameters
171178
172- - ` args ` ** ...any**
173- - ` selector ` ** [ string] [ 19 ] ** the selector
174- - ` Class ` ** [ Function] [ 22 ] & lt ; [ PageObject] [ 23 ] >** optional [ PageObject] [ 1 ] subclass that
179+ * ` args ` ** ...any**
180+ * ` selector ` ** [ string] [ 24 ] ** the selector
181+ * ` Class ` ** [ Function] [ 27 ] < [ PageObject] [ 28 ] >** optional [ PageObject] [ 1 ] subclass that
175182 can be used to extend the functionality of this page object
176183
177184### Examples
@@ -214,7 +221,7 @@ page.listItems[0].popover; // document.body.querySelectorAll('.popover')
214221page .listItems [0 ].popover .icon ; // document.body.querySelectorAll('.popover .icon')
215222```
216223
217- Returns ** [ PageObject] [ 23 ] ** a [ PageObject] [ 1 ] or [ PageObject] [ 1 ] subclass
224+ Returns ** [ PageObject] [ 28 ] ** a [ PageObject] [ 1 ] or [ PageObject] [ 1 ] subclass
218225instance
219226
220227## setRoot
@@ -225,9 +232,41 @@ element is `document.body`.
225232
226233### Parameters
227234
228- - ` element ` ** ([ Element] [ 20 ] \ | [ Function] [ 22 ] )** the root element or a function that will
235+ * ` element ` ** ([ Element] [ 25 ] | [ Function] [ 27 ] )** the root element or a function that will
229236 return it
230237
238+ ## assertExists
239+
240+ Useful for providing clarity to consumers of page-objects
241+ to provide additional context so "can't access property on undefined"
242+ errors do not public up to the consumer.
243+
244+ In typescript, this is also useful for type-narrowing so that
245+ you can pass on the element to other utilities.
246+
247+ ### Parameters
248+
249+ * ` msg ` ** [ string] [ 24 ] ** a descriptor for what it could mean when the element doesn't exist
250+ * ` pageObject ` ** [ PageObject] [ 28 ] ** the page object
251+
252+ ### Examples
253+
254+ ``` javascript
255+ let page = new Page ();
256+
257+ assertExists (' is the element on the page?' , page);
258+
259+ await click (page .element );
260+ ```
261+
262+ ## getDescription
263+
264+ Utility to get the fully resolved selector path of a [ PageObject] [ 1 ]
265+
266+ ### Parameters
267+
268+ * ` pageObject `
269+
231270[ 1 ] : #pageobject
232271
233272[ 2 ] : #parameters
@@ -254,24 +293,34 @@ element is `document.body`.
254293
255294[ 13 ] : #parameters-3
256295
257- [ 14 ] : https://developer.mozilla.org/docs/Web/API/Element
296+ [ 14 ] : #assertexists
297+
298+ [ 15 ] : #parameters-4
299+
300+ [ 16 ] : #examples-3
301+
302+ [ 17 ] : #getdescription
303+
304+ [ 18 ] : #parameters-5
305+
306+ [ 19 ] : https://developer.mozilla.org/docs/Web/API/Element
258307
259- [ 15 ] : #pageobjectelement
308+ [ 20 ] : #pageobjectelement
260309
261- [ 16 ] : #pageobjectelements
310+ [ 21 ] : #pageobjectelements
262311
263- [ 17 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
312+ [ 22 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
264313
265- [ 18 ] : PageObject#map
314+ [ 23 ] : PageObject#map
266315
267- [ 19 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
316+ [ 24 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
268317
269- [ 20 ] : https://developer.mozilla.org/docs/Web/API/Element
318+ [ 25 ] : https://developer.mozilla.org/docs/Web/API/Element
270319
271- [ 21 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
320+ [ 26 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
272321
273- [ 22 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
322+ [ 27 ] : https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
274323
275- [ 23 ] : #pageobject
324+ [ 28 ] : #pageobject
276325
277- [ 24 ] : selector( )
326+ [ 29 ] : selector\(\ )
0 commit comments