@vibe/testkit
Version:
Vibe e2e testing toolkit
96 lines • 4.53 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());
});
};
import { test } from "@playwright/test";
import { BaseElement } from "./BaseElement";
import { Button } from "./Button";
/**
* Class representing a ButtonGroup element.
* Extends the BaseElement class.
*/
export class ButtonGroup extends 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.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(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.step(`Get button by name ${buttonName} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return new 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.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.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.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");
}));
});
}
}
//# sourceMappingURL=ButtonGroup.js.map