Normalize user input into a canonical locator AST.
The AST supports:
- leaf locators (
:text,:label,:css,:testid, ...) - composition (
:scope,:and,:or,:not) - descendant/state filters via
filter/2(:has,:has_not, and:visible) - closest-scope input via
:from - regex text values for text-like locators and role names (without
:exact)
Summary
Functions
Normalizes locators and returns {:ok, locator} or {:error, reason}.
Normalizes locators and raises Cerberus.InvalidLocatorError on invalid input.
Types
@type composite_kind() :: :scope | :and | :or | :not
@type composite_value() :: [t()]
@type leaf_kind() :: :text | :label | :placeholder | :title | :alt | :testid | :css
@type locator_kind() :: leaf_kind() | role_kind() | composite_kind()
@type normalize_result() :: {:ok, t()} | {:error, Exception.t()}
@type resolved_role_kind() :: :text | :label | :link | :button | :alt
@type role_kind() :: :role
@type t() :: %Cerberus.Locator{ kind: locator_kind(), opts: keyword(), value: String.t() | Regex.t() | composite_value() }
Functions
@spec closest(t(), Cerberus.Options.closest_opts()) :: t()
@spec contains_kind?(t(), locator_kind()) :: boolean()
@spec leaf(leaf_kind(), String.t() | Regex.t(), Cerberus.Options.locator_leaf_opts()) :: t()
@spec normalize(t()) :: normalize_result()
Normalizes locators and returns {:ok, locator} or {:error, reason}.
Normalizes locators and raises Cerberus.InvalidLocatorError on invalid input.
@spec resolve_role_kind(String.t() | atom()) :: {:ok, resolved_role_kind()} | :error
@spec resolve_role_kind!(String.t() | atom(), term()) :: resolved_role_kind()
@spec resolved_kind(t()) :: locator_kind() | resolved_role_kind()
@spec role(String.t() | atom(), Cerberus.Options.role_locator_opts()) :: t()