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.
249 lines (248 loc) • 9.32 kB
TypeScript
import { CustomWorld } from "../helpers/world";
/**
* Asserts that an input element matching the given selector has an exact expected value.
*
* ```gherkin
* Then I see input {string} has value {string}
* ```
*
* @param selector - The CSS selector of the input element (e.g., "input[name='email']").
* @param expectedValue - The exact value the input is expected to have.
*
* @example
* Then I see input "input[name='email']" has value "user@example.com"
*
* @remarks
* This step uses Playwright's `expect(locator).toHaveValue()` which automatically waits
* for the input to have the specified value.
* @category Input Assertion Steps
*/
export declare function Then_I_see_input_has_value(this: CustomWorld, selector: string, expectedValue: string): Promise<void>;
/**
* Asserts that the previously stored input element has an exact expected value.
*
* ```gherkin
* Then I see input value {string}
* ```
*
* @param expectedValue - The exact value the stored input is expected to have.
*
* @example
* When I find element by selector "input[name='email']"
* Then I see input value "user@example.com"
*
* @remarks
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
* to an input element. It uses Playwright's `locator.inputValue()` to get the current value
* and asserts strict equality.
* @category Input Assertion Steps
*/
export declare function Then_I_see_stored_input_value(this: CustomWorld, expectedValue: string): Promise<void>;
/**
* Asserts that the previously stored input element's value contains a given substring.
*
* ```gherkin
* Then I see input value contains {string}
* ```
*
* @param part - The substring expected to be contained within the input's value.
*
* @example
* When I find element by selector "input[name='email']"
* Then I see input value contains "@gmail.com"
*
* @remarks
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
* to an input element. It uses Playwright's `locator.inputValue()` and then checks for substring presence.
* @category Input Assertion Steps
*/
export declare function Then_I_see_stored_input_value_contains(this: CustomWorld, part: string): Promise<void>;
/**
* Asserts that an input element matching the given selector's value contains a given substring.
*
* ```gherkin
* Then I see input {string} value contains {string}
* ```
*
* @param selector - The CSS selector of the input element.
* @param partial - The substring expected to be contained within the input's value.
*
* @example
* Then I see input "input[name='email']" value contains "@gmail.com"
*
* @remarks
* This step uses Playwright's `locator.inputValue()` and asserts that the value includes the substring.
* @category Input Assertion Steps
*/
export declare function Then_I_see_input_value_contains(this: CustomWorld, selector: string, partial: string): Promise<void>;
/**
* Asserts that a textarea element matching the given selector has an exact expected value.
*
* ```gherkin
* Then I see textarea {string} has value {string}
* ```
*
* @param selector - The CSS selector of the textarea element (e.g., "textarea[name='bio']").
* @param expectedValue - The exact value the textarea is expected to have.
*
* @example
* Then I see textarea "textarea[name='bio']" has value "Hello"
*
* @remarks
* This step uses Playwright's `expect(locator).toHaveValue()` which automatically waits
* for the textarea to have the specified value.
* @category Textarea Assertion Steps
*/
export declare function Then_I_see_textarea_has_value(this: CustomWorld, selector: string, expectedValue: string): Promise<void>;
/**
* Asserts that the previously stored textarea element has an exact expected value.
*
* ```gherkin
* Then I see textarea value {string}
* ```
*
* @param expectedValue - The exact value the stored textarea is expected to have.
*
* @example
* When I find element by selector "textarea[name='bio']"
* Then I see textarea value "Hello"
*
* @remarks
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
* to a textarea element. It uses Playwright's `locator.inputValue()` to get the current value
* and asserts strict equality.
* @category Textarea Assertion Steps
*/
export declare function Then_I_see_stored_textarea_value(this: CustomWorld, expectedValue: string): Promise<void>;
/**
* Asserts that the previously stored textarea element's value contains a given substring.
*
* ```gherkin
* Then I see textarea value contains {string}
* ```
*
* @param part - The substring expected to be contained within the textarea's value.
*
* @example
* When I find element by selector "textarea[name='bio']"
* Then I see textarea value contains "Hello"
*
* @remarks
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
* to a textarea element. It uses Playwright's `locator.inputValue()` and then checks for substring presence.
* @category Textarea Assertion Steps
*/
export declare function Then_I_see_stored_textarea_value_contains(this: CustomWorld, part: string): Promise<void>;
/**
* Asserts that a textarea element matching the given selector's value contains a given substring.
*
* ```gherkin
* Then I see textarea {string} value contains {string}
* ```
*
* @param selector - The CSS selector of the textarea element.
* @param partial - The substring expected to be contained within the textarea's value.
*
* @example
* Then I see textarea "textarea[name='bio']" value contains "Hello"
*
* @remarks
* This step uses Playwright's `locator.inputValue()` and asserts that the value includes the substring.
* @category Textarea Assertion Steps
*/
export declare function Then_I_see_textarea_value_contains(this: CustomWorld, selector: string, partial: string): Promise<void>;
/**
* Asserts that an element matching the given selector has an exact expected value.
* This step is generic and can be used for inputs, textareas, or other elements
* whose value can be retrieved by Playwright's `toHaveValue`.
*
* ```gherkin
* Then I see value {string} in {string}
* ```
*
* @param expectedValue - The exact value expected.
* @param selector - The CSS selector of the element to check.
*
* @example
* Then I see value "foo" in "input[name='foo']"
* Then I see value "true" in "input[type='checkbox'][name='terms']"
*
* @remarks
* This step uses Playwright's `expect(locator).toHaveValue()` which is suitable
* for `<input>`, `<textarea>`, and `<select>` elements.
* @category Generic Assertion Steps
*/
export declare function Then_I_see_value_in_element(this: CustomWorld, expectedValue: string, selector: string): Promise<void>;
/**
* Asserts that an element matching the given selector does NOT have a specific value.
*
* ```gherkin
* Then I do not see value {string} in {string}
* ```
*
* @param unwantedValue - The value that is expected NOT to be found.
* @param selector - The CSS selector of the element to check.
*
* @example
* Then I do not see value "guest" in "input[name='userRole']"
*
* @remarks
* This step uses Playwright's `expect(locator).not.toHaveValue()` for robust assertion.
* @category Generic Assertion Steps
*/
export declare function Then_I_do_not_see_value_in_element(this: CustomWorld, unwantedValue: string, selector: string): Promise<void>;
/**
* Asserts that an `<option>` element with the given text exists in the DOM.
* It does not necessarily assert that it is selected or visible within a `<select>` element.
*
* ```gherkin
* Then I see option {string}
* ```
*
* @param optionText - The text of the option expected to exist.
*
* @example
* Then I see option "Admin"
*
* @remarks
* This step directly targets `<option>` tags by their text content.
* It asserts that at least one such option exists in the DOM.
* @category Select Option Assertion Steps
*/
export declare function Then_I_see_option(this: CustomWorld, optionText: string): Promise<void>;
/**
* Asserts that an `<option>` element with the given text is NOT visible.
*
* ```gherkin
* Then I do not see option {string}
* ```
*
* @param optionText - The text of the option expected NOT to be visible.
*
* @example
* Then I do not see option "Deprecated Feature"
*
* @remarks
* This step targets `<option>` tags by their text content and asserts that
* any matching options are not visible. This is useful for dynamically hidden options.
* @category Select Option Assertion Steps
*/
export declare function Then_I_do_not_see_option(this: CustomWorld, optionText: string): Promise<void>;
/**
* Asserts that an `<option>` element with the given text does NOT exist in the DOM.
*
* ```gherkin
* Then I do not see option {string} (regex pattern)
* ```
*
* @param optionText - The text of the option expected NOT to exist in the DOM.
*
* @example
* Then I do not see option "Super Admin"
*
* @remarks
* This step targets `<option>` tags by their text content and asserts that
* no such option is present in the DOM. This is useful for verifying removed options.
* @category Select Option Assertion Steps
*/
export declare function Then_I_do_not_see_option_exists(this: CustomWorld, optionText: string): Promise<void>;