@vibe/testkit
Version:
Vibe e2e testing toolkit
102 lines • 4.57 kB
JavaScript
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 { ListItem } from "./ListItem";
import { Search } from "./Search";
/**
* Class representing a Combobox element.
* Extends the BaseElement class.
*/
export class Combobox extends BaseElement {
/**
* Create a Combobox element.
* @param {Page} page - The Playwright page object.
* @param {Locator} locator - The locator for the Combobox element.
* @param {string} elementReportName - The name for reporting purposes.
*/
constructor(page, locator, elementReportName) {
super(page, locator, elementReportName);
this.searchField = new Search(page, locator, `${elementReportName} - Search Field`);
}
/**
* Get a combobox item by option.
* @param {string} option - The name of the option to get the combobox item for.
* @returns {Promise<ListItem>} The combobox item.
*/
getComboboxItemByOption(option) {
return __awaiter(this, void 0, void 0, function* () {
return yield test.step(`Get combobox item by option ${option} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return new ListItem(this.getPage(), this.getLocator().getByText(option), option);
}));
});
}
/**
* Select an item from the combobox.
* @param {string} item - The name of the item to select.
* @returns {Promise<void>}
*/
selectItem(item) {
return __awaiter(this, void 0, void 0, function* () {
yield test.step(`Select item ${item} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
yield this.search(item);
const comboBoxItem = yield this.getComboboxItemByOption(item);
yield comboBoxItem.click();
}));
});
}
/**
* Search for an option in the combobox.
* @param {string} option - The name of the option to search for.
* @returns {Promise<void>}
*/
search(option) {
return __awaiter(this, void 0, void 0, function* () {
yield test.step(`Search for ${option} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
yield this.searchField.setText(option);
}));
});
}
/**
* Clear the search.
* @returns {Promise<void>}
*/
clearSearch() {
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.searchField.clickClearSearchButton();
}));
});
}
/**
* Get the search input value.
* @returns {Promise<string>} The search input value.
*/
getSearchInputValue() {
return __awaiter(this, void 0, void 0, function* () {
return yield test.step(`Get search input value for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return yield this.searchField.getText();
}));
});
}
/**
* Check if the search result is visible.
* @param {string} item - The name of the item to check if the search result is visible for.
* @returns {Promise<boolean>} True if the search result is visible, false otherwise.
*/
isSearchResultVisible(item) {
return __awaiter(this, void 0, void 0, function* () {
return yield test.step(`Check if search result is visible for ${item} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return (yield this.getComboboxItemByOption(item)).isVisible(2000);
}));
});
}
}
//# sourceMappingURL=Combobox.js.map