@vibe/testkit
Version:
Vibe e2e testing toolkit
129 lines • 5.78 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 element.
* @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);
}
/**
* Get a tab by its name.
* @param {string} tabName - The name of the tab to retrieve.
* @returns {Promise<Tab>} The tab with the specified name.
*/
getTabByName(tabName) {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Get tab by name ${tabName} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return new Tab_1.Tab(this.getPage(), this.getLocator().getByRole("tab", { name: tabName }), tabName);
}));
});
}
/**
* Get all tabs.
* @returns {Promise<Tab[]>} An array of tabs.
*/
getAllTabs() {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Get all tabs for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
const tabs = yield this.getLocator().getByRole("tab").all();
return tabs.map((tab, index) => new Tab_1.Tab(this.getPage(), tab, `${this.getElementReportName()} - Tab ${index}`));
}));
});
}
/**
* Get a tab by its index.
* @param {number} index - The index of the tab to retrieve.
* @returns {Promise<Tab>} The tab with the specified index.
*/
getTabByIndex(index) {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Get tab by index ${index} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return new Tab_1.Tab(this.getPage(), this.getLocator().getByRole("tab").nth(index), `${this.getElementReportName()} - Tab ${index}`);
}));
});
}
/**
* 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} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
const tab = yield this.getTabByName(tabName);
yield tab.click();
}));
});
}
/**
* Get the name of the selected tab.
* @returns {Promise<string>} The name of the selected tab.
*/
getSelectedTabName() {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Get selected tab name for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
const tabs = yield this.getAllTabs();
let selectedTab = null;
for (const tab of tabs) {
if (yield tab.isSelected()) {
selectedTab = tab;
break;
}
}
if (!selectedTab) {
throw new Error("No selected tab found");
}
return yield selectedTab.getText();
}));
});
}
/**
* Check if a tab is selected.
* @param {string} tabName - The name of the tab to check.
* @returns {Promise<boolean>} True if the tab is selected.
*/
isTabSelected(tabName) {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Check if tab ${tabName} is selected for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
const tab = yield this.getTabByName(tabName);
return yield tab.isSelected();
}));
});
}
/**
* Get the name of a tab by its index.
* @param {number} index - The index of the tab to retrieve.
* @returns {Promise<string>} The name of the tab with the specified index.
*/
getTabNameByIndex(index) {
return __awaiter(this, void 0, void 0, function* () {
return yield test_1.test.step(`Get tab name by index ${index} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
const tab = yield this.getTabByIndex(index);
return yield tab.getText();
}));
});
}
}
exports.TabList = TabList;
//# sourceMappingURL=TabList.js.map