UNPKG

@vibe/testkit

Version:
95 lines 4.04 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 { BaseElement } from "./BaseElement"; /** * Class representing a MenuButton element. * Extends the BaseElement class. */ export class MenuButton extends BaseElement { /** * Create a MenuButton element. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the MenuButton element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName, menu) { super(page, locator, elementReportName); this.menu = menu; } /** * Select an item from the menu. * @param {string} itemName - The name of the item to select. * @returns {Promise<void>} */ selectItem(itemName) { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Select menu item by name ${itemName} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.openMenu(); yield this.menu.selectItem(itemName); })); }); } /** * Open the menu if it is not already expanded. * @returns {Promise<void>} */ openMenu() { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Open menu for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { if (!(yield this.isExpanded())) { yield this.click(); // Wait for the menu to open yield this.getPage().waitForTimeout(200); } })); }); } /** * Close the menu if it is currently expanded. * @returns {Promise<void>} */ closeMenu() { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Close menu for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { if (yield this.isExpanded()) { yield this.click(); // Wait for the menu to close yield this.getPage().waitForTimeout(200); } })); }); } /** * Check if the secondary button menu is expanded. * @returns {Promise<boolean>} True if the secondary button menu is expanded, false otherwise. */ isMenuExpanded() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Check if menu is expanded for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.isExpanded(); })); }); } /** * Select a sub menu item. * @param {string} rootItem - The name of the root item. * @param {string} subItem - The name of the sub item. * @returns {Promise<void>} */ selectSubItem(rootItem, subItem) { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Select sub menu item ${subItem} in ${rootItem} in ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.menu.selectSubItem(rootItem, subItem); })); }); } } //# sourceMappingURL=MenuButton.js.map