@vibe/testkit
Version:
Vibe e2e testing toolkit
67 lines • 3.24 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 group of buttons.
* Extends the BaseElement class.
*/
export class ButtonGroup extends BaseElement {
constructor(page, locator, elementReportName) {
super(page, locator, elementReportName);
}
/**
* Get all buttons in the button group.
* @returns {Promise<Button[]>} An array of Button objects.
*/
getAllButtons() {
return __awaiter(this, void 0, void 0, function* () {
let buttons = [];
yield test.step(`Get all buttons in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () {
const buttonsLocators = yield this.locator.locator("button").all();
const buttonPromises = buttonsLocators.map((buttonLocator) => __awaiter(this, void 0, void 0, function* () { return new Button(this.page, buttonLocator, yield buttonLocator.innerText()); }));
buttons = yield Promise.all(buttonPromises);
}));
return buttons;
});
}
/**
* Get a button by its name.
* @param {string} buttonName - The name of the button to retrieve.
* @returns {Button} The button with the specified name.
*/
getButtonByName(buttonName) {
return __awaiter(this, void 0, void 0, function* () {
let button;
yield test.step(`Get button by name ${buttonName} in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () {
button = new Button(this.page, this.locator.locator("button").filter({ hasText: buttonName }), `Button: ${buttonName}`);
}));
return button;
});
}
/**
* 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 ${buttonName} in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () {
const button = new Button(this.page, this.locator.locator("button").filter({ hasText: buttonName }), `Button: ${buttonName}`);
if (!button) {
throw new Error(`Invalid button name provided: ${buttonName}`);
}
yield button.click();
}));
});
}
}
//# sourceMappingURL=ButtonGroup.js.map