@vibe/testkit
Version:
Vibe e2e testing toolkit
56 lines • 2.66 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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColorPicker = void 0;
const BaseElement_1 = require("./BaseElement");
const Button_1 = require("./Button");
/**
* Class representing a ColorPicker element.
* Extends the BaseElement class.
*/
class ColorPicker extends BaseElement_1.BaseElement {
/**
* Create a ColorPicker.
* @param {Page} page - The Playwright page object.
* @param {Locator} locator - The locator for the ColorPicker element.
* @param {string} elementReportName - The name for reporting purposes.
*/
constructor(page, locator, elementReportName) {
super(page, locator, elementReportName);
this.page = page;
this.locator = locator;
}
/**
* Select a color from the color picker.
* @param {string} color - The color to select.
* @returns {Promise<void>}
*/
selectColor(color) {
return __awaiter(this, void 0, void 0, function* () {
const colorItem = new Button_1.Button(this.page, this.locator.getByTestId(`color-picker-item_${color}`), `Color: ${color}`);
yield colorItem.click();
});
}
/**
* Get the currently selected color.
* @returns {Promise<string>} The selected color.
*/
getSelectedColor() {
return __awaiter(this, void 0, void 0, function* () {
const selectedColor = new BaseElement_1.BaseElement(this.page, this.locator.locator("//*[contains(@class, 'selectedColor')]"), "Selected Color");
const dataTestIdAttr = yield selectedColor.getAttributeValue("data-testId");
const parts = dataTestIdAttr === null || dataTestIdAttr === void 0 ? void 0 : dataTestIdAttr.split("_");
return parts === null || parts === void 0 ? void 0 : parts.slice(-2).join("_"); // Returning the last two parts as the selected color
});
}
}
exports.ColorPicker = ColorPicker;
//# sourceMappingURL=ColorPicker.js.map