@vibe/testkit
Version:
Vibe e2e testing toolkit
71 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.ButtonGroup = void 0;
const test_1 = require("@playwright/test");
const BaseElement_1 = require("./BaseElement");
const Button_1 = require("./Button");
/**
* Class representing a group of buttons.
* Extends the BaseElement class.
*/
class ButtonGroup extends BaseElement_1.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_1.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_1.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_1.test.step(`Get button by name ${buttonName} in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () {
button = new Button_1.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_1.test.step(`Click button ${buttonName} in ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () {
const button = new Button_1.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();
}));
});
}
}
exports.ButtonGroup = ButtonGroup;
//# sourceMappingURL=ButtonGroup.js.map