UNPKG

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.

354 lines (353 loc) 13.4 kB
import type { CustomWorld } from "../helpers/world"; /** * Asserts that the status code of the last API response matches the expected number. * * ```gherkin * Then I should see response status {int} * ``` * * @param expectedStatus - The expected HTTP status code (e.g., 200, 404). * * @example * When I make request to "https://api.example.com/data" * Then I should see response status 200 * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It uses `expect().toBe()` for robust assertion. * @category API Response Assertion Steps */ export declare function Then_I_should_see_response_status(this: CustomWorld, expectedStatus: number): void; /** * Asserts that the status code of the last API response does NOT match the given number. * * ```gherkin * Then I see response status is not {int} * ``` * * @param unexpectedStatus - The HTTP status code that is NOT expected. * * @example * When I make request to "https://api.example.com/data" * Then I see response status is not 404 * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It uses `expect().not.toBe()` for robust assertion. * @category API Response Assertion Steps */ export declare function Then_I_see_response_status_is_not(this: CustomWorld, unexpectedStatus: number): void; /** * Asserts that the body of the last API response contains the expected text substring. * * ```gherkin * Then I should see response body contains {string} * ``` * * @param expectedText - The substring expected to be present in the response body. * * @example * When I make request to "https://api.example.com/users" * Then I should see response body contains "John Doe" * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It uses `expect().toContain()` for robust assertion. * @category API Response Assertion Steps */ export declare function Then_I_should_see_response_body_contains(this: CustomWorld, expectedText: string): void; /** * Asserts that the body of the last API response strictly matches the expected string. * * ```gherkin * Then I see response body {string} * ``` * * @param expectedBody - The exact string expected to be the response body. * * @example * When I make request to "https://api.example.com/status" * Then I see response body "OK" * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It performs a strict equality check on the entire response body string. * @category API Response Assertion Steps */ export declare function Then_I_see_response_body(this: CustomWorld, expectedBody: string): void; /** * Asserts that the body of the last API response does NOT contain the given substring. * * ```gherkin * Then I see response body does not contain {string} * ``` * * @param unexpectedPart - The substring expected NOT to be present in the response body. * * @example * When I make request to "https://api.example.com/error" * Then I see response body does not contain "internal server error" * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It checks for the absence of the substring within the response body. * @category API Response Assertion Steps */ export declare function Then_I_see_response_body_does_not_contain(this: CustomWorld, unexpectedPart: string): void; /** * Asserts that the body of the last API response is empty (contains only whitespace or is empty). * * ```gherkin * Then I see response body is empty * ``` * * @example * When I make request to "https://api.example.com/no-content" * Then I see response body is empty * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It trims whitespace and checks if the resulting string is empty. * @category API Response Assertion Steps */ export declare function Then_I_see_response_body_is_empty(this: CustomWorld): void; /** * Asserts that the body of the last API response is NOT empty (contains non-whitespace characters). * * ```gherkin * Then I see response body is not empty * ``` * * @example * When I make request to "https://api.example.com/data" * Then I see response body is not empty * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It trims whitespace and checks if the resulting string is not empty. * @category API Response Assertion Steps */ export declare function Then_I_see_response_body_is_not_empty(this: CustomWorld): void; /** * Asserts that the body of the last API response is valid JSON. * * ```gherkin * Then I see response body is JSON * ``` * * @example * When I make request to "https://api.example.com/json-data" * Then I see response body is JSON * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It attempts to parse the response body as JSON. If parsing fails, the step fails. * @category API Response Assertion Steps */ export declare function Then_I_see_response_body_is_JSON(this: CustomWorld): void; /** * Asserts that the body of the last API response is NOT valid JSON. * * ```gherkin * Then I see response body is not JSON * ``` * * @example * When I make request to "https://api.example.com/plain-text" * Then I see response body is not JSON * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It attempts to parse the response body as JSON and expects the parsing to fail. * @category API Response Assertion Steps */ export declare function Then_I_see_response_body_is_not_JSON(this: CustomWorld): void; /** * Asserts that the body of the last API response matches the given JSON schema. * * ```gherkin * Then I see response body matches JSON schema {string} * ``` * * @param schemaPath - The path to the JSON schema file (e.g., "schemas/responseSchema.js"). * * @example * When I make request to "https://api.example.com/users/1" * Then I see response body matches JSON schema "schemas/userSchema.js" * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It dynamically imports the schema file and uses `ajv` to validate the JSON response body. * Ensure `ajv` is installed (`npm install ajv`) and your schema files are accessible. * @category API Response Assertion Steps */ export declare function Then_I_see_response_body_matches_JSON_schema_path(this: CustomWorld, schemaPath: string): Promise<void>; /** * Asserts that the body of the last API response matches the given JSON schema object directly provided in the step. * * ```gherkin * Then I see response body matches JSON schema: * """ * { "type": "object", "properties": { "id": { "type": "number" } } } * """ * ``` * * @param schema - The JSON schema object (provided as a Cucumber DocString). * * @example * When I make request to "https://api.example.com/users/latest" * Then I see response body matches JSON schema: * """ * { * "type": "object", * "properties": { * "id": { "type": "number" }, * "name": { "type": "string" } * }, * "required": ["id", "name"] * } * """ * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It expects the schema as a direct JSON string (DocString) in the Gherkin step. * Uses `ajv` to validate the JSON response body against this inline schema. * Ensure `ajv` is installed (`npm install ajv`). * @category API Response Assertion Steps */ export declare function Then_I_see_response_body_matches_JSON_schema_object(this: CustomWorld, schemaString: string): Promise<void>; /** * Asserts that a specific header in the last API response strictly equals an expected value. * * ```gherkin * Then I see response header {string} equals {string} * ``` * * @param headerName - The name of the header (case-insensitive, e.g., "Content-Type"). * @param expectedValue - The exact expected value of the header. * * @example * When I make request to "https://api.example.com/data" * Then I see response header "content-type" equals "application/json" * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It retrieves the header value and performs a strict equality check. * @category API Response Assertion Steps */ export declare function Then_I_see_response_header_equals(this: CustomWorld, headerName: string, expectedValue: string): void; /** * Asserts that a specific header in the last API response contains a given substring. * * ```gherkin * Then I see response header {string} contains {string} * ``` * * @param headerName - The name of the header (case-insensitive, e.g., "Set-Cookie"). * @param expectedPart - The substring expected to be contained within the header's value. * * @example * When I make request to "https://api.example.com/login" * Then I see response header "set-cookie" contains "session_id" * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It retrieves the header value and checks if it includes the `expectedPart`. * @category API Response Assertion Steps */ export declare function Then_I_see_response_header_contains(this: CustomWorld, headerName: string, expectedPart: string): void; /** * Asserts that a specific header in the last API response does NOT contain a given substring. * * ```gherkin * Then I see response header {string} does not contain {string} * ``` * * @param headerName - The name of the header (case-insensitive). * @param unexpectedPart - The substring expected NOT to be present within the header's value. * * @example * When I make request to "https://api.example.com/no-cache" * Then I see response header "cache-control" does not contain "no-store" * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It retrieves the header value and asserts that it does not include the `unexpectedPart`. * @category API Response Assertion Steps */ export declare function Then_I_see_response_header_does_not_contain(this: CustomWorld, headerName: string, unexpectedPart: string): void; /** * Asserts that a specific header in the last API response does NOT strictly equal a given value. * * ```gherkin * Then I see response header {string} does not equal {string} * ``` * * @param headerName - The name of the header (case-insensitive). * @param unexpectedValue - The value that is NOT expected for the header. * * @example * When I make request to "https://api.example.com/html-page" * Then I see response header "content-type" does not equal "application/json" * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It retrieves the header value and asserts that it does not strictly match `unexpectedValue`. * @category API Response Assertion Steps */ export declare function Then_I_see_response_header_does_not_equal(this: CustomWorld, headerName: string, unexpectedValue: string): void; /** * Asserts that a specific header in the last API response exists (is present). * * ```gherkin * Then I see response header {string} exists * ``` * * @param headerName - The name of the header expected to exist. * * @example * When I make request to "https://api.example.com/data" * Then I see response header "content-length" exists * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It checks if the header value is defined (not `undefined` or `null`). * @category API Response Assertion Steps */ export declare function Then_I_see_response_header_exists(this: CustomWorld, headerName: string): void; /** * Asserts that a specific header in the last API response does NOT exist (is not present). * * ```gherkin * Then I see response header {string} does not exist * ``` * * @param headerName - The name of the header expected NOT to exist. * * @example * When I make request to "https://api.example.com/simple" * Then I see response header "x-powered-by" does not exist * * @remarks * This step requires a preceding step that stores the API response in * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. * It checks if the header value is `undefined` or `null`. * @category API Response Assertion Steps */ export declare function Then_I_see_response_header_does_not_exist(this: CustomWorld, headerName: string): void;