UNPKG

@vibe/testkit

Version:
73 lines 3.51 kB
var __awaiter = (this && this.__awaiter) || function (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()); }); }; import { test } from "@playwright/test"; import { MenuItem } from "./MenuItem"; import { BaseElement } from "./BaseElement"; /** * Class representing a List element. * Extends the BaseElement class. */ export class Menu extends BaseElement { /** * Create a Menu. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the List element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName) { super(page, locator, elementReportName); this.items = []; this.itemsInitialized = false; } /** * Get all menu items. * @returns {Promise<MenuItem[]>} An array of MenuItem objects. */ getAllMenuItems() { return __awaiter(this, void 0, void 0, function* () { let menuItems = []; yield test.step(`Get all menu items in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { const menuItemsLocators = yield this.locator.getByRole("menuitem").all(); const menuItemsPromises = menuItemsLocators.map((locator) => __awaiter(this, void 0, void 0, function* () { return new MenuItem(this.page, locator, yield locator.innerText()); })); menuItems = yield Promise.all(menuItemsPromises); })); return menuItems; }); } /** * Get a menu item by its name. * @param {string} itemName - The name of the item to retrieve. * @returns {ListItem | undefined} The list item with the specified name or undefined if not found. */ getItemByName(itemName) { return __awaiter(this, void 0, void 0, function* () { let menuItem; yield test.step(`Get menu item by name ${itemName} in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { const menuItemLocator = this.locator.getByRole("menuitem"); menuItem = new MenuItem(this.page, menuItemLocator.filter({ has: this.page.getByText(itemName, { exact: true }) }), `Menu Item: ${itemName}`); })); return menuItem; }); } /** * Select a menu item. * @param {string} listItem - The name of the item to select. * @returns {Promise<void>} */ selectItem(listItem) { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Select menu item ${listItem} in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { const menuItem = yield this.getItemByName(listItem); yield (menuItem === null || menuItem === void 0 ? void 0 : menuItem.click()); })); }); } } //# sourceMappingURL=Menu.js.map