Modules API Reference

Complete auto-generated reference for every technology module.

API module

API module: HTTP testing steps.

steplib.modules.api.register(registry)[source]

Register all API steps into the given registry.

Return type:

None

API step definitions for behave.

These steps cover the MVP: configuration, requests, and assertions. All steps delegate to pure action functions in actions.py.

steplib.modules.api.steps.register(registry)[source]

Register all API steps into the given registry.

Return type:

None

steplib.modules.api.steps.step_clear_request_data(context)[source]

Clear request-specific data.

Return type:

None

steplib.modules.api.steps.step_disable_redirects(context)[source]

Disable redirects.

Return type:

None

steplib.modules.api.steps.step_disable_ssl(context)[source]

Disable SSL verification.

Return type:

None

steplib.modules.api.steps.step_enable_redirects(context)[source]

Enable redirects.

Return type:

None

steplib.modules.api.steps.step_enable_ssl(context)[source]

Enable SSL verification.

Return type:

None

steplib.modules.api.steps.step_json_path_contains(context, path, value)[source]

Assert JSON path contains value.

Return type:

None

steplib.modules.api.steps.step_json_path_equals(context, path, value)[source]

Assert JSON path equals value.

Return type:

None

steplib.modules.api.steps.step_json_path_exists(context, path)[source]

Assert JSON path exists.

Return type:

None

steplib.modules.api.steps.step_json_path_has_length(context, path, length)[source]

Assert JSON path value has a specific length.

Return type:

None

steplib.modules.api.steps.step_json_path_is_not_null(context, path)[source]

Assert JSON path value is not null.

Return type:

None

steplib.modules.api.steps.step_json_path_is_null(context, path)[source]

Assert JSON path value is null.

Return type:

None

steplib.modules.api.steps.step_json_path_matches_regex(context, path, pattern)[source]

Assert JSON path value matches regex pattern.

Return type:

None

steplib.modules.api.steps.step_json_path_not_equals(context, path, value)[source]

Assert JSON path does not equal value.

Return type:

None

steplib.modules.api.steps.step_json_path_type(context, path, type)[source]

Assert JSON path value type.

Return type:

None

steplib.modules.api.steps.step_remove_header(context, name)[source]

Remove a default header.

Return type:

None

steplib.modules.api.steps.step_remove_query_param(context, name)[source]

Remove a query parameter.

Return type:

None

steplib.modules.api.steps.step_response_body_contains(context, text)[source]

Assert response body contains text.

Return type:

None

steplib.modules.api.steps.step_response_body_not_contains(context, text)[source]

Assert response body does not contain text.

Return type:

None

steplib.modules.api.steps.step_response_body_valid_json(context)[source]

Assert response body is valid JSON.

Return type:

None

steplib.modules.api.steps.step_response_content_type(context, content_type)[source]

Assert content type equals.

Return type:

None

steplib.modules.api.steps.step_response_content_type_contains(context, content_type)[source]

Assert content type contains.

Return type:

None

steplib.modules.api.steps.step_response_header_contains(context, name, value)[source]

Assert response header contains substring.

Return type:

None

steplib.modules.api.steps.step_response_header_equals(context, name, value)[source]

Assert response header equals value.

Return type:

None

steplib.modules.api.steps.step_response_header_exists(context, name)[source]

Assert response header exists.

Return type:

None

steplib.modules.api.steps.step_response_header_not_equals(context, name, value)[source]

Assert response header does not equal value.

Return type:

None

steplib.modules.api.steps.step_response_header_not_exists(context, name)[source]

Assert response header does not exist.

Return type:

None

steplib.modules.api.steps.step_response_matches_schema(context)[source]

Validate response against a JSON Schema from step text.

Return type:

None

steplib.modules.api.steps.step_response_matches_table(context)[source]

Compare the response JSON with a behave table.

Uses behave-tables to convert context.table to dicts and behave-kit for soft assertions. Both require their respective extras.

Return type:

None

steplib.modules.api.steps.step_response_status(context, status)[source]

Assert response status code.

Return type:

None

steplib.modules.api.steps.step_response_status_in(context, statuses)[source]

Assert response status is in a list.

Return type:

None

steplib.modules.api.steps.step_response_time_between(context, min, max)[source]

Assert response time is between min and max seconds.

Return type:

None

steplib.modules.api.steps.step_response_time_greater_than(context, seconds)[source]

Assert response time is greater than N seconds.

Return type:

None

steplib.modules.api.steps.step_response_time_less_than(context, seconds)[source]

Assert response time is less than N seconds.

Return type:

None

steplib.modules.api.steps.step_save_cookies(context)[source]

Save cookies from the response.

Return type:

None

steplib.modules.api.steps.step_send_form_data(context, method, url)[source]

Send an HTTP request with form data from a behave table.

Return type:

None

steplib.modules.api.steps.step_send_json_body(context, method, url)[source]

Send an HTTP request with a JSON body from step text.

Return type:

None

steplib.modules.api.steps.step_send_request(context, method, url)[source]

Send an HTTP request.

Return type:

None

steplib.modules.api.steps.step_send_request_with_body(context, method, url)[source]

Send an HTTP request with a body from the step’s text.

Return type:

None

steplib.modules.api.steps.step_send_with_headers(context, method, url)[source]

Send an HTTP request with extra headers from a behave table.

Return type:

None

steplib.modules.api.steps.step_send_with_params(context, method, url)[source]

Send an HTTP request with query params from a behave table.

Return type:

None

steplib.modules.api.steps.step_set_base_url(context, url)[source]

Set the API base URL.

Return type:

None

steplib.modules.api.steps.step_set_basic_auth(context, user, password)[source]

Set basic auth credentials.

Return type:

None

steplib.modules.api.steps.step_set_bearer_token(context, token)[source]

Set a bearer token.

Return type:

None

steplib.modules.api.steps.step_set_header(context, name, value)[source]

Set a default API header.

Return type:

None

steplib.modules.api.steps.step_set_proxy(context, url)[source]

Set the proxy URL.

Return type:

None

steplib.modules.api.steps.step_set_query_param(context, name, value)[source]

Set a query parameter.

Return type:

None

steplib.modules.api.steps.step_set_timeout(context, seconds)[source]

Set the API timeout.

Return type:

None

steplib.modules.api.steps.step_store_header(context, name, variable)[source]

Store a response header as a variable.

Return type:

None

steplib.modules.api.steps.step_store_json_path(context, path, variable)[source]

Store a JSON path value as a variable.

Return type:

None

steplib.modules.api.steps.step_store_response_body(context, variable)[source]

Store the response body as a variable.

Return type:

None

steplib.modules.api.steps.step_store_response_time(context, variable)[source]

Store response time as a variable.

Return type:

None

steplib.modules.api.steps.step_store_status(context, variable)[source]

Store the response status as a variable.

Return type:

None

steplib.modules.api.steps.step_use_variable_as_header(context, variable, name)[source]

Set a header from a stored variable.

Return type:

None

steplib.modules.api.steps.step_use_variable_as_param(context, variable, name)[source]

Set a query param from a stored variable.

Return type:

None

steplib.modules.api.steps.step_variable_equals(context, variable, value)[source]

Assert stored variable equals value.

Return type:

None

Pure action functions for the API module.

These functions contain the actual logic and are called by step definitions. They operate on ApiContext and are fully testable without behave.

steplib.modules.api.actions.api_assert_body_contains(api_ctx, text)[source]

Assert that the last response body contains text.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • text (str) – The substring to search for.

Raises:

AssertionError – If no response exists or the body does not contain text.

Return type:

None

steplib.modules.api.actions.api_assert_body_not_contains(api_ctx, text)[source]

Assert that the last response body does NOT contain text.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • text (str) – The substring that should not be present.

Raises:

AssertionError – If no response exists or the body contains text.

Return type:

None

steplib.modules.api.actions.api_assert_content_type(api_ctx, expected)[source]

Assert that the Content-Type response header equals expected.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • expected (str) – The expected content type value.

Raises:

AssertionError – If no response exists or the content type does not match.

Return type:

None

steplib.modules.api.actions.api_assert_content_type_contains(api_ctx, substring)[source]

Assert that the Content-Type response header contains substring.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • substring (str) – The substring to search for in the Content-Type header.

Raises:

AssertionError – If no response exists or the content type does not contain the substring.

Return type:

None

steplib.modules.api.actions.api_assert_header_contains(api_ctx, name, substring)[source]

Assert that a response header contains substring.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • name (str) – The header name.

  • substring (str) – The substring to search for.

Raises:

AssertionError – If no response exists, the header is missing, or the value does not contain the substring.

Return type:

None

steplib.modules.api.actions.api_assert_header_equals(api_ctx, name, expected)[source]

Assert that a response header equals expected.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • name (str) – The header name.

  • expected (str) – The expected header value.

Raises:

AssertionError – If no response exists, the header is missing, or the value does not match.

Return type:

None

steplib.modules.api.actions.api_assert_header_exists(api_ctx, name)[source]

Assert that a response header exists.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • name (str) – The header name.

Raises:

AssertionError – If no response exists or the header is missing.

Return type:

None

steplib.modules.api.actions.api_assert_header_not_equals(api_ctx, name, value)[source]

Assert that a response header does NOT equal value.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • name (str) – The header name.

  • value (str) – The value that should not match.

Raises:

AssertionError – If no response exists, the header is missing, or the value matches.

Return type:

None

steplib.modules.api.actions.api_assert_header_not_exists(api_ctx, name)[source]

Assert that a response header does NOT exist.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • name (str) – The header name.

Raises:

AssertionError – If no response exists or the header is present.

Return type:

None

steplib.modules.api.actions.api_assert_json_path_contains(api_ctx, path, value)[source]

Assert that a JSON path value contains value (for lists or strings).

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • path (str) – A JSONPath expression starting with $.

  • value (str) – The value that should be contained.

Raises:

AssertionError – If no response exists or the value is not contained.

Return type:

None

steplib.modules.api.actions.api_assert_json_path_equals(api_ctx, path, expected)[source]

Assert that a JSON path in the last response equals expected.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • path (str) – A JSONPath expression starting with $.

  • expected (str) – The expected value (compared as string).

Raises:

AssertionError – If no response exists or the value does not match.

Return type:

None

steplib.modules.api.actions.api_assert_json_path_exists(api_ctx, path)[source]

Assert that a JSON path exists in the last response.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • path (str) – A JSONPath expression starting with $.

Raises:

AssertionError – If no response exists or the path does not exist.

Return type:

None

steplib.modules.api.actions.api_assert_json_path_has_length(api_ctx, path, expected)[source]

Assert that a JSON path value has a specific length.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • path (str) – A JSONPath expression starting with $.

  • expected (int) – The expected length.

Raises:

AssertionError – If no response exists or the length does not match.

Return type:

None

steplib.modules.api.actions.api_assert_json_path_is_not_null(api_ctx, path)[source]

Assert that a JSON path value is not null.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • path (str) – A JSONPath expression starting with $.

Raises:

AssertionError – If no response exists or the value is null.

Return type:

None

steplib.modules.api.actions.api_assert_json_path_is_null(api_ctx, path)[source]

Assert that a JSON path value is null.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • path (str) – A JSONPath expression starting with $.

Raises:

AssertionError – If no response exists or the value is not null.

Return type:

None

steplib.modules.api.actions.api_assert_json_path_matches_regex(api_ctx, path, pattern)[source]

Assert that a JSON path string value matches a regex pattern.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • path (str) – A JSONPath expression starting with $.

  • pattern (str) – A regular expression pattern to match.

Raises:

AssertionError – If no response exists or the value does not match.

Return type:

None

steplib.modules.api.actions.api_assert_json_path_not_equals(api_ctx, path, value)[source]

Assert that a JSON path value does NOT equal value.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • path (str) – A JSONPath expression starting with $.

  • value (str) – The value that should not match.

Raises:

AssertionError – If no response exists or the value matches.

Return type:

None

steplib.modules.api.actions.api_assert_json_path_type(api_ctx, path, expected_type)[source]

Assert that the value at a JSON path is of a specific type.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • path (str) – A JSONPath expression starting with $.

  • expected_type (str) – One of "str", "int", "float", "bool", "list", "dict", "NoneType".

Raises:
  • AssertionError – If no response exists or the type does not match.

  • ValueError – If expected_type is not a recognized type name.

Return type:

None

steplib.modules.api.actions.api_assert_json_schema(api_ctx, schema)[source]

Validate the last response body against a JSON Schema (draft-07 subset).

Supports: type, properties, required, items, enum, minimum, maximum, minLength, maxLength, pattern.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • schema (dict[str, Any]) – The JSON Schema dictionary.

Raises:

AssertionError – If no response exists or validation fails.

Return type:

None

steplib.modules.api.actions.api_assert_json_valid(api_ctx)[source]

Assert that the last response body is valid JSON.

Parameters:

api_ctx (ApiContext) – The API context to operate on.

Raises:

AssertionError – If no response exists or the body is not valid JSON.

Return type:

None

steplib.modules.api.actions.api_assert_response_time_between(api_ctx, min_s, max_s)[source]

Assert that the last response time is between min_s and max_s seconds.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • min_s (float) – The minimum acceptable response time in seconds.

  • max_s (float) – The maximum acceptable response time in seconds.

Raises:

AssertionError – If no response exists or the response time is out of range.

Return type:

None

steplib.modules.api.actions.api_assert_response_time_greater_than(api_ctx, seconds)[source]

Assert that the last response took more than seconds seconds.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • seconds (float) – The minimum acceptable response time in seconds.

Raises:

AssertionError – If no response exists or the response was too fast.

Return type:

None

steplib.modules.api.actions.api_assert_response_time_less_than(api_ctx, seconds)[source]

Assert that the last response took less than seconds seconds.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • seconds (float) – The maximum acceptable response time in seconds.

Raises:

AssertionError – If no response exists or the response was too slow.

Return type:

None

steplib.modules.api.actions.api_assert_status(api_ctx, expected)[source]

Assert that the last response status matches expected.

Raises:

AssertionError – If the status does not match or no response exists.

Return type:

None

steplib.modules.api.actions.api_assert_status_in(api_ctx, expected)[source]

Assert that the last response status is one of the expected values.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • expected (list[int]) – A list of acceptable status codes.

Raises:

AssertionError – If no response exists or the status is not in the list.

Return type:

None

steplib.modules.api.actions.api_assert_variable_equals(api_ctx, variable, expected)[source]

Assert that a stored variable equals expected (compared as string).

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • variable (str) – The variable name.

  • expected (str) – The expected value.

Raises:

AssertionError – If the variable does not exist or the value does not match.

Return type:

None

steplib.modules.api.actions.api_clear_request_data(api_ctx)[source]

Reset request-specific data: headers, params, auth, cookies, body.

Keeps base_url, timeout, ssl_verify, allow_redirects, and proxies.

Parameters:

api_ctx (ApiContext) – The API context to operate on.

Return type:

None

steplib.modules.api.actions.api_remove_header(api_ctx, name)[source]

Remove a default header from the context.

Header lookup is case-insensitive per RFC 7230.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • name (str) – The header name to remove.

Raises:

KeyError – If the header does not exist.

Return type:

None

steplib.modules.api.actions.api_remove_query_param(api_ctx, name)[source]

Remove a query parameter from the default params.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • name (str) – The query parameter name to remove.

Raises:

KeyError – If the parameter does not exist.

Return type:

None

steplib.modules.api.actions.api_save_cookies(api_ctx)[source]

Extract cookies from the last response and store them in the context.

Parameters:

api_ctx (ApiContext) – The API context to operate on.

Raises:

AssertionError – If no response exists.

Return type:

None

steplib.modules.api.actions.api_send(api_ctx, method, url, body=None, *, params=None, extra_headers=None)[source]

Send an HTTP request and store the response in api_ctx.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • method (str) – HTTP method (e.g. "GET", "POST").

  • url (str) – URL (relative URLs are resolved against base_url).

  • body (str | bytes | None) – Optional request body as string or bytes.

  • params (dict[str, str] | None) – Optional per-request query params (overrides context defaults).

  • extra_headers (dict[str, str] | None) – Optional per-request headers merged with defaults.

Return type:

Response

Returns:

The Response object.

Raises:

RuntimeError – If no HTTP client is configured.

steplib.modules.api.actions.api_send_form(api_ctx, method, url, data)[source]

Send an HTTP request with form-encoded data.

Sets Content-Type: application/x-www-form-urlencoded and encodes data as the request body.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • method (str) – HTTP method (typically "POST" or "PUT").

  • url (str) – Target URL.

  • data (dict[str, str]) – Form fields as a dict.

Return type:

Response

Returns:

The Response object.

steplib.modules.api.actions.api_send_json(api_ctx, method, url, data)[source]

Send an HTTP request with a JSON body.

Sets Content-Type: application/json. If data is a dict, it is serialized to JSON. If it is a string, it is sent as-is.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • method (str) – HTTP method.

  • url (str) – Target URL.

  • data (str | dict[str, Any]) – JSON body as a dict or pre-serialized string.

Return type:

Response

Returns:

The Response object.

steplib.modules.api.actions.api_set_allow_redirects(api_ctx, allow)[source]

Enable or disable following redirects.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • allow (bool) – Whether to follow redirects.

Return type:

None

steplib.modules.api.actions.api_set_base_url(api_ctx, url)[source]

Set the base URL for subsequent requests.

Return type:

None

steplib.modules.api.actions.api_set_basic_auth(api_ctx, username, password)[source]

Set basic authentication credentials for subsequent requests.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • username (str) – The username for basic auth.

  • password (str) – The password for basic auth.

Return type:

None

steplib.modules.api.actions.api_set_bearer_token(api_ctx, token)[source]

Set a Bearer token in the Authorization header.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • token (str) – The bearer token value.

Return type:

None

steplib.modules.api.actions.api_set_header(api_ctx, name, value)[source]

Set a default header that will be sent with every request.

Return type:

None

steplib.modules.api.actions.api_set_proxy(api_ctx, url)[source]

Set a proxy URL for both HTTP and HTTPS requests.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • url (str) – The proxy URL (e.g. "http://proxy:8080").

Return type:

None

steplib.modules.api.actions.api_set_query_param(api_ctx, name, value)[source]

Set a default query parameter sent with every request.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • name (str) – The query parameter name.

  • value (str) – The query parameter value.

Return type:

None

steplib.modules.api.actions.api_set_ssl_verify(api_ctx, verify)[source]

Enable or disable SSL certificate verification.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • verify (bool) – Whether to verify SSL certificates.

Return type:

None

steplib.modules.api.actions.api_set_timeout(api_ctx, seconds)[source]

Set the request timeout in seconds.

Return type:

None

steplib.modules.api.actions.api_store(api_ctx, variable, value)[source]

Store a value under variable name in the API context.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • variable (str) – The variable name.

  • value (Any) – The value to store.

Return type:

None

steplib.modules.api.actions.api_store_header(api_ctx, name, variable)[source]

Store a response header value as variable.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • name (str) – The header name.

  • variable (str) – The variable name to store the header value under.

Raises:

AssertionError – If no response exists or the header is missing.

Return type:

None

steplib.modules.api.actions.api_store_json_path(api_ctx, path, variable)[source]

Store the value at a JSON path from the last response as variable.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • path (str) – A JSONPath expression starting with $.

  • variable (str) – The variable name to store the value under.

Raises:

AssertionError – If no response exists.

Return type:

None

steplib.modules.api.actions.api_store_response_body(api_ctx, variable)[source]

Store the last response body as variable.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • variable (str) – The variable name to store the body under.

Raises:

AssertionError – If no response exists.

Return type:

None

steplib.modules.api.actions.api_store_response_time(api_ctx, variable)[source]

Store the last response time in milliseconds as variable.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • variable (str) – The variable name to store the elapsed time under.

Raises:

AssertionError – If no response exists.

Return type:

None

steplib.modules.api.actions.api_store_status(api_ctx, variable)[source]

Store the last response status code as variable.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • variable (str) – The variable name to store the status code under.

Raises:

AssertionError – If no response exists.

Return type:

None

steplib.modules.api.actions.api_use_variable_as_header(api_ctx, name, variable)[source]

Set a header from a stored variable.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • name (str) – The header name to set.

  • variable (str) – The variable name to read the value from.

Raises:

KeyError – If the variable does not exist.

Return type:

None

steplib.modules.api.actions.api_use_variable_as_query_param(api_ctx, name, variable)[source]

Set a query parameter from a stored variable.

Parameters:
  • api_ctx (ApiContext) – The API context to operate on.

  • name (str) – The query parameter name to set.

  • variable (str) – The variable name to read the value from.

Raises:

KeyError – If the variable does not exist.

Return type:

None

ApiContext: per-scenario HTTP state for the API module.

class steplib.modules.api.context.ApiContext(client=None, base_url='', default_headers=<factory>, query_params=<factory>, auth=None, cookies=<factory>, timeout=None, allow_redirects=True, ssl_verify=True, proxies=<factory>, last_request=None, last_response=None, variables=<factory>, backend='stdlib')[source]

Bases: object

Holds all HTTP state for a scenario.

Lives at context.steplib.api and is reset between scenarios.

client

The HTTP client implementation (defaults to UrllibHTTPClient).

base_url

The base URL for resolving relative URLs.

default_headers

Headers sent with every request.

query_params

Default query parameters sent with every request.

auth

Optional (username, password) tuple for basic auth.

cookies

Cookies sent with every request.

timeout

Request timeout in seconds (None = no timeout).

allow_redirects

Whether to follow redirects (default True).

ssl_verify

Whether to verify SSL certificates (default True).

proxies

Proxy mappings (e.g. {"http": "http://proxy:8080"}).

last_request

The most recent Request sent.

last_response

The most recent Response received.

variables

User-defined variables stored by steps.

backend

The backend name (e.g. "stdlib", "httpx").

allow_redirects: bool = True
auth: tuple[str, str] | None = None
backend: str = 'stdlib'
base_url: str = ''
cleanup()[source]

Close any resources held by the client.

Return type:

None

client: HTTPClient | None = None
cookies: dict[str, str]
default_headers: dict[str, str]
last_request: Request | None = None
last_response: Response | None = None
proxies: dict[str, str]
query_params: dict[str, str]
reset()[source]

Reset per-scenario state, keeping the client and configuration.

Return type:

None

ssl_verify: bool = True
timeout: float | None = None
variables: dict[str, Any]

HTTP client abstraction: protocol, stdlib fallback, and lazy httpx/requests clients.

class steplib.modules.api.client.HTTPClient(*args, **kwargs)[source]

Bases: Protocol

Protocol for HTTP client implementations.

request(method, url, *, headers=None, body=None, timeout=None, params=None, auth=None, cookies=None, allow_redirects=True, verify=True, proxies=None)[source]

Send an HTTP request and return the response.

Parameters:
  • method (str) – The HTTP method (e.g. "GET").

  • url (str) – The target URL.

  • headers (dict[str, str] | None) – Optional request headers.

  • body (bytes | None) – Optional request body as bytes.

  • timeout (float | None) – Optional timeout in seconds.

  • params (dict[str, str] | None) – Optional query parameters.

  • auth (tuple[str, str] | None) – Optional (username, password) tuple for basic auth.

  • cookies (dict[str, str] | None) – Optional cookies to send.

  • allow_redirects (bool) – Whether to follow redirects (default True).

  • verify (bool) – Whether to verify SSL certificates (default True).

  • proxies (dict[str, str] | None) – Optional proxy mappings.

Return type:

Response

Returns:

The Response object.

class steplib.modules.api.client.HttpxHTTPClient[source]

Bases: object

HTTP client backed by httpx (requires the [api] extra).

request(method, url, *, headers=None, body=None, timeout=None, params=None, auth=None, cookies=None, allow_redirects=True, verify=True, proxies=None)[source]

Send an HTTP request using httpx.

Parameters:
  • method (str) – The HTTP method (e.g. "GET").

  • url (str) – The target URL.

  • headers (dict[str, str] | None) – Optional request headers.

  • body (bytes | None) – Optional request body as bytes.

  • timeout (float | None) – Optional timeout in seconds.

  • params (dict[str, str] | None) – Optional query parameters.

  • auth (tuple[str, str] | None) – Optional (username, password) for basic auth.

  • cookies (dict[str, str] | None) – Optional cookies to send.

  • allow_redirects (bool) – Whether to follow redirects (default True).

  • verify (bool) – Whether to verify SSL certificates (default True).

  • proxies (dict[str, str] | None) – Optional proxy mappings.

Return type:

Response

Returns:

The Response object.

class steplib.modules.api.client.NoRedirectHandler[source]

Bases: HTTPRedirectHandler

Redirect handler that raises HTTPError instead of following redirects.

redirect_request(req, fp, code, msg, headers, newurl)[source]

Reject all redirects by raising an HTTPError with the real status and headers.

Return type:

None

class steplib.modules.api.client.Request(method, url, headers=<factory>, body=None)[source]

Bases: object

Immutable HTTP request representation.

method

The HTTP method (e.g. "GET", "POST").

url

The resolved URL.

headers

Request headers.

body

Optional request body as bytes.

body: bytes | None
headers: dict[str, str]
method: str
url: str
class steplib.modules.api.client.RequestsHTTPClient[source]

Bases: object

HTTP client backed by requests (requires the requests package).

request(method, url, *, headers=None, body=None, timeout=None, params=None, auth=None, cookies=None, allow_redirects=True, verify=True, proxies=None)[source]

Send an HTTP request using requests.

Parameters:
  • method (str) – The HTTP method (e.g. "GET").

  • url (str) – The target URL.

  • headers (dict[str, str] | None) – Optional request headers.

  • body (bytes | None) – Optional request body as bytes.

  • timeout (float | None) – Optional timeout in seconds.

  • params (dict[str, str] | None) – Optional query parameters.

  • auth (tuple[str, str] | None) – Optional (username, password) for basic auth.

  • cookies (dict[str, str] | None) – Optional cookies to send.

  • allow_redirects (bool) – Whether to follow redirects (default True).

  • verify (bool) – Whether to verify SSL certificates (default True).

  • proxies (dict[str, str] | None) – Optional proxy mappings.

Return type:

Response

Returns:

The Response object.

class steplib.modules.api.client.Response(status, headers=<factory>, body=b'', elapsed_ms=0.0)[source]

Bases: object

Immutable HTTP response representation.

status

The HTTP status code.

headers

Response headers.

body

The raw response body as bytes.

elapsed_ms

The request duration in milliseconds.

body: bytes
elapsed_ms: float
headers: dict[str, str]
json()[source]

Parse the body as JSON.

Return type:

Any

Returns:

The parsed JSON data.

Raises:

json.JSONDecodeError – If the body is not valid JSON.

status: int
property text: str

Decode the body as UTF-8 text.

class steplib.modules.api.client.UrllibHTTPClient[source]

Bases: object

HTTP client using only the standard library (urllib).

request(method, url, *, headers=None, body=None, timeout=None, params=None, auth=None, cookies=None, allow_redirects=True, verify=True, proxies=None)[source]

Send an HTTP request using urllib.

Parameters:
  • method (str) – The HTTP method (e.g. "GET").

  • url (str) – The target URL.

  • headers (dict[str, str] | None) – Optional request headers.

  • body (bytes | None) – Optional request body as bytes.

  • timeout (float | None) – Optional timeout in seconds.

  • params (dict[str, str] | None) – Optional query parameters appended to the URL.

  • auth (tuple[str, str] | None) – Optional (username, password) for basic auth.

  • cookies (dict[str, str] | None) – Optional cookies sent as a Cookie header.

  • allow_redirects (bool) – Whether to follow redirects (default True).

  • verify (bool) – Whether to verify SSL certificates (default True).

  • proxies (dict[str, str] | None) – Optional proxy mappings.

Return type:

Response

Returns:

The Response object.

steplib.modules.api.client.get_client(backend='stdlib')[source]

Return an HTTP client for the given backend.

Parameters:

backend (str) – "stdlib", "httpx", or "requests".

Return type:

HTTPClient

Returns:

An HTTPClient instance for the requested backend.

Raises:

MissingDependencyError – If the backend’s dependency is not installed.

Transformers for the API module: HttpMethod, Url, JsonPath.

class steplib.modules.api.transforms.HttpMethod(method)[source]

Bases: object

Validates and normalizes HTTP method strings.

class steplib.modules.api.transforms.JsonPath(path)[source]

Bases: object

Simple JSONPath evaluator supporting $.path.to.value syntax.

Parameters:

path (str) – A JSONPath expression starting with $ (e.g. "$.users[0].name").

evaluate(data)[source]

Evaluate the path against data and return the matched value.

Parameters:

data (Any) – The JSON data to traverse (typically a dict or list).

Return type:

Any

Returns:

The value at the matched path.

Raises:

KeyError – If the path does not exist in data.

class steplib.modules.api.transforms.Url(url, base_url='')[source]

Bases: object

Represents a URL, resolving relative paths against a base URL.

Parameters:
  • url (str) – The URL string (absolute or relative).

  • base_url (str) – Optional base URL for resolving relative URLs.

steplib.modules.api.transforms.parse_json(text)[source]

Parse a JSON string, raising ValueError on invalid input.

Parameters:

text (str) – A JSON string.

Return type:

Any

Returns:

The parsed JSON data.

Raises:

json.JSONDecodeError – If the text is not valid JSON.

Web module

Web module: browser testing steps with Selenium.

steplib.modules.web.register(registry)[source]

Register all web steps into the given registry.

Return type:

None

Web step definitions for behave.

steplib.modules.web.steps.register(registry)[source]

Register all web steps into the given registry.

Return type:

None

steplib.modules.web.steps.step_clear_input(context, by, value)[source]

Clear an input element.

Return type:

None

steplib.modules.web.steps.step_click_element(context, by, value)[source]

Click an element.

Return type:

None

Assert cookie exists.

Return type:

None

Delete a cookie.

Return type:

None

steplib.modules.web.steps.step_element_attribute_equals(context, by, value, attr, expected)[source]

Assert element attribute equals.

Return type:

None

steplib.modules.web.steps.step_element_enabled(context, by, value)[source]

Assert element is enabled.

Return type:

None

steplib.modules.web.steps.step_element_not_present(context, by, value)[source]

Assert element is not present.

Return type:

None

steplib.modules.web.steps.step_element_present(context, by, value)[source]

Assert element is present.

Return type:

None

steplib.modules.web.steps.step_element_text_equals(context, by, value, expected)[source]

Assert element text equals.

Return type:

None

steplib.modules.web.steps.step_element_visible(context, by, value)[source]

Assert element is visible.

Return type:

None

steplib.modules.web.steps.step_navigate(context, url)[source]

Navigate to a URL.

Return type:

None

steplib.modules.web.steps.step_navigate_back(context)[source]

Navigate back.

Return type:

None

steplib.modules.web.steps.step_navigate_forward(context)[source]

Navigate forward.

Return type:

None

steplib.modules.web.steps.step_page_contains(context, text)[source]

Assert page contains text.

Return type:

None

steplib.modules.web.steps.step_page_not_contains(context, text)[source]

Assert page does not contain text.

Return type:

None

steplib.modules.web.steps.step_page_title(context, title)[source]

Assert page title.

Return type:

None

steplib.modules.web.steps.step_refresh_page(context)[source]

Refresh the page.

Return type:

None

steplib.modules.web.steps.step_select_option(context, option, by, value)[source]

Select an option from a dropdown.

Return type:

None

steplib.modules.web.steps.step_set_implicit_wait(context, seconds)[source]

Set implicit wait.

Return type:

None

steplib.modules.web.steps.step_set_page_load_timeout(context, seconds)[source]

Set page load timeout.

Return type:

None

steplib.modules.web.steps.step_set_web_base_url(context, url)[source]

Set the web base URL.

Return type:

None

steplib.modules.web.steps.step_set_window_size(context, width, height)[source]

Set window size.

Return type:

None

Store cookie as variable.

Return type:

None

steplib.modules.web.steps.step_store_current_url(context, variable)[source]

Store current URL as variable.

Return type:

None

steplib.modules.web.steps.step_store_element_attribute(context, attr, by, value, variable)[source]

Store element attribute as variable.

Return type:

None

steplib.modules.web.steps.step_store_element_text(context, by, value, variable)[source]

Store element text as variable.

Return type:

None

steplib.modules.web.steps.step_switch_to_default(context)[source]

Switch to default content.

Return type:

None

steplib.modules.web.steps.step_switch_to_frame(context, by, value)[source]

Switch to frame.

Return type:

None

steplib.modules.web.steps.step_take_screenshot(context, filename)[source]

Take a screenshot.

Return type:

None

steplib.modules.web.steps.step_type_text(context, text, by, value)[source]

Type text into an input.

Return type:

None

steplib.modules.web.steps.step_url_contains(context, fragment)[source]

Assert URL contains fragment.

Return type:

None

steplib.modules.web.steps.step_wait_for_element(context, by, value)[source]

Wait for element to be present.

Return type:

None

steplib.modules.web.steps.step_wait_for_element_visible(context, by, value)[source]

Wait for element to be visible.

Return type:

None

steplib.modules.web.steps.step_wait_for_text(context, text)[source]

Wait for text to appear on page.

Return type:

None

Pure action functions for the Web module.

Assert a cookie exists.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • name (str) – The cookie name.

Raises:
Return type:

None

steplib.modules.web.actions.web_assert_element_attribute(web_ctx, by, value, attr, expected)[source]

Assert an element’s attribute equals expected.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

  • attr (str) – The attribute name.

  • expected (str) – The expected attribute value.

Raises:
Return type:

None

steplib.modules.web.actions.web_assert_element_enabled(web_ctx, by, value)[source]

Assert an element is enabled.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

Raises:
Return type:

None

steplib.modules.web.actions.web_assert_element_not_present(web_ctx, by, value)[source]

Assert an element is NOT present on the page.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

Raises:
Return type:

None

steplib.modules.web.actions.web_assert_element_present(web_ctx, by, value)[source]

Assert an element is present on the page.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name (e.g. "id", "xpath").

  • value (str) – The locator value.

Raises:
Return type:

None

steplib.modules.web.actions.web_assert_element_text_equals(web_ctx, by, value, expected)[source]

Assert an element’s text content equals expected.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

  • expected (str) – The expected text content.

Raises:
Return type:

None

steplib.modules.web.actions.web_assert_element_visible(web_ctx, by, value)[source]

Assert an element is visible on the page.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

Raises:
Return type:

None

steplib.modules.web.actions.web_assert_page_contains(web_ctx, text)[source]

Assert the page source contains text.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • text (str) – The substring to search for in the page source.

Raises:
Return type:

None

steplib.modules.web.actions.web_assert_page_not_contains(web_ctx, text)[source]

Assert the page source does NOT contain text.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • text (str) – The substring that should not be present.

Raises:
Return type:

None

steplib.modules.web.actions.web_assert_title(web_ctx, expected)[source]

Assert the page title equals expected.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • expected (str) – The expected page title.

Raises:
Return type:

None

steplib.modules.web.actions.web_assert_url_contains(web_ctx, fragment)[source]

Assert the current URL contains fragment.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • fragment (str) – The substring to search for in the current URL.

Raises:
Return type:

None

steplib.modules.web.actions.web_clear_input(web_ctx, by, value)[source]

Clear an input element.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_click(web_ctx, by, value)[source]

Click an element on the page.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name (e.g. "id", "xpath").

  • value (str) – The locator value.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

Delete a cookie by name.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • name (str) – The cookie name.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_navigate(web_ctx, url)[source]

Navigate to url, resolving relative URLs against the base URL.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • url (str) – The URL (absolute or relative).

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_navigate_back(web_ctx)[source]

Navigate back in browser history.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_navigate_forward(web_ctx)[source]

Navigate forward in browser history.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_refresh_page(web_ctx)[source]

Refresh the current page.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_select_option(web_ctx, by, value, option)[source]

Select an option from a <select> element by visible text.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

  • option (str) – The visible text of the option to select.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_set_base_url(web_ctx, url)[source]

Set the base URL for subsequent navigations.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • url (str) – The base URL.

Return type:

None

steplib.modules.web.actions.web_set_implicit_wait(web_ctx, seconds)[source]

Set the implicit wait time.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • seconds (float) – The implicit wait in seconds.

Return type:

None

steplib.modules.web.actions.web_set_page_load_timeout(web_ctx, seconds)[source]

Set the page load timeout.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • seconds (float) – The page load timeout in seconds.

Return type:

None

steplib.modules.web.actions.web_set_window_size(web_ctx, width, height)[source]

Set the browser window size.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • width (int) – The window width in pixels.

  • height (int) – The window height in pixels.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_store(web_ctx, variable, value)[source]

Store a value under variable name in the Web context.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • variable (str) – The variable name.

  • value (Any) – The value to store.

Return type:

None

Store a cookie value as a variable.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • name (str) – The cookie name.

  • variable (str) – The variable name to store under.

Raises:
Return type:

None

steplib.modules.web.actions.web_store_current_url(web_ctx, variable)[source]

Store the current URL as a variable.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • variable (str) – The variable name to store under.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_store_element_attribute(web_ctx, by, value, attr, variable)[source]

Store an element’s attribute value as a variable.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

  • attr (str) – The attribute name.

  • variable (str) – The variable name to store under.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_store_element_text(web_ctx, by, value, variable)[source]

Store an element’s text content as a variable.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

  • variable (str) – The variable name to store under.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_switch_to_default(web_ctx)[source]

Switch back to the default content from a frame.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_switch_to_frame(web_ctx, by, value)[source]

Switch to an iframe element.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_take_screenshot(web_ctx, filename)[source]

Take a screenshot and save it.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • filename (str) – The filename (or full path) for the screenshot.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_type_text(web_ctx, by, value, text)[source]

Type text into an input element, clearing it first.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

  • text (str) – The text to type.

Raises:

RuntimeError – If no browser driver is configured.

Return type:

None

steplib.modules.web.actions.web_wait_for_element(web_ctx, by, value, timeout=None)[source]

Wait until an element is present on the page.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

  • timeout (float | None) – Maximum wait in seconds. Defaults to implicit_wait.

Raises:
Return type:

None

steplib.modules.web.actions.web_wait_for_element_visible(web_ctx, by, value, timeout=None)[source]

Wait until an element is visible on the page.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • by (str) – The Selenium By strategy name.

  • value (str) – The locator value.

  • timeout (float | None) – Maximum wait in seconds. Defaults to implicit_wait.

Raises:
Return type:

None

steplib.modules.web.actions.web_wait_for_text(web_ctx, text, timeout=None)[source]

Wait until the page source contains text.

Parameters:
  • web_ctx (WebContext) – The web context to operate on.

  • text (str) – The text to wait for.

  • timeout (float | None) – Maximum wait in seconds. Defaults to implicit_wait.

Raises:
Return type:

None

WebContext: per-scenario browser state for the Web module.

class steplib.modules.web.context.WebContext(driver=None, base_url='', implicit_wait=10.0, page_load_timeout=30.0, window_size=None, screenshots_dir='', last_screenshot='', variables=<factory>, backend='selenium')[source]

Bases: object

Holds all browser state for a scenario.

Lives at context.steplib.web and is reset between scenarios.

driver

The browser driver instance (e.g. SeleniumDriver).

base_url

The base URL for resolving relative navigations.

implicit_wait

Implicit wait time in seconds for element lookups.

page_load_timeout

Page load timeout in seconds.

window_size

Optional (width, height) tuple for the browser window.

screenshots_dir

Directory path where screenshots are saved.

last_screenshot

Path to the last screenshot taken.

variables

User-defined variables stored by steps.

backend

The backend name (e.g. "selenium").

backend: str = 'selenium'
base_url: str = ''
cleanup()[source]

Close the browser driver if it exists.

Return type:

None

driver: Any = None
implicit_wait: float = 10.0
last_screenshot: str = ''
page_load_timeout: float = 30.0
reset()[source]

Reset per-scenario state, keeping the driver and configuration.

Return type:

None

screenshots_dir: str = ''
variables: dict[str, Any]
window_size: tuple[int, int] | None = None

Browser client abstraction: protocol and lazy Selenium driver.

class steplib.modules.web.client.BrowserDriver(*args, **kwargs)[source]

Bases: Protocol

Protocol for browser driver implementations.

back()[source]

Navigate back in browser history.

Return type:

None

clear_input(by, value)[source]

Clear an input element.

Return type:

None

click(by, value)[source]

Click an element matching the locator.

Return type:

None

property current_url: str

The current browser URL.

Delete a cookie by name.

Return type:

None

find_element(by, value)[source]

Find a single element on the page.

Return type:

Any

find_elements(by, value)[source]

Find multiple elements on the page.

Return type:

list[Any]

forward()[source]

Navigate forward in browser history.

Return type:

None

get(url)[source]

Navigate the browser to url.

Return type:

None

Get a cookie by name.

Return type:

dict[str, Any] | None

get_cookies()[source]

Get all cookies.

Return type:

list[dict[str, Any]]

get_element_attribute(by, value, attr)[source]

Get an attribute value from an element.

Return type:

str

get_element_text(by, value)[source]

Get the text content of an element.

Return type:

str

is_element_enabled(by, value)[source]

Check if an element is enabled.

Return type:

bool

is_element_visible(by, value)[source]

Check if an element is visible on the page.

Return type:

bool

property page_source: str

The current page source HTML.

quit()[source]

Close the browser and release resources.

Return type:

None

refresh()[source]

Refresh the current page.

Return type:

None

select_option(by, value, option)[source]

Select an option from a <select> element by visible text.

Return type:

None

set_window_size(width, height)[source]

Set the browser window size.

Return type:

None

switch_to_default()[source]

Switch back to the default content.

Return type:

None

switch_to_frame(by, value)[source]

Switch to an iframe element.

Return type:

None

take_screenshot(path)[source]

Take a screenshot and save to path.

Return type:

None

property title: str

The current page title.

type_text(by, value, text)[source]

Type text into an input element.

Return type:

None

class steplib.modules.web.client.SeleniumDriver(browser='chrome', headless=True)[source]

Bases: object

Browser driver backed by Selenium (requires the [web] extra).

back()[source]

Navigate back in browser history.

Return type:

None

clear_input(by, value)[source]

Clear an input element.

Return type:

None

click(by, value)[source]

Click an element matching the locator.

Return type:

None

property current_url: str

Return the current URL.

Delete a cookie by name.

Return type:

None

find_element(by, value)[source]

Find a single element by by strategy and value.

Parameters:
  • by (str) – The Selenium By strategy name (e.g. "id", "xpath").

  • value (str) – The locator value.

Return type:

Any

Returns:

The matched Selenium WebElement.

find_elements(by, value)[source]

Find multiple elements by by strategy and value.

Parameters:
  • by (str) – The Selenium By strategy name (e.g. "id", "xpath").

  • value (str) – The locator value.

Return type:

list[Any]

Returns:

A list of matched Selenium WebElements.

forward()[source]

Navigate forward in browser history.

Return type:

None

get(url)[source]

Navigate to url.

Return type:

None

Get a cookie by name.

Return type:

dict[str, Any] | None

get_cookies()[source]

Get all cookies.

Return type:

list[dict[str, Any]]

get_element_attribute(by, value, attr)[source]

Get an attribute value from an element.

Return type:

str

get_element_text(by, value)[source]

Get the text content of an element.

Return type:

str

is_element_enabled(by, value)[source]

Check if an element is enabled.

Return type:

bool

is_element_visible(by, value)[source]

Check if an element is visible on the page.

Return type:

bool

property page_source: str

Return the page source HTML.

quit()[source]

Quit the browser.

Return type:

None

refresh()[source]

Refresh the current page.

Return type:

None

select_option(by, value, option)[source]

Select an option from a <select> element by visible text.

Return type:

None

set_window_size(width, height)[source]

Set the browser window size.

Return type:

None

switch_to_default()[source]

Switch back to the default content.

Return type:

None

switch_to_frame(by, value)[source]

Switch to an iframe element.

Return type:

None

take_screenshot(path)[source]

Take a screenshot and save to path.

Return type:

None

property title: str

Return the page title.

type_text(by, value, text)[source]

Type text into an input element, clearing it first.

Return type:

None

steplib.modules.web.client.get_driver(backend='selenium', **kwargs)[source]

Return a browser driver for the given backend.

Parameters:
  • backend (str) – "selenium" (only supported for now).

  • **kwargs (Any) – Additional arguments passed to the driver constructor (e.g. browser="firefox", headless=False).

Return type:

BrowserDriver

Returns:

A BrowserDriver instance.

Raises:

DB module

DB module: database testing steps with SQLAlchemy.

steplib.modules.db.register(registry)[source]

Register all DB steps into the given registry.

Return type:

None

DB step definitions for behave.

steplib.modules.db.steps.register(registry)[source]

Register all DB steps into the given registry.

Return type:

None

steplib.modules.db.steps.step_begin_transaction(context)[source]

Begin a transaction.

Return type:

None

steplib.modules.db.steps.step_column_contains(context, column, value)[source]

Assert column value contains substring.

Return type:

None

steplib.modules.db.steps.step_column_equals(context, column, value)[source]

Assert column value in first row.

Return type:

None

steplib.modules.db.steps.step_column_is_not_null(context, column)[source]

Assert column value is not null.

Return type:

None

steplib.modules.db.steps.step_column_is_null(context, column)[source]

Assert column value is null.

Return type:

None

steplib.modules.db.steps.step_column_not_equals(context, column, value)[source]

Assert column value does not equal.

Return type:

None

steplib.modules.db.steps.step_commit_transaction(context)[source]

Commit transaction.

Return type:

None

steplib.modules.db.steps.step_db_connect(context)[source]

Connect to the database.

Return type:

None

steplib.modules.db.steps.step_db_disconnect(context)[source]

Disconnect from the database.

Return type:

None

steplib.modules.db.steps.step_execute_query(context, query)[source]

Execute a SQL query.

Return type:

None

steplib.modules.db.steps.step_execute_query_with_params(context, query, params)[source]

Execute a SQL query with bind parameters.

Return type:

None

steplib.modules.db.steps.step_query_row_count(context, count)[source]

Assert query row count.

Return type:

None

steplib.modules.db.steps.step_query_row_count_greater_than(context, count)[source]

Assert query row count is greater than.

Return type:

None

steplib.modules.db.steps.step_query_row_count_less_than(context, count)[source]

Assert query row count is less than.

Return type:

None

steplib.modules.db.steps.step_rollback_transaction(context)[source]

Rollback transaction.

Return type:

None

steplib.modules.db.steps.step_scalar_equals(context, query, value)[source]

Assert scalar query equals value.

Return type:

None

steplib.modules.db.steps.step_set_db_connection(context, connection_string)[source]

Set the database connection string.

Return type:

None

steplib.modules.db.steps.step_store_column_value(context, column, variable)[source]

Store column value as variable.

Return type:

None

steplib.modules.db.steps.step_store_row_count(context, variable)[source]

Store row count as variable.

Return type:

None

steplib.modules.db.steps.step_store_scalar(context, query, variable)[source]

Store scalar query result as variable.

Return type:

None

steplib.modules.db.steps.step_table_exists(context, table)[source]

Assert table exists.

Return type:

None

steplib.modules.db.steps.step_table_row_count(context, table, count)[source]

Assert table row count.

Return type:

None

Pure action functions for the DB module.

steplib.modules.db.actions.db_assert_column_contains(db_ctx, query, column, substring)[source]

Assert that a column in the first row contains substring.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • column (str) – The column name to check.

  • substring (str) – The substring to search for.

Raises:

AssertionError – If the query returns no rows, the column is missing, or the value does not contain substring.

Return type:

None

steplib.modules.db.actions.db_assert_column_equals(db_ctx, query, column, expected)[source]

Assert that a column in the first row of a query equals expected.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • column (str) – The column name to check.

  • expected (str) – The expected value (compared as string).

Raises:

AssertionError – If the query returns no rows, the column is missing, or the value does not match.

Return type:

None

steplib.modules.db.actions.db_assert_column_is_not_null(db_ctx, query, column)[source]

Assert that a column in the first row is NOT NULL.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • column (str) – The column name to check.

Raises:

AssertionError – If the query returns no rows, the column is missing, or the value is NULL.

Return type:

None

steplib.modules.db.actions.db_assert_column_is_null(db_ctx, query, column)[source]

Assert that a column in the first row is NULL.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • column (str) – The column name to check.

Raises:

AssertionError – If the query returns no rows, the column is missing, or the value is not NULL.

Return type:

None

steplib.modules.db.actions.db_assert_column_not_equals(db_ctx, query, column, expected)[source]

Assert that a column in the first row does NOT equal expected.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • column (str) – The column name to check.

  • expected (str) – The value that should not match.

Raises:

AssertionError – If the query returns no rows, the column is missing, or the value equals expected.

Return type:

None

steplib.modules.db.actions.db_assert_row_count(db_ctx, query, expected)[source]

Assert that a query returns exactly expected rows.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • expected (int) – The expected number of rows.

Raises:

AssertionError – If the row count does not match.

Return type:

None

steplib.modules.db.actions.db_assert_row_count_greater_than(db_ctx, query, minimum)[source]

Assert that a query returns more than minimum rows.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • minimum (int) – The minimum number of rows (exclusive).

Raises:

AssertionError – If the row count is not greater than minimum.

Return type:

None

steplib.modules.db.actions.db_assert_row_count_less_than(db_ctx, query, maximum)[source]

Assert that a query returns fewer than maximum rows.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • maximum (int) – The maximum number of rows (exclusive).

Raises:

AssertionError – If the row count is not less than maximum.

Return type:

None

steplib.modules.db.actions.db_assert_scalar_equals(db_ctx, query, expected, params=None)[source]

Assert that a scalar query result equals expected.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • expected (str) – The expected value (compared as string).

  • params (dict[str, Any] | None) – Optional bind parameters.

Raises:

AssertionError – If the scalar value does not match.

Return type:

None

steplib.modules.db.actions.db_assert_table_exists(db_ctx, table_name)[source]

Assert that a table exists in the database.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • table_name (str) – The table name to check.

Raises:
Return type:

None

steplib.modules.db.actions.db_assert_table_row_count(db_ctx, table_name, expected)[source]

Assert that a table has exactly expected rows.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • table_name (str) – The table name to check.

  • expected (int) – The expected number of rows.

Raises:
Return type:

None

steplib.modules.db.actions.db_begin_transaction(db_ctx)[source]

Begin a transaction on the current connection.

Parameters:

db_ctx (DbContext) – The DB context to operate on.

Raises:

RuntimeError – If no database connection is configured.

Return type:

None

steplib.modules.db.actions.db_commit(db_ctx)[source]

Commit the current transaction.

Parameters:

db_ctx (DbContext) – The DB context to operate on.

Raises:

RuntimeError – If no transaction is active.

Return type:

None

steplib.modules.db.actions.db_connect(db_ctx)[source]

Create a database connection from the stored connection string.

Parameters:

db_ctx (DbContext) – The DB context to operate on.

Raises:
Return type:

None

steplib.modules.db.actions.db_disconnect(db_ctx)[source]

Close the database connection and dispose the engine.

Parameters:

db_ctx (DbContext) – The DB context to operate on.

Return type:

None

steplib.modules.db.actions.db_query(db_ctx, query)[source]

Execute a SQL query and return rows as a list of dicts.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

Return type:

list[dict[str, Any]]

Returns:

A list of dictionaries, one per row, keyed by column name.

Raises:

RuntimeError – If no database connection is configured.

steplib.modules.db.actions.db_query_scalar(db_ctx, query, params=None)[source]

Execute a SQL query and return a single scalar value.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • params (dict[str, Any] | None) – Optional bind parameters.

Return type:

Any

Returns:

The first column of the first row.

Raises:

RuntimeError – If no database connection is configured.

steplib.modules.db.actions.db_query_with_params(db_ctx, query, params)[source]

Execute a SQL query with bind parameters and return rows as a list of dicts.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • params (dict[str, Any]) – Bind parameters for the query.

Return type:

list[dict[str, Any]]

Returns:

A list of dictionaries, one per row, keyed by column name.

Raises:

RuntimeError – If no database connection is configured.

steplib.modules.db.actions.db_rollback(db_ctx)[source]

Rollback the current transaction.

Parameters:

db_ctx (DbContext) – The DB context to operate on.

Raises:

RuntimeError – If no transaction is active.

Return type:

None

steplib.modules.db.actions.db_set_connection_string(db_ctx, connection_string)[source]

Set the database connection string.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • connection_string (str) – A SQLAlchemy-compatible connection string.

Return type:

None

steplib.modules.db.actions.db_store(db_ctx, variable, value)[source]

Store a value under variable name in the DB context.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • variable (str) – The variable name.

  • value (Any) – The value to store.

Return type:

None

steplib.modules.db.actions.db_store_column_value(db_ctx, query, column, variable)[source]

Store a column value from the first row of a query as a variable.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • column (str) – The column name to extract.

  • variable (str) – The variable name to store under.

Raises:

AssertionError – If the query returns no rows or the column is missing.

Return type:

None

steplib.modules.db.actions.db_store_row_count(db_ctx, query, variable)[source]

Store the row count of a query as a variable.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • variable (str) – The variable name to store under.

Return type:

None

steplib.modules.db.actions.db_store_scalar(db_ctx, query, variable, params=None)[source]

Store a scalar query result as a variable.

Parameters:
  • db_ctx (DbContext) – The DB context to operate on.

  • query (str) – The SQL query string.

  • variable (str) – The variable name to store under.

  • params (dict[str, Any] | None) – Optional bind parameters.

Return type:

None

DbContext: per-scenario database state for the DB module.

class steplib.modules.db.context.DbContext(engine=None, connection=None, connection_string='', transaction=None, variables=<factory>, backend='sqlalchemy')[source]

Bases: object

Holds all database state for a scenario.

Lives at context.steplib.db and is reset between scenarios.

engine

The SQLAlchemy engine instance.

connection

The active SQLAlchemy connection.

connection_string

The SQLAlchemy connection string.

transaction

The active transaction (if any).

variables

User-defined variables stored by steps.

backend

The backend name (e.g. "sqlalchemy").

backend: str = 'sqlalchemy'
cleanup()[source]

Close the database connection if it exists.

Return type:

None

connection: Any = None
connection_string: str = ''
engine: Any = None
reset()[source]

Reset per-scenario state, keeping the engine and configuration.

Return type:

None

transaction: Any = None
variables: dict[str, Any]

Database client abstraction with lazy SQLAlchemy import.

class steplib.modules.db.client.DatabaseClient(connection_string)[source]

Bases: object

Database client backed by SQLAlchemy (requires the [db] extra).

engine

The SQLAlchemy engine instance.

connection

The active SQLAlchemy connection.

begin()[source]

Begin a transaction on the underlying connection.

Return type:

Any

Returns:

The transaction object from SQLAlchemy.

close()[source]

Close the connection and dispose the engine.

Return type:

None

execute(query, params=None)[source]

Execute a SQL query and return rows as a list of dicts.

Parameters:
  • query (str) – The SQL query string.

  • params (dict[str, Any] | None) – Optional bind parameters.

Return type:

list[dict[str, Any]]

Returns:

A list of dictionaries, one per row, keyed by column name.

execute_scalar(query, params=None)[source]

Execute a SQL query and return a single scalar value.

Parameters:
  • query (str) – The SQL query string.

  • params (dict[str, Any] | None) – Optional bind parameters.

Return type:

Any

Returns:

The first column of the first row.

steplib.modules.db.client.get_client(connection_string)[source]

Return a database client for the given connection string.

Parameters:

connection_string (str) – A SQLAlchemy-compatible connection string.

Return type:

DatabaseClient

Returns:

A DatabaseClient instance.

Raises:

MissingDependencyError – If SQLAlchemy is not installed.

Kafka module

Kafka module: Kafka producer/consumer testing steps.

steplib.modules.kafka.register(registry)[source]

Register all Kafka steps into the given registry.

Return type:

None

Kafka step definitions for behave.

steplib.modules.kafka.steps.register(registry)[source]

Register all Kafka steps into the given registry.

Return type:

None

steplib.modules.kafka.steps.step_consume_messages(context, topic)[source]

Consume Kafka messages.

Return type:

None

steplib.modules.kafka.steps.step_consume_with_timeout(context, topic, timeout_ms)[source]

Consume Kafka messages with custom timeout.

Return type:

None

steplib.modules.kafka.steps.step_message_contains(context, text)[source]

Assert a message contains text.

Return type:

None

steplib.modules.kafka.steps.step_message_count(context, count)[source]

Assert message count.

Return type:

None

steplib.modules.kafka.steps.step_message_count_greater_than(context, count)[source]

Assert message count is greater than.

Return type:

None

steplib.modules.kafka.steps.step_message_key_equals(context, index, key)[source]

Assert message key equals.

Return type:

None

steplib.modules.kafka.steps.step_message_order(context, keys)[source]

Assert message order.

Return type:

None

steplib.modules.kafka.steps.step_message_value_equals(context, index, value)[source]

Assert message value equals.

Return type:

None

steplib.modules.kafka.steps.step_message_value_matches_regex(context, pattern)[source]

Assert message value matches regex.

Return type:

None

steplib.modules.kafka.steps.step_produce_json(context, topic, key, payload)[source]

Produce a JSON message.

Return type:

None

steplib.modules.kafka.steps.step_produce_message(context, topic, key, value)[source]

Produce a Kafka message.

Return type:

None

steplib.modules.kafka.steps.step_produce_multiple(context, count, topic)[source]

Produce multiple messages from a behave table.

Return type:

None

steplib.modules.kafka.steps.step_set_auto_offset_reset(context, strategy)[source]

Set auto offset reset.

Return type:

None

steplib.modules.kafka.steps.step_set_consumer_config(context, config)[source]

Set consumer config from JSON string.

Return type:

None

steplib.modules.kafka.steps.step_set_consumer_group(context, group)[source]

Set consumer group.

Return type:

None

steplib.modules.kafka.steps.step_set_kafka_servers(context, servers)[source]

Set Kafka bootstrap servers.

Return type:

None

steplib.modules.kafka.steps.step_set_producer_config(context, config)[source]

Set producer config from JSON string.

Return type:

None

steplib.modules.kafka.steps.step_store_message_count(context, variable)[source]

Store message count as variable.

Return type:

None

steplib.modules.kafka.steps.step_store_message_key(context, index, variable)[source]

Store message key as variable.

Return type:

None

steplib.modules.kafka.steps.step_store_message_value(context, index, variable)[source]

Store message value as variable.

Return type:

None

Pure action functions for the Kafka module.

steplib.modules.kafka.actions.kafka_assert_message_contains(messages, text)[source]

Assert that at least one message value contains text.

Parameters:
  • messages (list[dict[str, Any]]) – The list of consumed messages.

  • text (str) – The substring to search for in message values.

Raises:

AssertionError – If no message value contains text.

Return type:

None

steplib.modules.kafka.actions.kafka_assert_message_count(messages, expected)[source]

Assert that the number of messages equals expected.

Parameters:
  • messages (list[dict[str, Any]]) – The list of consumed messages.

  • expected (int) – The expected number of messages.

Raises:

AssertionError – If the count does not match.

Return type:

None

steplib.modules.kafka.actions.kafka_assert_message_count_greater_than(messages, minimum)[source]

Assert that the number of messages is greater than minimum.

Parameters:
  • messages (list[dict[str, Any]]) – The list of consumed messages.

  • minimum (int) – The minimum number of messages (exclusive).

Raises:

AssertionError – If the count is not greater than minimum.

Return type:

None

steplib.modules.kafka.actions.kafka_assert_message_key_equals(messages, index, expected)[source]

Assert that the key of the message at index equals expected.

Parameters:
  • messages (list[dict[str, Any]]) – The list of consumed messages.

  • index (int) – The zero-based message index.

  • expected (str) – The expected key value.

Raises:

AssertionError – If the index is out of range or the key does not match.

Return type:

None

steplib.modules.kafka.actions.kafka_assert_message_order(messages, expected_keys)[source]

Assert that message keys appear in the order specified by expected_keys.

Parameters:
  • messages (list[dict[str, Any]]) – The list of consumed messages.

  • expected_keys (list[str]) – The expected sequence of message keys.

Raises:

AssertionError – If the message keys do not match the expected order.

Return type:

None

steplib.modules.kafka.actions.kafka_assert_message_value_equals(messages, index, expected)[source]

Assert that the value of the message at index equals expected.

Parameters:
  • messages (list[dict[str, Any]]) – The list of consumed messages.

  • index (int) – The zero-based message index.

  • expected (str) – The expected value.

Raises:

AssertionError – If the index is out of range or the value does not match.

Return type:

None

steplib.modules.kafka.actions.kafka_assert_message_value_matches_regex(messages, pattern)[source]

Assert that at least one message value matches pattern (regex).

Parameters:
  • messages (list[dict[str, Any]]) – The list of consumed messages.

  • pattern (str) – The regex pattern to match against message values.

Raises:

AssertionError – If no message value matches the pattern.

Return type:

None

steplib.modules.kafka.actions.kafka_consume(kafka_ctx, topic, timeout_ms=5000, max_records=100)[source]

Consume messages from a Kafka topic.

Parameters:
  • kafka_ctx (KafkaContext) – The Kafka context to operate on.

  • topic (str) – The Kafka topic to consume from.

  • timeout_ms (int) – Poll timeout in milliseconds.

  • max_records (int) – Maximum number of records to consume.

Return type:

list[dict[str, Any]]

Returns:

A list of dicts with key, value, topic, partition, and offset keys.

Raises:

MissingDependencyError – If kafka-python-ng is not installed.

steplib.modules.kafka.actions.kafka_produce(kafka_ctx, topic, key=None, value='')[source]

Produce a message to a Kafka topic.

Parameters:
  • kafka_ctx (KafkaContext) – The Kafka context to operate on.

  • topic (str) – The target Kafka topic.

  • key (str | None) – Optional message key. None for no key.

  • value (str) – The message value.

Raises:

MissingDependencyError – If kafka-python-ng is not installed.

Return type:

None

steplib.modules.kafka.actions.kafka_produce_json(kafka_ctx, topic, key=None, value=None)[source]

Produce a JSON-serialized message to a Kafka topic.

Parameters:
  • kafka_ctx (KafkaContext) – The Kafka context to operate on.

  • topic (str) – The target Kafka topic.

  • key (str | None) – Optional message key. None for no key.

  • value (dict[str, Any] | None) – The dict to serialize as JSON and send.

Raises:

MissingDependencyError – If kafka-python-ng is not installed.

Return type:

None

steplib.modules.kafka.actions.kafka_produce_multiple(kafka_ctx, topic, messages)[source]

Produce multiple messages to a Kafka topic.

Parameters:
  • kafka_ctx (KafkaContext) – The Kafka context to operate on.

  • topic (str) – The target Kafka topic.

  • messages (list[dict[str, str]]) – A list of dicts with key and value keys.

Raises:

MissingDependencyError – If kafka-python-ng is not installed.

Return type:

None

steplib.modules.kafka.actions.kafka_set_auto_offset_reset(kafka_ctx, strategy)[source]

Set the auto offset reset strategy.

Parameters:
  • kafka_ctx (KafkaContext) – The Kafka context to operate on.

  • strategy (str) – "earliest" or "latest".

Raises:

ValueError – If the strategy is not valid.

Return type:

None

steplib.modules.kafka.actions.kafka_set_bootstrap_servers(kafka_ctx, servers)[source]

Set the Kafka bootstrap servers.

Parameters:
  • kafka_ctx (KafkaContext) – The Kafka context to operate on.

  • servers (str) – Comma-separated bootstrap server addresses.

Return type:

None

steplib.modules.kafka.actions.kafka_set_consumer_config(kafka_ctx, config)[source]

Set additional consumer configuration overrides.

Parameters:
  • kafka_ctx (KafkaContext) – The Kafka context to operate on.

  • config (dict[str, Any]) – A dict of consumer configuration key-value pairs.

Return type:

None

steplib.modules.kafka.actions.kafka_set_consumer_group(kafka_ctx, group)[source]

Set the Kafka consumer group ID.

Parameters:
  • kafka_ctx (KafkaContext) – The Kafka context to operate on.

  • group (str) – The consumer group ID.

Return type:

None

steplib.modules.kafka.actions.kafka_set_producer_config(kafka_ctx, config)[source]

Set additional producer configuration overrides.

Parameters:
  • kafka_ctx (KafkaContext) – The Kafka context to operate on.

  • config (dict[str, Any]) – A dict of producer configuration key-value pairs.

Return type:

None

steplib.modules.kafka.actions.kafka_store_message_count(messages, kafka_ctx, variable)[source]

Store the message count as a variable.

Parameters:
  • messages (list[dict[str, Any]]) – The list of consumed messages.

  • kafka_ctx (KafkaContext) – The Kafka context to store into.

  • variable (str) – The variable name to store under.

Return type:

None

steplib.modules.kafka.actions.kafka_store_message_key(messages, index, kafka_ctx, variable)[source]

Store the key of the message at index as a variable.

Parameters:
  • messages (list[dict[str, Any]]) – The list of consumed messages.

  • index (int) – The zero-based message index.

  • kafka_ctx (KafkaContext) – The Kafka context to store into.

  • variable (str) – The variable name to store under.

Raises:

AssertionError – If the index is out of range.

Return type:

None

steplib.modules.kafka.actions.kafka_store_message_value(messages, index, kafka_ctx, variable)[source]

Store the value of the message at index as a variable.

Parameters:
  • messages (list[dict[str, Any]]) – The list of consumed messages.

  • index (int) – The zero-based message index.

  • kafka_ctx (KafkaContext) – The Kafka context to store into.

  • variable (str) – The variable name to store under.

Raises:

AssertionError – If the index is out of range.

Return type:

None

KafkaContext: per-scenario Kafka state for the Kafka module.

class steplib.modules.kafka.context.KafkaContext(producer=None, consumer=None, bootstrap_servers='localhost:9092', consumer_group='steplib-group', auto_offset_reset='earliest', producer_config=<factory>, consumer_config=<factory>, variables=<factory>, backend='kafka-python-ng')[source]

Bases: object

Holds all Kafka state for a scenario.

Lives at context.steplib.kafka and is reset between scenarios.

producer

The Kafka producer instance.

consumer

The Kafka consumer instance.

bootstrap_servers

Comma-separated Kafka bootstrap server addresses.

consumer_group

The consumer group ID.

auto_offset_reset

Offset reset strategy ("earliest" or "latest").

producer_config

Additional producer configuration overrides.

consumer_config

Additional consumer configuration overrides.

variables

User-defined variables stored by steps.

backend

The backend name (e.g. "kafka-python-ng").

auto_offset_reset: str = 'earliest'
backend: str = 'kafka-python-ng'
bootstrap_servers: str = 'localhost:9092'
cleanup()[source]

Close the producer and consumer if they exist.

Return type:

None

consumer: Any = None
consumer_config: dict[str, Any]
consumer_group: str = 'steplib-group'
producer: Any = None
producer_config: dict[str, Any]
reset()[source]

Reset per-scenario state, keeping bootstrap servers and group config.

Return type:

None

variables: dict[str, Any]

Data module

Data module: generic variable and environment variable testing steps.

steplib.modules.data.register(registry)[source]

Register all data steps into the given registry.

Return type:

None

Data step definitions for behave — generic variables and environment.

steplib.modules.data.steps.register(registry)[source]

Register all data steps into the given registry.

Return type:

None

steplib.modules.data.steps.step_clear_variables(context)[source]

Clear all variables.

Return type:

None

steplib.modules.data.steps.step_copy_variable(context, source, target)[source]

Copy a variable.

Return type:

None

steplib.modules.data.steps.step_delete_env_var(context, key)[source]

Delete an environment variable.

Return type:

None

steplib.modules.data.steps.step_delete_variable(context, name)[source]

Delete a variable.

Return type:

None

steplib.modules.data.steps.step_env_equals(context, key, value)[source]

Assert env var equals.

Return type:

None

steplib.modules.data.steps.step_env_exists(context, key)[source]

Assert env var exists.

Return type:

None

steplib.modules.data.steps.step_env_not_equals(context, key, value)[source]

Assert env var does not equal.

Return type:

None

steplib.modules.data.steps.step_env_not_exists(context, key)[source]

Assert env var does not exist.

Return type:

None

steplib.modules.data.steps.step_extract_key_path(context, key_path, name, target)[source]

Extract a value via dot-path navigation.

Return type:

None

steplib.modules.data.steps.step_increment_variable(context, name, amount)[source]

Increment a numeric variable.

Return type:

None

steplib.modules.data.steps.step_load_env_file(context, path)[source]

Load env vars from a .env file.

Return type:

None

steplib.modules.data.steps.step_load_json_file(context, path, name)[source]

Load JSON file into variable.

Return type:

None

steplib.modules.data.steps.step_load_yaml(context, path, name)[source]

Load YAML file into variable.

Return type:

None

steplib.modules.data.steps.step_set_env_from_variable(context, key, variable)[source]

Set env var from a data variable.

Return type:

None

steplib.modules.data.steps.step_set_env_var(context, key, value)[source]

Set an environment variable.

Return type:

None

steplib.modules.data.steps.step_set_variable(context, name, value)[source]

Set a generic variable.

Return type:

None

steplib.modules.data.steps.step_set_variable_json(context, name, json_str)[source]

Set a variable from a JSON string.

Return type:

None

steplib.modules.data.steps.step_store_env_var(context, key, variable)[source]

Store env var into a data variable.

Return type:

None

steplib.modules.data.steps.step_variable_contains(context, name, text)[source]

Assert variable contains substring.

Return type:

None

steplib.modules.data.steps.step_variable_ends_with(context, name, text)[source]

Assert variable ends with text.

Return type:

None

steplib.modules.data.steps.step_variable_equals(context, name, value)[source]

Assert variable equals.

Return type:

None

steplib.modules.data.steps.step_variable_exists(context, name)[source]

Assert variable exists.

Return type:

None

steplib.modules.data.steps.step_variable_greater_than(context, name, value)[source]

Assert variable is greater than value.

Return type:

None

steplib.modules.data.steps.step_variable_has_length(context, name, count)[source]

Assert variable has length.

Return type:

None

steplib.modules.data.steps.step_variable_is_empty(context, name)[source]

Assert variable is empty.

Return type:

None

steplib.modules.data.steps.step_variable_is_not_empty(context, name)[source]

Assert variable is not empty.

Return type:

None

steplib.modules.data.steps.step_variable_less_than(context, name, value)[source]

Assert variable is less than value.

Return type:

None

steplib.modules.data.steps.step_variable_matches(context, name, pattern)[source]

Assert variable matches regex pattern.

Return type:

None

steplib.modules.data.steps.step_variable_not_equals(context, name, value)[source]

Assert variable does not equal.

Return type:

None

steplib.modules.data.steps.step_variable_not_exists(context, name)[source]

Assert variable does not exist.

Return type:

None

steplib.modules.data.steps.step_variable_starts_with(context, name, text)[source]

Assert variable starts with text.

Return type:

None

steplib.modules.data.steps.step_wait(context, seconds)[source]

Wait for a number of seconds.

Return type:

None

Pure action functions for the data module (variables + environment).

steplib.modules.data.actions.data_assert_env_equals(key, expected)[source]

Assert that an environment variable equals an expected value.

Parameters:
  • key (str) – The environment variable name.

  • expected (str) – The expected value.

Raises:

AssertionError – If the env var does not exist or differs.

Return type:

None

steplib.modules.data.actions.data_assert_env_exists(key)[source]

Assert that an environment variable exists.

Parameters:

key (str) – The environment variable name.

Raises:

AssertionError – If the env var does not exist.

Return type:

None

steplib.modules.data.actions.data_assert_env_not_equals(key, expected)[source]

Assert that an environment variable does not equal a value.

Parameters:
  • key (str) – The environment variable name.

  • expected (str) – The value that the env var should NOT have.

Raises:

AssertionError – If the env var does not exist or equals the value.

Return type:

None

steplib.modules.data.actions.data_assert_env_not_exists(key)[source]

Assert that an environment variable does not exist.

Parameters:

key (str) – The environment variable name.

Raises:

AssertionError – If the env var exists.

Return type:

None

steplib.modules.data.actions.data_assert_variable_contains(data_ctx, name, substring)[source]

Assert that a variable’s string value contains a substring.

Parameters:
  • data_ctx (DataContext) – The data context to check.

  • name (str) – The variable name.

  • substring (str) – The substring to look for.

Raises:

AssertionError – If the variable does not exist or doesn’t contain the substring.

Return type:

None

steplib.modules.data.actions.data_assert_variable_ends_with(data_ctx, name, text)[source]

Assert that a variable’s string value ends with the given text.

Parameters:
  • data_ctx (DataContext) – The data context.

  • name (str) – Variable name.

  • text (str) – Expected suffix.

Raises:

AssertionError – If the variable does not end with the text or does not exist.

Return type:

None

steplib.modules.data.actions.data_assert_variable_equals(data_ctx, name, expected)[source]

Assert that a variable equals an expected value.

Parameters:
  • data_ctx (DataContext) – The data context to check.

  • name (str) – The variable name.

  • expected (str) – The expected value.

Raises:

AssertionError – If the variable does not exist or the value differs.

Return type:

None

steplib.modules.data.actions.data_assert_variable_exists(data_ctx, name)[source]

Assert that a variable exists in the data context.

Parameters:
  • data_ctx (DataContext) – The data context to check.

  • name (str) – The variable name.

Raises:

AssertionError – If the variable does not exist.

Return type:

None

steplib.modules.data.actions.data_assert_variable_greater_than(data_ctx, name, value)[source]

Assert that a variable’s numeric value is greater than a threshold.

Parameters:
  • data_ctx (DataContext) – The data context.

  • name (str) – Variable name.

  • value (str) – Threshold value (compared as float).

Raises:

AssertionError – If the variable is not greater than the value or does not exist.

Return type:

None

steplib.modules.data.actions.data_assert_variable_has_length(data_ctx, name, expected)[source]

Assert that a variable has a specific length.

Works with strings, lists, dicts, and any object with __len__.

Parameters:
  • data_ctx (DataContext) – The data context to check.

  • name (str) – The variable name.

  • expected (int) – The expected length.

Raises:

AssertionError – If the variable does not exist or has a different length.

Return type:

None

steplib.modules.data.actions.data_assert_variable_is_empty(data_ctx, name)[source]

Assert that a variable is empty (empty string, empty list, empty dict, or None).

Parameters:
  • data_ctx (DataContext) – The data context to check.

  • name (str) – The variable name.

Raises:

AssertionError – If the variable does not exist or is not empty.

Return type:

None

steplib.modules.data.actions.data_assert_variable_is_not_empty(data_ctx, name)[source]

Assert that a variable is not empty.

Parameters:
  • data_ctx (DataContext) – The data context to check.

  • name (str) – The variable name.

Raises:

AssertionError – If the variable does not exist or is empty.

Return type:

None

steplib.modules.data.actions.data_assert_variable_less_than(data_ctx, name, value)[source]

Assert that a variable’s numeric value is less than a threshold.

Parameters:
  • data_ctx (DataContext) – The data context.

  • name (str) – Variable name.

  • value (str) – Threshold value (compared as float).

Raises:

AssertionError – If the variable is not less than the value or does not exist.

Return type:

None

steplib.modules.data.actions.data_assert_variable_matches(data_ctx, name, pattern)[source]

Assert that a variable’s string value matches a regex pattern.

Parameters:
  • data_ctx (DataContext) – The data context.

  • name (str) – Variable name.

  • pattern (str) – Regex pattern to match.

Raises:

AssertionError – If the variable does not match or does not exist.

Return type:

None

steplib.modules.data.actions.data_assert_variable_not_equals(data_ctx, name, expected)[source]

Assert that a variable does not equal a value.

Parameters:
  • data_ctx (DataContext) – The data context to check.

  • name (str) – The variable name.

  • expected (str) – The value that the variable should NOT have.

Raises:

AssertionError – If the variable does not exist or equals the value.

Return type:

None

steplib.modules.data.actions.data_assert_variable_not_exists(data_ctx, name)[source]

Assert that a variable does not exist in the data context.

Parameters:
  • data_ctx (DataContext) – The data context to check.

  • name (str) – The variable name.

Raises:

AssertionError – If the variable exists.

Return type:

None

steplib.modules.data.actions.data_assert_variable_starts_with(data_ctx, name, text)[source]

Assert that a variable’s string value starts with the given text.

Parameters:
  • data_ctx (DataContext) – The data context.

  • name (str) – Variable name.

  • text (str) – Expected prefix.

Raises:

AssertionError – If the variable does not start with the text or does not exist.

Return type:

None

steplib.modules.data.actions.data_clear_variables(data_ctx)[source]

Clear all variables from the data context.

Return type:

None

steplib.modules.data.actions.data_copy_variable(data_ctx, source, target)[source]

Copy a variable to a new name.

Parameters:
  • data_ctx (DataContext) – The data context to operate on.

  • source (str) – The source variable name.

  • target (str) – The target variable name.

Raises:

KeyError – If the source variable does not exist.

Return type:

None

steplib.modules.data.actions.data_delete_env_var(data_ctx, key)[source]

Delete an environment variable, backing up the original for restoration.

Parameters:
  • data_ctx (DataContext) – The data context (used for backup tracking).

  • key (str) – The environment variable name.

Return type:

None

steplib.modules.data.actions.data_delete_variable(data_ctx, name)[source]

Delete a variable from the data context.

Parameters:
  • data_ctx (DataContext) – The data context to operate on.

  • name (str) – The variable name.

Raises:

KeyError – If the variable does not exist.

Return type:

None

steplib.modules.data.actions.data_extract_key_path(data_ctx, source, key_path, target)[source]

Extract a value from a variable using dot-path navigation.

Navigates nested dicts/lists using dot-separated keys. List indices are supported via integer keys (e.g. items.0.name).

Parameters:
  • data_ctx (DataContext) – The data context to operate on.

  • source (str) – The source variable name.

  • key_path (str) – Dot-separated path (e.g. user.address.city).

  • target (str) – The target variable name to store the extracted value.

Raises:
  • KeyError – If the source variable does not exist.

  • KeyError – If any key in the path is not found.

Return type:

None

steplib.modules.data.actions.data_increment_variable(data_ctx, name, amount=1)[source]

Increment a numeric variable by a given amount.

Parameters:
  • data_ctx (DataContext) – The data context.

  • name (str) – Variable name.

  • amount (int) – Amount to increment (default 1).

Raises:
  • KeyError – If the variable does not exist.

  • ValueError – If the variable is not numeric.

Return type:

None

steplib.modules.data.actions.data_load_env_file(data_ctx, path)[source]

Load environment variables from a .env-style file.

Parses simple KEY=VALUE lines. Lines starting with # are ignored. Quoted values (single or double) are unquoted.

Parameters:
  • data_ctx (DataContext) – The data context (used for backup tracking).

  • path (str) – Path to the .env file.

Raises:

FileNotFoundError – If the file does not exist.

Return type:

None

steplib.modules.data.actions.data_load_json_file(data_ctx, path, name)[source]

Load a JSON file into a variable as a dict.

Parameters:
  • data_ctx (DataContext) – The data context to operate on.

  • path (str) – Path to the JSON file.

  • name (str) – The variable name to store the parsed content.

Raises:

FileNotFoundError – If the file does not exist.

Return type:

None

steplib.modules.data.actions.data_load_yaml_file(data_ctx, path, name)[source]

Load a YAML file into a variable as a dict.

Parameters:
  • data_ctx (DataContext) – The data context to operate on.

  • path (str) – Path to the YAML file.

  • name (str) – The variable name to store the parsed content.

Raises:
Return type:

None

steplib.modules.data.actions.data_set_env_from_variable(data_ctx, variable, key)[source]

Set an environment variable from a data variable’s value.

Parameters:
  • data_ctx (DataContext) – The data context (used for backup tracking).

  • variable (str) – The source data variable name.

  • key (str) – The environment variable name to set.

Raises:

KeyError – If the source variable does not exist.

Return type:

None

steplib.modules.data.actions.data_set_env_var(data_ctx, key, value)[source]

Set an environment variable, backing up the original for restoration.

Parameters:
  • data_ctx (DataContext) – The data context (used for backup tracking).

  • key (str) – The environment variable name.

  • value (str) – The value to set.

Return type:

None

steplib.modules.data.actions.data_set_variable(data_ctx, name, value)[source]

Set a generic variable in the data context.

Parameters:
  • data_ctx (DataContext) – The data context to operate on.

  • name (str) – The variable name.

  • value (str) – The variable value (stored as string).

Return type:

None

steplib.modules.data.actions.data_set_variable_json(data_ctx, name, json_str)[source]

Set a variable to a parsed JSON value.

Parameters:
  • data_ctx (DataContext) – The data context to operate on.

  • name (str) – The variable name.

  • json_str (str) – A JSON string to parse and store.

Raises:

json.JSONDecodeError – If the string is not valid JSON.

Return type:

None

steplib.modules.data.actions.data_store_env_var(data_ctx, key, variable)[source]

Store an environment variable’s value into a data variable.

Parameters:
  • data_ctx (DataContext) – The data context to operate on.

  • key (str) – The environment variable name.

  • variable (str) – The target variable name.

Raises:

AssertionError – If the env var does not exist.

Return type:

None

steplib.modules.data.actions.data_wait(seconds)[source]

Sleep for a given number of seconds.

Parameters:

seconds (float) – Number of seconds to sleep.

Return type:

None

DataContext: per-scenario state for the data module (variables + env).

class steplib.modules.data.context.DataContext(variables=<factory>, _env_backup=<factory>)[source]

Bases: object

Holds all data-module state for a scenario.

Lives at context.steplib.data and is reset between scenarios.

variables

User-defined variables stored by steps.

_env_backup

Snapshot of environment variables modified during the scenario, so they can be restored on reset/cleanup.

cleanup()[source]

Restore any modified env vars after the scenario.

Return type:

None

reset()[source]

Reset per-scenario state, restoring any modified env vars.

Return type:

None

variables: dict[str, Any]