UNPKG

@vibe/testkit

Version:
100 lines 4.74 kB
"use strict"; 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.ButtonGroup = void 0; const test_1 = require("@playwright/test"); const BaseElement_1 = require("./BaseElement"); const Button_1 = require("./Button"); /** * Class representing a ButtonGroup element. * Extends the BaseElement class. */ class ButtonGroup extends BaseElement_1.BaseElement { /** * Create a ButtonGroup element. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the ButtonGroup element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName) { super(page, locator, elementReportName); } /** * Get all buttons. * @returns {Promise<Button[]>} An array of buttons. */ getAllButtons() { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Get all buttons for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return (yield this.getLocator().locator("button").all()).map((button, index) => new Button_1.Button(this.getPage(), button, `Button ${index + 1}`)); })); }); } /** * Get a button by its name. * @param {string} buttonName - The name of the button to get. * @returns {Promise<Button>} The button object. */ getButtonByName(buttonName) { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Get button by name ${buttonName} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return new Button_1.Button(this.getPage(), this.getLocator().locator("button").filter({ hasText: buttonName }), `Button: ${buttonName}`); })); }); } /** * Click a button by its name. * @param {string} buttonName - The name of the button to click. * @returns {Promise<void>} */ clickButton(buttonName) { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Click button by name ${buttonName} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const button = yield this.getButtonByName(buttonName); yield button.click(); })); }); } /** * Check if a button is selected. * @param {string} buttonName - The name of the button to check. * @returns {Promise<boolean>} True if the button is selected, false otherwise. */ isButtonSelected(buttonName) { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Check if button ${buttonName} is selected for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const button = yield this.getButtonByName(buttonName); return (yield button.getAttributeValue("class")).includes("selected"); })); }); } /** * Get the name of the selected button. * @returns {Promise<string>} The name of the selected button. */ getSelectedButtonName() { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Get selected button name for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const buttons = yield this.getAllButtons(); // Find the selected button for (const button of buttons) { if ((yield button.getAttributeValue("class")).includes("selected")) { return yield button.getText(); } } // If no selected button found, throw error throw new Error("No selected button found"); })); }); } } exports.ButtonGroup = ButtonGroup; //# sourceMappingURL=ButtonGroup.js.map