UNPKG

@vibe/testkit

Version:
248 lines 11.2 kB
"use strict"; 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.Steps = void 0; const test_1 = require("@playwright/test"); const BaseElement_1 = require("./BaseElement"); const Button_1 = require("./Button"); /** * Class representing a Steps element. * Extends the BaseElement class. */ class Steps extends BaseElement_1.BaseElement { /** * Create a Steps element. * @param {Page} page - The Playwright page object. * @param {Locator} locator - The locator for the Steps element. * @param {string} elementReportName - The name for reporting purposes. */ constructor(page, locator, elementReportName) { super(page, locator, elementReportName); this.backButton = new Button_1.Button(page, this.getLocator().locator("button").first(), `${elementReportName} - Back Button`); this.forwardButton = new Button_1.Button(page, this.getLocator().locator("button").last(), `${elementReportName} - Forward Button`); } /** * Get a step by its index. * @param {number} index - The index of the step to retrieve. * @returns {Promise<Button>} The step with the specified index. */ getStepByIndex(index) { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Get step by index ${index} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return new Button_1.Button(this.getPage(), this.getLocator().getByRole("group").locator("button").nth(index), `${this.getElementReportName()} - Step ${index}`); })); }); } /** * Get all step dots. * @returns {Promise<Button[]>} An array of step dots. */ getStepDots() { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Get all steps for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const steps = yield this.getLocator().getByRole("group").locator("button").all(); return steps.map((step, index) => new Button_1.Button(this.getPage(), step, `${this.getElementReportName()} - Step ${index}`)); })); }); } /** * Go to the previous step. */ goToPreviousStep() { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Click back button for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.backButton.click(); })); }); } /** * Go to the next step. */ goToNextStep() { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Click next button for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.forwardButton.click(); })); }); } /** * Check if the back button is enabled. * @returns {Promise<boolean>} True if the back button is enabled, false otherwise. */ isBackButtonEnabled() { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Check if back button is enabled for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.backButton.isEnabled(); })); }); } /** * Check if the forward button is enabled. * @returns {Promise<boolean>} True if the forward button is enabled, false otherwise. */ isForwardButtonEnabled() { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Check if forward button is enabled for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.forwardButton.isEnabled(); })); }); } /** * Check if the back button is visible. * @returns {Promise<boolean>} True if the back button is visible, false otherwise. */ isBackButtonVisible() { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Check if back button is visible for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.backButton.isVisible(); })); }); } /** * Check if the forward button is visible. * @returns {Promise<boolean>} True if the forward button is visible, false otherwise. */ isForwardButtonVisible() { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Check if forward button is visible for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { return yield this.forwardButton.isVisible(); })); }); } /** * Get the number of steps. * @returns {Promise<number>} The number of steps. */ getTotalStepsCount() { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Get number of steps for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const steps = yield this.getStepDots(); return steps.length; })); }); } /** * Click a step dot by its index. * @param {number} stepIndex - The index of the step dot to click. * @returns {Promise<void>} */ clickStepDot(stepIndex) { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Click step dot by index ${stepIndex} for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const step = yield this.getStepByIndex(stepIndex); yield step.click(); })); }); } /** * Get the active step dot index. * @returns {Promise<number>} The active step dot index. */ getActiveStepDotIndex() { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Get active step dot index for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const steps = yield this.getStepDots(); let activeStepIndex = -1; for (const step of steps) { if ((yield step.getAttributeValue("aria-current")) === "step") { activeStepIndex = steps.indexOf(step); break; } } return activeStepIndex; })); }); } /** * Check if a step dot is active. * @param {number} stepIndex - The index of the step dot to check. * @returns {Promise<boolean>} True if the step dot is active. */ isStepDotActive(stepIndex) { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Check if step dot ${stepIndex} is active for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const step = yield this.getStepByIndex(stepIndex); return (yield step.getAttributeValue("aria-current")) === "step"; })); }); } /** * Navigate to the first step. * @returns {Promise<void>} */ navigateToBeginning() { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Navigate to first step for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.clickStepDot(0); })); }); } /** * Navigate to the last step. * @returns {Promise<void>} */ navigateToEnd() { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Navigate to last step for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const numberOfSteps = yield this.getTotalStepsCount(); yield this.clickStepDot(numberOfSteps - 1); })); }); } /** * Get the current step content. * @returns {Promise<BaseElement>} The current step content. */ getCurrentStepContent() { return __awaiter(this, void 0, void 0, function* () { return yield test_1.test.step(`Get current step content for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { const locatorsToAvoid = this.getLocator() .locator('.header, [data-testid*="steps-forward-command"], [data-testid*="steps-backward-command"]') .first(); const stepContent = this.getLocator().locator("> *").filter({ hasNot: locatorsToAvoid }); return new BaseElement_1.BaseElement(this.getPage(), stepContent, `${this.getElementReportName()} - Step Content`); })); }); } /** * Get the current step index from the steps numbers header (for numbers type steps). * @returns {Promise<number>} The current step index (0-based). */ getCurrentStepIndex() { return __awaiter(this, void 0, void 0, function* () { let currentStepIndex = 0; yield test_1.test.step(`Get current step index from ${this.elementReportName}`, () => __awaiter(this, void 0, void 0, function* () { const numbersText = yield this.locator .locator("span") .filter({ hasText: /\d+\s*\\\s*\d+/ }) .innerText(); const match = numbersText.match(/(\d+)\s*\\\s*(\d+)/); if (match) { currentStepIndex = parseInt(match[1]) - 1; // Convert to 0-based index } })); return currentStepIndex; }); } /** * Wait for the steps to load. * @returns {Promise<void>} */ waitForStepsToLoad() { return __awaiter(this, void 0, void 0, function* () { yield test_1.test.step(`Wait for steps to load for ${this.getElementReportName()}`, () => __awaiter(this, void 0, void 0, function* () { yield this.waitForElementToBeVisible(); })); }); } } exports.Steps = Steps; //# sourceMappingURL=Steps.js.map