@vibe/testkit
Version:
Vibe e2e testing toolkit
76 lines • 3.45 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TabList = void 0;
const test_1 = require("@playwright/test");
const BaseElement_1 = require("./BaseElement");
const Tab_1 = require("./Tab");
/**
* Class representing a TabList element.
* Extends the BaseElement class.
*/
class TabList extends BaseElement_1.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_1.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_1.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_1.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_1.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_1.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}`);
}
}));
});
}
}
exports.TabList = TabList;
//# sourceMappingURL=TabList.js.map