UNPKG

@vibe/testkit

Version:
52 lines 2.22 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"; /** * Class representing a Toggle element. * Extends the BaseElement class. */ export class Toggle extends BaseElement { /** * Create a Toggle. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the Toggle element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName) { super(page, locator, elementReportName); } /** * Set the toggle state. * @param {boolean} isToCheck - True to turn on the toggle, false to turn off. * @returns {Promise<void>} */ set(isToCheck) { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Toggle: ${isToCheck}: ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { const currentState = yield this.isOn(); if (currentState !== isToCheck) { yield this.locator.click(); } })); }); } /** * Check if the toggle is on. * @returns {Promise<boolean>} True if the toggle is on, false otherwise. */ isOn() { return __awaiter(this, void 0, void 0, function* () { const isSelectedAttribute = yield this.locator.getAttribute("aria-checked"); return isSelectedAttribute === "true"; }); } } //# sourceMappingURL=Toggle.js.map