UNPKG

@vibe/testkit

Version:
79 lines 3.38 kB
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 { TextField } from "./TextField"; import { Text } from "./Text"; /** * Class representing a Checkbox element. * Extends the BaseElement class. */ export class Checkbox extends BaseElement { /** * Create a Checkbox element. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the Checkbox element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName) { super(page, locator, elementReportName); this.checkbox = new TextField(page, locator.locator("input"), `${elementReportName} - Checkbox`); this.label = new Text(page, locator.locator("span"), `${elementReportName} - Label`); } /** * Set the checkbox to checked. * @returns {Promise<void>} */ setChecked() { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Check checkbox for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { if (!(yield this.isChecked())) { yield this.getLocator().click(); } })); }); } /** * Set the checkbox to unchecked. * @returns {Promise<void>} */ setUnchecked() { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Uncheck checkbox for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { if (yield this.isChecked()) { yield this.getLocator().click(); } })); }); } /** * Check if the checkbox is checked. * @returns {Promise<boolean>} True if the checkbox is checked, false otherwise. */ isChecked() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Check if checkbox is checked for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.checkbox.getLocator().isChecked(); })); }); } /** * Get the label of the checkbox. * @returns {Promise<string>} The label of the checkbox. */ getLabel() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get checkbox label for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.label.getText(); })); }); } } //# sourceMappingURL=Checkbox.js.map