UNPKG

@vibe/testkit

Version:
72 lines 3.27 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"; import { Tab } from "./Tab"; /** * Class representing a TabList element. * Extends the BaseElement class. */ export class TabList extends BaseElement { /** * Create a TabList. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the TabList element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName) { super(page, locator, elementReportName); } getAllTabs() { return __awaiter(this, void 0, void 0, function* () { let tabs = []; yield test.step(`Get all tabs in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { const tabsLocators = yield this.locator.locator("li").all(); const tabPromises = tabsLocators.map((tabLocator) => __awaiter(this, void 0, void 0, function* () { return new Tab(this.page, tabLocator, yield tabLocator.innerText()); })); tabs = yield Promise.all(tabPromises); })); return tabs; }); } /** * Get a tab by its name. * @param {string} tabName - The name of the button to retrieve. * @returns {Button} The button with the specified name. */ getTabByName(tabName) { return __awaiter(this, void 0, void 0, function* () { let tab; yield test.step(`Get tab by name ${tabName} in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { const tabLocator = this.locator.locator("li").filter({ hasText: tabName }); tab = new Tab(this.page, tabLocator, `Tab: ${tabName}`); })); return tab; }); } /** * Select a tab by its name. * @param {string} tabName - The name of the tab to select. * @returns {Promise<void>} */ selectTab(tabName) { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Select tab ${tabName} in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { const tab = yield this.getTabByName(tabName); if (tab) { yield tab.click(); } else { throw new Error(`Tab with name "${tabName}" not found in ${this.elementReportName}`); } })); }); } } //# sourceMappingURL=TabList.js.map