UNPKG

@vibe/testkit

Version:
83 lines 3.58 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.Checkbox = void 0; const test_1 = require("@playwright/test"); const BaseElement_1 = require("./BaseElement"); const TextField_1 = require("./TextField"); const Text_1 = require("./Text"); /** * Class representing a Checkbox element. * Extends the BaseElement class. */ class Checkbox extends BaseElement_1.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_1.TextField(page, locator.locator("input"), `${elementReportName} - Checkbox`); this.label = new Text_1.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_1.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_1.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_1.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_1.test.step(`Get checkbox label for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.label.getText(); })); }); } } exports.Checkbox = Checkbox; //# sourceMappingURL=Checkbox.js.map