@@ -3,32 +3,46 @@ import { enhance, NestedCollection } from './enhance'
33import { Handle , isLocator } from './utils'
44
55export interface ElementOptions {
6+ /**
7+ * When true, the locator will be based off the `frame`, rather than the
8+ * `root` thus escaping from any collection nesting. This is useful to
9+ * represent a page structure whose visual appearance differs from it's
10+ * DOM structure.
11+ *
12+ * @default false
13+ */
614 portal ?: boolean
15+ /**
16+ * When defined, creates a frame locator which the element will be nested
17+ * inside of.
18+ */
719 frame ?: string
20+ /**
21+ * Matches elements containing specified text somewhere inside, possibly in a
22+ * child or a descendant element.
23+ */
24+ hasText ?: string | RegExp
825}
926
1027export class Collection < T extends Handle = Locator > {
1128 constructor ( public root : T ) { }
1229
1330 /**
1431 * Retrieve a locator to a given element on the page identified by the
15- * selector. The locator is lazily initialized when retrieved to ensure that
16- * the most current `root` element is used.
17- *
18- * If `options.portal` is set to true, the locator will be based off the
19- * `frame`, rather than the `root` thus escaping from any collection nesting.
20- * This is useful to represent a page structure whose visual appearance
21- * differs from it's DOM structure.
32+ * selector.
2233 *
2334 * @param selector - The selector that identifies the element.
2435 * @param options - Options for how to build the locator.
2536 */
26- protected el ( selector : string , options ?: ElementOptions ) : Locator {
27- const root = options ?. portal ? this . frame : this . root
37+ protected el (
38+ selector : string ,
39+ { portal, frame, hasText } : ElementOptions = { }
40+ ) : Locator {
41+ const root = portal ? this . frame : this . root
2842
29- return options ?. frame
30- ? root . frameLocator ( options . frame ) . locator ( selector )
31- : root . locator ( selector )
43+ return frame
44+ ? root . frameLocator ( frame ) . locator ( selector , { hasText } )
45+ : root . locator ( selector , { hasText } )
3246 }
3347
3448 /**
0 commit comments