'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var leftest = require('@antischematic/leftest'); var test = require('@playwright/test'); var _a; // import process from "node:process" class PlaywrightTestSuiteAdapter { suite(name, impl, flag) { switch (flag) { case leftest.Flag.SKIP: test.test.describe.skip(name, impl); break; case leftest.Flag.ONLY: test.test.describe.only(name, impl); break; case leftest.Flag.DEFAULT: test.test.describe(name, impl); } } test(name, impl, metadata) { this.decorateFunction(impl, name, [...metadata.steps, ...metadata.beforeScenario, ...metadata.afterScenario, ...metadata.beforeStep, ...metadata.afterStep]); switch (metadata.flag) { case leftest.Flag.SKIP: this._test.skip(name, impl); break; case leftest.Flag.ONLY: this._test.only(name, impl); break; case leftest.Flag.DEFAULT: this._test(name, impl); } } afterScenario(impl, metadata) { return this._test.step('After Scenario', impl); } afterStep(impl, metadata) { return this._test.step('After Step', impl); } beforeScenario(impl, metadata) { return this._test.step('Before Scenario', impl); } beforeStep(impl, metadata) { return this._test.step('Before Step', impl); } step(name, description, impl) { return this._test.step(`${name} ${description}`, impl); } decorateFunction(fn, name, steps) { const fixtures = this.getFixtures(steps); const argString = `{ ${fixtures.join(', ')} }`; fn.toString = () => { return `async function test(${argString}) { [scenario: ${name}] }`; }; } parseFixtures(step) { const body = step.toString().replace(/(\r\n|\n|\r)/gm, ""); const arg = body.match(/{.*?}/); const argString = arg ? arg[0] : ""; const fakeFunction = new Function(`return function (_arg) { let ${argString} = _arg }`)(); const fixtures = []; const proxy = new Proxy({}, { get(target, p) { fixtures.push(p); } }); fakeFunction(proxy); return fixtures; } getFixtures(steps) { return Array.from(new Set(steps.flatMap((step) => this.parseFixtures(step)))); } constructor(_test) { this._test = _test; this.isAsync = true; } } function bindHook(register, filter, fn) { const hook = (fn || filter); function cb(scenario) { return hook(this, scenario); } cb.toString = () => hook.toString(); if (fn) { register(filter, cb); } else { register(cb); } } function beforeScenario(filter, fn) { bindHook(leftest.beforeScenario, filter, fn); } function beforeStep(filter, fn) { bindHook(leftest.beforeStep, filter, fn); } function afterScenario(filter, fn) { bindHook(leftest.afterScenario, filter, fn); } function afterStep(filter, fn) { bindHook(leftest.afterStep, filter, fn); } const createSteps = (steps) => { const mapped = {}; for (const key in steps) { mapped[key] = function (...args) { return steps[key](this, ...args); }; mapped[key].toString = () => steps[key].toString(); } return mapped; }; function extendTest(test) { leftest.setAdapter(new PlaywrightTestSuiteAdapter(test)); return createSteps; } leftest.setAdapter(new PlaywrightTestSuiteAdapter(test.test)); leftest.setTags((_a = process.env["LEFTEST_TAGS"]) !== null && _a !== void 0 ? _a : ""); /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __classPrivateFieldGet(receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); } function __classPrivateFieldSet(receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; } typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { var e = new Error(message); return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; }; /** * @file * These functions run inside the browser via playwright's `evaluate` functions. * * Every function has to be pure. They cannot have any dependencies, not even to * other functions in this file. */ /** * Gets text of element excluding certain selectors within the element. * * @param {Element} element Element to get text from, * @param {string} excludeSelector Selector identifying which elements to exclude * @internal * @returns {string} */ function getTextWithExcludedElements(element, excludeSelector) { var _a, _b, _c; const clone = /** @type {Element} */ (element.cloneNode(true)); for (const child of Array.from(clone.querySelectorAll(excludeSelector))) { (_a = child.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(child); } // Fallback to textContent for SVG elements return ( /** @type {Element & Partial} */ (_c = (_b = clone.innerText) !== null && _b !== void 0 ? _b : clone.textContent) !== null && _c !== void 0 ? _c : ''); } /** * Blurs the given element * @param {HTMLElement | SVGElement} element Element to blur * @internal */ function blur(element) { element.blur(); } /** * Check whether the given element matches the given selector * * @param {Element} element Element to match * @param {string} selector Selector to match the element against * @returns {boolean} Whether the element matches the selector * @internal */ function matches(element, selector) { return element.matches(selector); } /** * Returns the dimensions of the given element * * @param {Element} element The element for which to get the dimensions * @returns {import('@angular/cdk/testing').ElementDimensions} The dimensions of the element * @internal */ function getBoundingClientRect(element) { const { left, top, width, height } = element.getBoundingClientRect(); return { left, top, width, height }; } /** * Returns the computed value for the given style property on the given element * * @param {Element} element The element for which to get the style property * @param {string} styleProperty The style property to get * @returns {string} The value for the style property */ function getStyleProperty(element, styleProperty) { return getComputedStyle(element).getPropertyValue(styleProperty); } /** * * @param {Element} element * @param {[string, Record]} event * @returns {void} */ function dispatchEvent(element, [name, properties]) { const _a = properties !== null && properties !== void 0 ? properties : {}, { detail } = _a, otherProps = __rest(_a, ["detail"]); const event = new CustomEvent(name, { detail }); Object.assign(event, otherProps); element.dispatchEvent(event); } /** * @param {Element} element * @param {string} value */ function setContenteditableValue(element, value) { if (!( /** @type {HTMLElement} */element.isContentEditable)) { throw new Error("setContenteditableValue can only be called on a 'contenteditable' element"); } element.textContent = value; } /** * @param {Element} element * @param {string} property */ function getProperty(element, property) { return /** @type {any} */ element[property]; } var _PlaywrightElement_page, _PlaywrightElement_query, _PlaywrightElement_perform, _PlaywrightElement_evaluate, _PlaywrightElement_toClickOptions; /** * @type {Map} */ const keyMap = new Map([ [leftest.TestKey.ALT, "Alt"], [leftest.TestKey.BACKSPACE, "Backspace"], [leftest.TestKey.CONTROL, "Control"], [leftest.TestKey.DELETE, "Delete"], [leftest.TestKey.DOWN_ARROW, "ArrowDown"], [leftest.TestKey.END, "End"], [leftest.TestKey.ENTER, "Enter"], [leftest.TestKey.ESCAPE, "Escape"], [leftest.TestKey.F1, "F1"], [leftest.TestKey.F2, "F2"], [leftest.TestKey.F3, "F3"], [leftest.TestKey.F4, "F4"], [leftest.TestKey.F5, "F5"], [leftest.TestKey.F6, "F6"], [leftest.TestKey.F7, "F7"], [leftest.TestKey.F8, "F8"], [leftest.TestKey.F9, "F9"], [leftest.TestKey.F10, "F10"], [leftest.TestKey.F11, "F11"], [leftest.TestKey.F12, "F12"], [leftest.TestKey.HOME, "Home"], [leftest.TestKey.INSERT, "Insert"], [leftest.TestKey.LEFT_ARROW, "ArrowLeft"], [leftest.TestKey.META, "Meta"], [leftest.TestKey.PAGE_DOWN, "PageDown"], [leftest.TestKey.PAGE_UP, "PageUp"], [leftest.TestKey.RIGHT_ARROW, "ArrowRight"], [leftest.TestKey.SHIFT, "Shift"], [leftest.TestKey.TAB, "Tab"], [leftest.TestKey.UP_ARROW, "ArrowUp"], ]); const modifierMapping = /** @type {const} */ [ ["alt", "Alt"], ["shift", "Shift"], ["meta", "Meta"], ["control", "Control"], ]; /** * @param {ModifierKeys} modifiers */ function getModifiers(modifiers) { return modifierMapping .filter(([modifier]) => modifiers[modifier]) .map(([, modifier]) => modifier); } /** * @param {(string | TestKey)[] | [ModifierKeys, ...(string | TestKey)[]]} keys * @returns {keys is [ModifierKeys, ...(string | TestKey)[]]} */ function hasModifiers(keys) { return typeof keys[0] === "object"; } /** * @template {unknown[]} T * @param {T} args * @returns {args is T & ['center', ...unknown[]]} */ function isCenterClick(args) { return args[0] === "center"; } /** * @param {ClickParameters} args * @returns {args is [number, number, ModifierKeys?]} */ function isPositionedClick(args) { return typeof args[0] === "number"; } /** * * @param {ElementHandle | Locator} handleOrLocator * @returns {handleOrLocator is Locator} */ function isLocator(handleOrLocator) { return !("$$" in handleOrLocator); } /** * `TestElement` implementation backed by playwright's `ElementHandle` * * @internal * @implements TestElement */ class PlaywrightElement { /** * @param {() => Page} page * @param {ElementHandle | Locator} locator * @param {() => Promise} whenStable */ constructor(page, locator, whenStable) { this.locator = locator; /** * The page the element is on * * @readonly * @type {() => Page} */ _PlaywrightElement_page.set(this, void 0); /** * Awaits for the angular app to become stable * * This function has to be called after every manipulation and before any query * * @readonly * @type {(fn: (handle: Locator | ElementHandle) => Promise) => Promise} */ _PlaywrightElement_query.set(this, void 0); /** * Awaits for the angular app to become stable * * This function has to be called after every manipulation and before any query * * @readonly * @type {(fn: (handle: Locator | ElementHandle) => Promise) => Promise} */ _PlaywrightElement_perform.set(this, void 0); /** * Execute the given script * * @readonly * @type {Locator['evaluate']} */ _PlaywrightElement_evaluate.set(this, void 0); /** * * @param {ClickParameters} args * @returns {Promise[0]>} */ _PlaywrightElement_toClickOptions.set(this, (...args) => __awaiter(this, void 0, void 0, function* () { /** @type {Parameters[0]} */ const clickOptions = {}; /** @type {ModifierKeys | undefined} */ let modifierKeys; if (isCenterClick(args)) { const size = yield this.getDimensions(); clickOptions.position = { x: size.width / 2, y: size.height / 2, }; modifierKeys = args[1]; } else if (isPositionedClick(args)) { clickOptions.position = { x: args[0], y: args[1] }; modifierKeys = args[2]; } else { modifierKeys = args[0]; } if (modifierKeys) { clickOptions.modifiers = getModifiers(modifierKeys); } return clickOptions; }) /** * @returns {Promise} */ ); __classPrivateFieldSet(this, _PlaywrightElement_page, page, "f"); __classPrivateFieldSet(this, _PlaywrightElement_query, (fn) => __awaiter(this, void 0, void 0, function* () { yield whenStable(); return fn(locator); }), "f"); __classPrivateFieldSet(this, _PlaywrightElement_perform, (fn) => __awaiter(this, void 0, void 0, function* () { try { return yield fn(locator); } finally { yield whenStable(); } }), "f"); __classPrivateFieldSet(this, _PlaywrightElement_evaluate, /** @type {Locator} */ locator.evaluate.bind(locator), "f"); } /** * @returns {Promise} */ blur() { // Playwright exposes a `focus` function but no `blur` function, so we have // to resort to executing a function ourselves. return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, () => __classPrivateFieldGet(this, _PlaywrightElement_evaluate, "f").call(this, blur)); } /** * @returns {Promise} */ clear() { return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, (handle) => handle.fill("")); } /** * @param {ClickParameters} args * @returns {Promise} */ click(...args) { return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, (handle) => __awaiter(this, void 0, void 0, function* () { return handle.click(yield __classPrivateFieldGet(this, _PlaywrightElement_toClickOptions, "f").call(this, ...args)); })); } /** * @param {ClickParameters} args * @returns {Promise} */ rightClick(...args) { return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, (handle) => __awaiter(this, void 0, void 0, function* () { return handle.click(Object.assign(Object.assign({}, (yield __classPrivateFieldGet(this, _PlaywrightElement_toClickOptions, "f").call(this, ...args))), { button: "right" })); })); } /** * @param {string} name * @param {Record=} data * @returns {Promise} */ dispatchEvent(name, data) { // ElementHandle#dispatchEvent executes the equivalent of // `element.dispatchEvent(new CustomEvent(name, {detail: data}))` // which doesn't match what angular wants: `data` are properties to be // placed on the event directly rather than on the `details` property return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, () => // Cast to `any` needed because of infinite type instantiation __classPrivateFieldGet(this, _PlaywrightElement_evaluate, "f").call(this, dispatchEvent, /** @type {[string, any]} */ [name, data])); } /** * @returns {Promise} */ focus() { return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, (handle) => handle.focus()); } /** * @param {string} property * @returns {Promise} */ getCssValue(property) { return __awaiter(this, void 0, void 0, function* () { return __classPrivateFieldGet(this, _PlaywrightElement_query, "f").call(this, () => __classPrivateFieldGet(this, _PlaywrightElement_evaluate, "f").call(this, getStyleProperty, property)); }); } /** * @returns {Promise} */ hover() { return __awaiter(this, void 0, void 0, function* () { return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, (handle) => handle.hover()); }); } /** * @returns {Promise} */ mouseAway() { return __awaiter(this, void 0, void 0, function* () { const { left, top } = yield __classPrivateFieldGet(this, _PlaywrightElement_query, "f").call(this, (handle) => __awaiter(this, void 0, void 0, function* () { let { left, top } = yield __classPrivateFieldGet(this, _PlaywrightElement_evaluate, "f").call(this, getBoundingClientRect); if (left < 0 && top < 0) { yield handle.scrollIntoViewIfNeeded(); ({ left, top } = yield __classPrivateFieldGet(this, _PlaywrightElement_evaluate, "f").call(this, getBoundingClientRect)); } return { left, top }; })); return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, () => __classPrivateFieldGet(this, _PlaywrightElement_page, "f").call(this).mouse.move(Math.max(0, left - 1), Math.max(0, top - 1))); }); } /** * * @param {...number} optionIndexes * @returns {Promise} */ selectOptions(...optionIndexes) { // ElementHandle#selectOption supports selecting multiple options at once, // but that triggers only one change event. // So we select options as if we're a user: one at a time return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, (handle) => __awaiter(this, void 0, void 0, function* () { /** @type {{index: number}[]} */ const selections = []; for (const index of optionIndexes) { selections.push({ index }); yield handle.selectOption(selections); } })); } /** * * @param {(string | TestKey)[] | [ModifierKeys, ...(string | TestKey)[]]} input * @returns {Promise} */ sendKeys(...input) { return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, (handle) => __awaiter(this, void 0, void 0, function* () { var _a; /** @type {string | undefined} */ let modifiers; let keys; if (hasModifiers(input)) { /** @type {ModifierKeys} */ let modifiersObject; [modifiersObject, ...keys] = input; modifiers = getModifiers(modifiersObject).join("+"); } else { keys = input; } if (!keys.some((key) => key !== "")) { // throw getNoKeysSpecifiedError(); throw new Error("No keys specified"); } yield handle.focus(); const { keyboard } = __classPrivateFieldGet(this, _PlaywrightElement_page, "f").call(this); if (modifiers) { yield keyboard.down(modifiers); } try { for (const key of /** @type {(string | TestKey)[]} */ keys) { if (typeof key === "string") { yield keyboard.type(key); } else if (keyMap.has(key)) { yield keyboard.press( /** @type {string} */ keyMap.get(key)); } else { throw new Error(`Unknown key: ${(_a = leftest.TestKey[key]) !== null && _a !== void 0 ? _a : key}`); } } } finally { if (modifiers) { yield keyboard.up(modifiers); } } })); } /** * @param {string} value * @returns {Promise} */ setInputValue(value) { return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, (handle) => handle.fill(value)); } /** * @param {TextOptions=} options * @returns {Promise} */ text(options) { return __classPrivateFieldGet(this, _PlaywrightElement_query, "f").call(this, (handle) => { if (options === null || options === void 0 ? void 0 : options.exclude) { return __classPrivateFieldGet(this, _PlaywrightElement_evaluate, "f").call(this, getTextWithExcludedElements, options.exclude); } return handle.innerText(); }); } /** * @param {string} value * @returns {Promise} */ setContenteditableValue(value) { return __classPrivateFieldGet(this, _PlaywrightElement_perform, "f").call(this, () => __classPrivateFieldGet(this, _PlaywrightElement_evaluate, "f").call(this, setContenteditableValue, value)); } /** * @param {string} name * @returns {Promise} */ getAttribute(name) { return __classPrivateFieldGet(this, _PlaywrightElement_query, "f").call(this, (handle) => handle.getAttribute(name)); } /** * @param {string} name * @returns {Promise} */ hasClass(name) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const classes = (_b = (_a = (yield __classPrivateFieldGet(this, _PlaywrightElement_query, "f").call(this, (handle) => handle.getAttribute("class")))) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) !== null && _b !== void 0 ? _b : []; return classes.includes(name); }); } /** * @returns {Promise} */ getDimensions() { return __awaiter(this, void 0, void 0, function* () { return __classPrivateFieldGet(this, _PlaywrightElement_query, "f").call(this, () => __classPrivateFieldGet(this, _PlaywrightElement_evaluate, "f").call(this, getBoundingClientRect)); }); } /** * @param {string} name * @returns {Promise} */ getProperty(name) { return __awaiter(this, void 0, void 0, function* () { const property = yield __classPrivateFieldGet(this, _PlaywrightElement_query, "f").call(this, (handle) => __awaiter(this, void 0, void 0, function* () { if (isLocator(handle)) { return handle.evaluateHandle(getProperty, name); } else { return handle.getProperty(name); } })); try { return yield property.jsonValue(); } finally { yield property.dispose(); } }); } /** * @param {string} selector * @returns {Promise} */ matchesSelector(selector) { return __awaiter(this, void 0, void 0, function* () { return __classPrivateFieldGet(this, _PlaywrightElement_query, "f").call(this, () => __classPrivateFieldGet(this, _PlaywrightElement_evaluate, "f").call(this, matches, selector)); }); } /** * @returns {Promise} */ isFocused() { return __awaiter(this, void 0, void 0, function* () { return this.matchesSelector(":focus"); }); } } _PlaywrightElement_page = new WeakMap(), _PlaywrightElement_query = new WeakMap(), _PlaywrightElement_perform = new WeakMap(), _PlaywrightElement_evaluate = new WeakMap(), _PlaywrightElement_toClickOptions = new WeakMap(); var _PlaywrightHarnessEnvironment_page, _PlaywrightHarnessEnvironment_documentRoot, _PlaywrightHarnessEnvironment_opts; /** * @type {WeakMap | import('@playwright/test').Locator>} */ const elementHandles = new WeakMap(); /** * @internal */ class PlaywrightHarnessEnvironment extends leftest.HarnessEnvironment { static loader(page) { return new PlaywrightHarnessEnvironment(page); } static getHarnessForPage(page, harness) { return this.loader(page).getHarness(harness); } static getAllHarnessesForPage(page, harness) { return this.loader(page).getAllHarnesses(harness); } static getRootHarnessLoader(page) { return new PlaywrightHarnessEnvironment(page).rootHarnessLoader(); } static getLocator(element) { if (element instanceof PlaywrightElement) { return element.locator; } if (element instanceof leftest.ComponentHarness) { return this.getLocator(element.host()); } throw new Error("This TestElement was not created by the PlaywrightHarnessEnvironment"); } /** * * @param {import('@playwright/test').Page} page * @param {Readonly=} options * @param {import('@playwright/test').Locator=} documentRoot * @param {import('@playwright/test').ElementHandle | import('@playwright/test').Locator=} element */ constructor(page, { respectShadowBoundaries = false, useLocators = true } = {}, documentRoot = page.locator(":root"), element = documentRoot) { super(element); /** * @readonly * @type {import('@playwright/test').Page} */ _PlaywrightHarnessEnvironment_page.set(this, void 0); /** * @readonly * @type {import('@playwright/test').Locator} */ _PlaywrightHarnessEnvironment_documentRoot.set(this, void 0); /** * @readonly * @type {Required} */ _PlaywrightHarnessEnvironment_opts.set(this, void 0); __classPrivateFieldSet(this, _PlaywrightHarnessEnvironment_page, page, "f"); __classPrivateFieldSet(this, _PlaywrightHarnessEnvironment_documentRoot, documentRoot, "f"); __classPrivateFieldSet(this, _PlaywrightHarnessEnvironment_opts, { respectShadowBoundaries, useLocators, }, "f"); } /** * @type {boolean} * @override */ get respectShadowBoundaries() { return __classPrivateFieldGet(this, _PlaywrightHarnessEnvironment_opts, "f").respectShadowBoundaries; } /** * @returns {Promise} * @override */ waitForAngularReady() { return __awaiter(this, void 0, void 0, function* () { yield Promise.resolve(); // try { // await this.#page.waitForFunction(isAngularBootstrapped); // } catch { // throw new Error( // 'Angular failed to bootstrap the application, check whether there are any errors in the console when you open the application', // ); // } // // await this.forceStabilize(); }); } /** * @returns {Promise} * @override */ forceStabilize() { return __awaiter(this, void 0, void 0, function* () { // await this.#page.evaluate(waitUntilAngularStable); yield __classPrivateFieldGet(this, _PlaywrightHarnessEnvironment_page, "f").evaluate(() => { return new Promise(window.requestAnimationFrame); }); }); } /** * @returns {Promise} * @override */ waitForTasksOutsideAngular() { return __awaiter(this, void 0, void 0, function* () { throw new Error("Not implemented"); }); } /** * @param {import('@angular/cdk/testing').TestElement} element * @returns {Promise>} * @override */ getPlaywrightHandle(element) { return __awaiter(this, void 0, void 0, function* () { const handleOrLocator = elementHandles.get(element); if (handleOrLocator == null) { throw new Error("The given TestElement was not created by PlaywrightHarnessEnvironment"); } if (isLocator(handleOrLocator)) { // Only one case where we are passed a Locator: the root element of the page, which is always // present -> we can safely ignore the null return type return /** @type {import('@playwright/test').ElementHandle} */ yield handleOrLocator.elementHandle(); } else { return handleOrLocator; } }); } /** * @param {import('@angular/cdk/testing').TestElement} element * @returns {import('@playwright/test').Locator} * @override */ getPlaywrightLocator(element) { const handleOrLocator = elementHandles.get(element); if (handleOrLocator == null) { throw new Error("The given TestElement was not created by PlaywrightHarnessEnvironment"); } if (!isLocator(handleOrLocator)) { throw new Error("This PlaywrightHarnessEnvironment is not configured to use locators"); } return handleOrLocator; } /** * @param {import('./abstract-environment.js').PlaywrightHarnessEnvironmentOptions} options * @returns {PlaywrightHarnessEnvironment} * @override */ withOptions(options) { return new PlaywrightHarnessEnvironment(__classPrivateFieldGet(this, _PlaywrightHarnessEnvironment_page, "f"), Object.assign(Object.assign({}, __classPrivateFieldGet(this, _PlaywrightHarnessEnvironment_opts, "f")), options), __classPrivateFieldGet(this, _PlaywrightHarnessEnvironment_documentRoot, "f"), this.rawRootElement); } /** * * @returns {import('@playwright/test').Locator} * @override * @protected */ getDocumentRoot() { return __classPrivateFieldGet(this, _PlaywrightHarnessEnvironment_documentRoot, "f"); } /** * @param {import('@playwright/test').ElementHandle | import('@playwright/test').Locator} handle * @returns {import('@angular/cdk/testing').TestElement} * @override * @protected */ createTestElement(handle) { // This function is called in the HarnessEnvironment constructor, so we // can't directly use private properties here due to the polyfill in tslib const element = new PlaywrightElement(() => __classPrivateFieldGet(this, _PlaywrightHarnessEnvironment_page, "f"), handle, () => __awaiter(this, void 0, void 0, function* () { // if (shouldStabilizeAutomatically()) { // await this.forceStabilize(); // } })); elementHandles.set(element, handle); return element; } /** * @param {import('@playwright/test').ElementHandle | import('@playwright/test').Locator} element * @returns {PlaywrightHarnessEnvironment} * @override * @protected */ createEnvironment(element) { return new PlaywrightHarnessEnvironment(__classPrivateFieldGet(this, _PlaywrightHarnessEnvironment_page, "f"), __classPrivateFieldGet(this, _PlaywrightHarnessEnvironment_opts, "f"), __classPrivateFieldGet(this, _PlaywrightHarnessEnvironment_documentRoot, "f"), element); } /** * @param {string} selector * @returns {Promise<(import('@playwright/test').ElementHandle | import('@playwright/test').Locator)[]>} * @override * @protected */ getAllRawElements(selector) { return __awaiter(this, void 0, void 0, function* () { if (!isLocator(this.rawRootElement)) { return yield this.rawRootElement.$$(this.respectShadowBoundaries ? `css:light=${selector}` : `css=${selector}`); } else { const locator = this.rawRootElement.locator(this.respectShadowBoundaries ? `css:light=${selector}` : `css=${selector}`); if (__classPrivateFieldGet(this, _PlaywrightHarnessEnvironment_opts, "f").useLocators) { return Array.from({ length: yield locator.count() }, (_, i) => locator.nth(i)); } return /** @type {import('@playwright/test').ElementHandle[]} */ yield locator.elementHandles(); } }); } } _PlaywrightHarnessEnvironment_page = new WeakMap(), _PlaywrightHarnessEnvironment_documentRoot = new WeakMap(), _PlaywrightHarnessEnvironment_opts = new WeakMap(); function getHarnessForPage(page, harnessType) { return PlaywrightHarnessEnvironment.getHarnessForPage(page, harnessType); } function getAllHarnessesForPage(page, harnessType) { return PlaywrightHarnessEnvironment.getAllHarnessesForPage(page, harnessType); } function getRootHarnessLoader(page) { return PlaywrightHarnessEnvironment.getRootHarnessLoader(page); } function getLocator(element) { return PlaywrightHarnessEnvironment.getLocator(element); } exports.PlaywrightHarnessEnvironment = PlaywrightHarnessEnvironment; exports.PlaywrightTestSuiteAdapter = PlaywrightTestSuiteAdapter; exports.afterScenario = afterScenario; exports.afterStep = afterStep; exports.beforeScenario = beforeScenario; exports.beforeStep = beforeStep; exports.createSteps = createSteps; exports.extendTest = extendTest; exports.getAllHarnessesForPage = getAllHarnessesForPage; exports.getHarnessForPage = getHarnessForPage; exports.getLocator = getLocator; exports.getRootHarnessLoader = getRootHarnessLoader;