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.
175 lines (174 loc) • 6.47 kB
TypeScript
import { CustomWorld } from "../helpers/world";
/**
* Clears all items from the browser's Local Storage for the current page's origin.
*
* ```gherkin
* When I clear all local storage
* ```
*
* @example
* When I clear all local storage
*
* @remarks
* This step executes `localStorage.clear()` in the browser's context.
* Local Storage items are persistent across browser sessions until explicitly cleared.
* This step will only affect local storage for the current page's origin.
* @category Storage Steps
*/
export declare function When_I_clear_all_local_storage(this: CustomWorld): Promise<void>;
/**
* Clears all items from the browser's Local Storage for the current page's origin.
* This is an alias for "When I clear all local storage".
*
* ```gherkin
* When I clear local storage
* ```
*
* @example
* When I clear local storage
*
* @remarks
* This step is functionally identical to {@link When_I_clear_all_local_storage | "When I clear all local storage"}.
* It executes `localStorage.clear()` in the browser's context.
* Consider using one consistent step pattern.
* @category Storage Steps
*/
export declare function When_I_clear_local_storage(this: CustomWorld): Promise<void>;
/**
* Clears all items from the browser's Session Storage for the current page's origin.
*
* ```gherkin
* When I clear session storage
* ```
*
* @example
* When I clear session storage
*
* @remarks
* This step executes `sessionStorage.clear()` in the browser's context.
* Session Storage items are cleared when the browser session ends.
* This step will only affect session storage for the current page's origin.
* @category Storage Steps
*/
export declare function When_I_clear_session_storage(this: CustomWorld): Promise<void>;
/**
* Clears all browser storage: cookies, local storage, and session storage.
* It first navigates to the `BASE_URL` to ensure the correct origin's storage is cleared.
*
* ```gherkin
* When I clear all browser storage
* ```
*
* @example
* When I clear all browser storage
*
* @remarks
* This is a comprehensive cleanup step. It uses `context.clearCookies()` for cookies
* and `page.evaluate()` to clear `localStorage` and `sessionStorage`.
* Navigating to `BASE_URL` before clearing local/session storage is crucial to ensure
* the storage for the primary application domain is targeted. Ensure `process.env.BASE_URL` is set.
* @category Storage Steps
*/
export declare function When_I_clear_all_browser_storage(this: CustomWorld): Promise<void>;
/**
* Sets a specific item in the browser's Local Storage to the given value.
*
* ```gherkin
* When I set local storage item {string} to {string}
* ```
*
* @param key - The key of the local storage item.
* @param value - The value to set for the local storage item.
*
* @example
* When I set local storage item "token" to "abc123"
*
* @remarks
* This step executes `localStorage.setItem(key, value)` in the browser's context.
* This is useful for injecting authentication tokens, feature flags, or other data
* directly into local storage for test setup.
* @category Storage Steps
*/
export declare function When_I_set_local_storage_item(this: CustomWorld, key: string, value: string): Promise<void>;
/**
* Sets a specific item in the browser's Session Storage to the given value.
*
* ```gherkin
* When I set session storage item {string} to {string}
* ```
*
* @param key - The key of the session storage item.
* @param value - The value to set for the session storage item.
*
* @example
* When I set session storage item "sessionId" to "xyz789"
*
* @remarks
* This step executes `sessionStorage.setItem(key, value)` in the browser's context.
* This is useful for injecting data that needs to persist only for the current browser session.
* @category Storage Steps
*/
export declare function When_I_set_session_storage_item(this: CustomWorld, key: string, value: string): Promise<void>;
/**
* Stores the value of the currently focused input or textarea as an alias in the test data.
*
* ```gherkin
* When I store input text as {string}
* ```
*
* @param alias - The alias name under which to store the input's value.
*
* @example
* Given I find element by placeholder text "Enter your email"
* And I type "user@example.com"
* When I store input text as "userEmail"
* Then the value of alias "userEmail" should be "user@example.com"
*
* @remarks
* This step requires an input or textarea element to be currently focused. It retrieves
* the `value` attribute of that element and stores it in {@link CustomWorld.data | this.data}
* under the provided `alias`. This is useful for capturing dynamically generated input values.
* @category Data Manipulation Steps
*/
export declare function When_I_store_input_text_as(this: CustomWorld, alias: string): Promise<void>;
/**
* Deletes a session file with the given name from the artifact directory.
* These session files are typically used for storing browser session state (e.g., cookies, local storage).
*
* ```gherkin
* When I clear session {string}
* ```
*
* @param fileName - The name of the session file to delete (e.g., "my-session.json").
*
* @example
* Given I save session as "admin-session.json"
* # ... later in a cleanup scenario
* When I clear session "admin-session.json"
*
* @remarks
* The `fileName` is resolved relative to a base directory, which defaults to
* `test-artifacts/auth-cookies` or can be configured via `this.parameters?.artifactDir`
* or `process.env.TEST_ARTIFACT_DIR`.
* This step ensures clean-up of saved session states, which is crucial for isolated tests.
* @category File System Steps
*/
export declare function When_I_clear_session_file(this: CustomWorld, fileName: string): Promise<void>;
/**
* Clears all saved session files from the authentication directory.
* This is useful for ensuring a clean slate before or after tests that rely on persistent sessions.
*
* ```gherkin
* When I clear all saved session files
* ```
*
* @example
* When I clear all saved session files
*
* @remarks
* This step reads the `e2e/support/helper/auth` directory (hardcoded path) and deletes
* all files found within it. It's crucial for managing test artifacts related to user sessions.
* Ensure the directory path is correct for your project structure.
* @category File System Steps
*/
export declare function When_I_clear_all_saved_session_files(this: CustomWorld): Promise<void>;