@vibe/testkit
Version:
Vibe e2e testing toolkit
105 lines • 4.91 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 { ListItem } from "./ListItem";
import { BaseElement } from "./BaseElement";
/**
* Class representing a List element.
* Extends the BaseElement class.
*/
export class List extends BaseElement {
/**
* Create a List element.
* @param {Page} page - The Playwright page object.
* @param {Locator} locator - The locator for the List element.
* @param {string} elementReportName - The name for reporting purposes.
*/
constructor(page, locator, elementReportName) {
super(page, locator, elementReportName);
}
/**
* Get a list item by its name.
* @param {string} itemName - The name of the item to retrieve.
* @returns {Promise<ListItem>} The list item with the specified name.
*/
getItemByName(itemName) {
return __awaiter(this, void 0, void 0, function* () {
return yield test.step(`Get list item by name ${itemName} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return new ListItem(this.getPage(), this.getLocator().getByText(`${itemName}`), itemName);
}));
});
}
/**
* Get a list item by its index.
* @param {number} index - The index of the item to retrieve.
* @returns {Promise<ListItem>} The list item with the specified index.
*/
getItemByIndex(index) {
return __awaiter(this, void 0, void 0, function* () {
return yield test.step(`Get list item by index ${index} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
return new ListItem(this.getPage(), this.getLocator().getByRole("option").nth(index), `${this.getElementReportName()} - List Item ${index}`);
}));
});
}
/**
* Click a list item by its name.
* @param {string} itemName - The name of the item to click.
* @returns {Promise<void>}
*/
selectItem(itemName) {
return __awaiter(this, void 0, void 0, function* () {
yield test.step(`Click list item by name ${itemName} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
const listItem = yield this.getItemByName(itemName);
yield listItem.scrollIntoView();
yield listItem.click();
}));
});
}
/**
* Check if a list item is disabled.
* @param {string} itemName - The name of the item to check.
* @returns {Promise<boolean>} True if the item is disabled, false otherwise.
*/
isItemDisabled(itemName) {
return __awaiter(this, void 0, void 0, function* () {
return yield test.step(`Check if list item ${itemName} is disabled for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
const listItem = yield this.getItemByName(itemName);
return yield listItem.isDisabled();
}));
});
}
/**
* Get the text of a list item by its index.
* @param {number} index - The index of the item to retrieve.
* @returns {Promise<string>} The text of the list item with the specified index.
*/
getItemTextByIndex(index) {
return __awaiter(this, void 0, void 0, function* () {
return yield test.step(`Get list item text by index ${index} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
const listItem = yield this.getItemByIndex(index);
return yield listItem.getText();
}));
});
}
/**
* Click a list item by its index.
* @param {number} index - The index of the item to click.
* @returns {Promise<void>}
*/
clickItemByIndex(index) {
return __awaiter(this, void 0, void 0, function* () {
yield test.step(`Click list item by index ${index} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () {
const listItem = yield this.getItemByIndex(index);
yield listItem.click();
}));
});
}
}
//# sourceMappingURL=List.js.map