UNPKG

@vibe/testkit

Version:
88 lines 3.77 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 { TextField } from "./TextField"; import { BaseElement } from "./BaseElement"; /** * Class representing a DropDown element. * Extends the BaseElement class. */ export class Dropdown extends BaseElement { /** * Create a DropDown. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the DropDown element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName) { super(page, locator, elementReportName); this.inputField = new TextField(this.page, this.locator.locator("input"), "Dropdown Input Field"); } /** * Open the dropdown. * @returns {Promise<void>} */ open() { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Open ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { if (!(yield this.isDropdownOpen())) { yield this.locator.click(); } })); }); } /** * Select an item from a dropdown. * @param {string} item - The value text to be selected in the dropdown. * @returns {Promise<void>} */ selectItem(item) { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Select ${item} from ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { yield this.open(); yield this.inputField.setText(item); const dropdownItem = this.locator.getByRole("option", { name: item }); yield dropdownItem.click(); })); }); } /** * Select multiple items from a dropdown. * @param items - The values text to be selected in the dropdown. * @returns {Promise<void>} */ selectMultipleItems(items) { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Select ${items} from ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { yield this.open(); for (const item of items) { yield this.inputField.setText(item); const dropdownItem = this.locator.getByRole("option", { name: item }); yield dropdownItem.click(); } })); }); } /** * Check if the dropdown is open. * @returns {Promise<boolean>} */ isDropdownOpen() { return __awaiter(this, void 0, void 0, function* () { let isOpen = false; yield test.step(`Check if ${this.elementReportName} is open`, () => __awaiter(this, void 0, void 0, function* () { const expandedAttribute = yield this.inputField.getAttributeValue("aria-expanded"); isOpen = expandedAttribute === "true" ? true : false; })); return isOpen; }); } } //# sourceMappingURL=Dropdown.js.map