playwright-cucumber-ts-steps
Version:
A collection of reusable Playwright step definitions for Cucumber in TypeScript, designed to streamline end-to-end testing across web, API, and mobile applications.
246 lines (245 loc) • 9.05 kB
TypeScript
import type { CustomWorld } from "../helpers/world";
/**
* Asserts that the previously stored collection of elements has an exact expected count.
*
* ```gherkin
* Then I count {int} elements
* ```
*
* @param expectedCount - The expected number of elements in the collection.
*
* @example
* Given I find elements by selector ".list-item"
* Then I count 5 elements
*
* @remarks
* This step requires a preceding step that populates {@link CustomWorld.elements | this.elements}
* (e.g., "When I find elements by selector"). It then asserts that the number of
* elements in that collection matches `expectedCount`. It also waits for `networkidle`
* to ensure all elements that might affect the count have loaded.
* @category Assertion Steps
*/
export declare function Then_I_count_elements(this: CustomWorld, expectedCount: number): Promise<void>;
/**
* Asserts that a button with the given text (or text from an alias) is visible on the page.
* The text matching is case-insensitive and can be partial.
*
* ```gherkin
* Then I see button {string}
* ```
*
* @param rawText - The text of the button, or an alias prefixed with "@" (e.g., "Submit", "@submitButtonLabel").
*
* @example
* Then I see button "Sign In"
* Then I see button "@myLoginButton"
*
* @remarks
* This step uses `page.getByRole("button", { name: ..., exact: false })`.
* It waits for the page to be network idle and then asserts that the button is visible.
* @category Assertion Steps
*/
export declare function Then_I_see_button(this: CustomWorld, rawText: string): Promise<void>;
/**
* Asserts that a button with the given text (or text from an alias) is NOT visible on the page.
* The text matching is case-insensitive and can be partial.
*
* ```gherkin
* Then I do not see button {string}
* ```
*
* @param rawText - The text of the button, or an alias prefixed with "@".
*
* @example
* Then I do not see button "Delete Account"
* Then I do not see button "@hiddenAdminButton"
*
* @remarks
* This step checks for the absence of a visible button. It first waits for the page
* to be network idle, then finds potential buttons by role and name. If any matching
* button is found and is visible, the step will fail.
* @category Assertion Steps
*/
export declare function Then_I_do_not_see_button(this: CustomWorld, rawText: string): Promise<void>;
/**
* Asserts that specific text is visible on the current page or within the current frame/scope.
*
* ```gherkin
* Then I see text {string}
* ```
*
* @param expectedText - The text string expected to be visible.
*
* @example
* Then I see text "Welcome to your Dashboard"
*
* @remarks
* This step uses `locator.waitFor({ state: "visible" })` to ensure the text is present
* and displayed within the current Playwright scope (main page or active iframe).
* Text matching is a substring match by default.
* @category Assertion Steps
*/
export declare function Then_I_see_text(this: CustomWorld, expectedText: string): Promise<void>;
/**
* Asserts that the exact visible text is present on the page.
* This is similar to "I see text", but emphasizes "visible" for clarity.
*
* ```gherkin
* Then I see visible text {string}
* ```
*
* @param text - The exact text string expected to be visible.
*
* @example
* Then I see visible text "Dashboard"
*
* @remarks
* This step uses `:text-is()` pseudo-class for exact text matching and `isVisible()`
* to confirm presence. It also waits for `networkidle` beforehand.
* Consider consolidating with `Then I see text {string}` if you prefer `toBeVisible`
* which handles exact matching via options or `text-is` more flexibly.
* @category Assertion Steps
*/
export declare function Then_I_see_visible_text(this: CustomWorld, text: string): Promise<void>;
/**
* Asserts that specific exact visible text is NOT present on the page.
*
* ```gherkin
* Then I do not see visible text {string}
* ```
*
* @param text - The exact text string expected NOT to be visible.
*
* @example
* Then I do not see visible text "Logout"
*
* @remarks
* This step uses `:text-is()` for exact text matching. It asserts that no element
* with this exact text is visible.
* @category Assertion Steps
*/
export declare function Then_I_do_not_see_visible_text(this: CustomWorld, text: string): Promise<void>;
/**
* Asserts that the previously selected element has a specific input value.
*
* ```gherkin
* Then I see value {string}
* ```
*
* @param expectedValue - The expected exact value of the input or textarea.
*
* @example
* When I find element by selector "input[name='email']"
* Then I see value "test@example.com"
*
* @remarks
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
* to an input, textarea, or other element that has an input value.
* It uses Playwright's `locator.inputValue()`.
* @category Assertion Steps
*/
export declare function Then_I_see_value(this: CustomWorld, expectedValue: string): Promise<void>;
/**
* Asserts that the previously selected element does NOT have a specific input value.
*
* ```gherkin
* Then I do not see value {string}
* ```
*
* @param unwantedValue - The value that is expected NOT to be present in the input or textarea.
*
* @example
* When I find element by selector "input[name='password']"
* Then I do not see value "admin123"
*
* @remarks
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
* It asserts that the element's current input value does not match `unwantedValue`.
* @category Assertion Steps
*/
export declare function Then_I_do_not_see_value(this: CustomWorld, unwantedValue: string): Promise<void>;
/**
* Asserts that specific text is NOT present on the page. This checks for complete absence,
* not just visibility.
*
* ```gherkin
* Then I do not see text {string}
* ```
*
* @param unexpectedText - The text string that is expected NOT to be found on the page.
*
* @example
* Then I do not see text "Error Message"
*
* @remarks
* This step uses `page.getByText` with `exact: true` and then asserts that the count
* of matching elements is 0. This confirms the text is entirely absent from the DOM.
* @category Assertion Steps
*/
export declare function Then_I_do_not_see_text(this: CustomWorld, unexpectedText: string): Promise<void>;
/**
* Asserts that the previously selected element contains the given text,
* which can be a literal string, an alias, or a Faker.js expression.
*
* ```gherkin
* Then I see {string} in the element
* ```
*
* @param expected - The text string, alias (prefixed with "@"), or Faker.js expression expected to be contained within the element's text content.
*
* @example
* When I find element by selector "#welcome-message"
* Then I see "Welcome, John Doe!" in the element
* Given I store "user.name" as "loggedInUserName"
* When I find element by selector "#user-profile-name"
* Then I see "@loggedInUserName" in the element
* Then I see "Hello, {{person.firstName}}!" in the element
*
* @remarks
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
* It resolves aliases and Faker expressions before comparing the `textContent` of the element.
* It uses `expect(textContent).toContain(expected)` for partial matching.
* @category Assertion Steps
*/
export declare function Then_I_see_text_in_the_element(this: CustomWorld, expected: string): Promise<void>;
/**
* Asserts that the previously selected element contains the value retrieved from a specific alias.
*
* ```gherkin
* Then I see @{word} in the element
* ```
*
* @param alias - The alias name from which to retrieve the expected text value.
*
* @example
* Given I store "Generated Name" as "tempName"
* When I find element by selector "#display-name"
* Then I see @tempName in the element
*
* @remarks
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
* It fetches the value from `this.data[alias]` and then asserts that the element's
* `textContent` (trimmed) contains this stored value. This is a specialized version of
* `Then I see {string} in the element` specifically for aliases.
* @category Assertion Steps
*/
export declare function Then_I_see_alias_in_the_element(this: CustomWorld, alias: string): Promise<void>;
/**
* Asserts that a button with the given text (or text from an alias) is disabled.
*
* ```gherkin
* Then I see button {string} is disabled
* ```
*
* @param rawText - The text of the button, or an alias prefixed with "@".
*
* @example
* Then I see button "Submit" is disabled
* Then I see button "@checkoutButton" is disabled
*
* @remarks
* This step first locates the button by its role and name, asserts it's visible,
* and then checks its disabled state using Playwright's `isDisabled()` method.
* @category Assertion Steps
*/
export declare function Then_I_see_button_is_disabled(this: CustomWorld, rawText: string): Promise<void>;