UNPKG

@lariat/playwright

Version:

Page object framework for end-to-end testing in Playwright.

88 lines (82 loc) 2.87 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { default: () => src_default }); module.exports = __toCommonJS(src_exports); // src/enhance.ts function enhance(collection, root, instance) { const inst = instance; inst.nth = (index) => new collection(root.nth(index)); inst.first = () => inst.nth(0); inst.last = () => inst.nth(-1); return inst; } // src/utils.ts var isLocator = (handle) => "_frame" in handle; // src/Collection.ts var Collection = class { constructor(root) { this.root = root; this.getByAltText = this.enhanceMethod("getByAltText"); this.getByLabel = this.enhanceMethod("getByLabel"); this.getByPlaceholder = this.enhanceMethod("getByPlaceholder"); this.getByRole = this.enhanceMethod("getByRole"); this.getByTestId = this.enhanceMethod("getByTestId"); this.getByText = this.enhanceMethod("getByText"); this.getByTitle = this.enhanceMethod("getByTitle"); } getByAltText; getByLabel; getByPlaceholder; getByRole; getByTestId; getByText; getByTitle; el(selector, { frame, portal, ...options } = {}) { return this.getParent(frame, portal).locator(selector, options); } nest(collection, root) { const rootElement = typeof root === "string" ? this.el(root) : root; const instance = new collection(rootElement); return isLocator(rootElement) ? enhance(collection, rootElement, instance) : instance; } get frame() { return isLocator(this.root) ? this.root._frame : "mainFrame" in this.root ? this.root.mainFrame() : this.root; } get page() { return this.frame.page(); } getParent(frame, portal = false) { const root = portal ? this.frame : this.root; return frame ? root.frameLocator(frame) : root; } enhanceMethod(method) { const enhanced = (arg, { frame, portal, ...options } = {}) => { return this.getParent(frame, portal)[method](arg, options); }; return enhanced; } }; // src/index.ts var src_default = Collection; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = {});