UNPKG

@vibe/testkit

Version:
90 lines 3.94 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 { IconButton } from "./IconButton"; import { MenuButton } from "./MenuButton"; /** * Class representing a Search element. * Extends the BaseElement class. */ export class Search extends BaseElement { /** * Create a Search element. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the Search element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName, filterMenuType) { super(page, locator, elementReportName); this.input = new TextField(page, locator.locator("[type='search']"), `${elementReportName} - Input`); this.clearSearchIconButton = new IconButton(page, locator.locator("[aria-label='Clear']"), `${elementReportName} - Clear Search Icon Button`); if (filterMenuType) { this.filterButton = new MenuButton(this.getPage(), this.getLocator().locator("[aria-label='Filters']").nth(1), "Filter Button", filterMenuType); } } /** * Set specified text in search field. * @param {string} text - Text to be filled in the search field. * @returns {Promise<void>} */ setText(text) { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Set text: ${text} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.input.setText(text); })); }); } /** * Clear the text in the search field. */ clear() { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Clear text for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.input.clearText(); })); }); } /** * Get the text from the search field. * @returns {Promise<string>} The text from the search field. */ getText() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Get text for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.input.getText(); })); }); } /** * Check if the search field is empty. * @returns {Promise<string>} */ isEmpty() { return __awaiter(this, void 0, void 0, function* () { return yield test.step(`Check if search field is empty for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.input.isEmpty(); })); }); } /** * Click the clear search button. * @returns {Promise<void>} */ clickClearSearchButton() { return __awaiter(this, void 0, void 0, function* () { yield test.step(`Clear search for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.clearSearchIconButton.click(); })); }); } } //# sourceMappingURL=Search.js.map