plushie/testing/element

Element: a query-friendly wrapper around a tree Node.

Elements provide convenient accessors for testing: find by ID, extract text content, read props, and traverse children.

Types

A test element wrapping a Node for convenient querying.

pub type Element {
  Element(node: node.Node)
}

Constructors

Values

pub fn a11y(
  element: Element,
) -> dict.Dict(String, node.PropValue)

Get the a11y props dict from an element.

Returns an empty dict if no a11y key is set.

pub fn child_at(
  element: Element,
  index: Int,
) -> option.Option(Element)

Get a child element by index.

pub fn children(element: Element) -> List(Element)

Get the element’s children as Elements.

pub fn find(
  in root: node.Node,
  id target: String,
) -> option.Option(Element)

Find an element by ID in a normalized tree.

pub fn find_all(
  element: Element,
  predicate: fn(Element) -> Bool,
) -> List(Element)

Collect all descendant elements matching a predicate.

pub fn find_within(
  element: Element,
  target: String,
) -> option.Option(Element)

Find a descendant element by ID within this element’s subtree.

pub fn from_node(node: node.Node) -> Element

Wrap a Node as an Element.

pub fn has_children(element: Element) -> Bool

Check if the element has any children.

pub fn id(element: Element) -> String

Get the element’s ID.

pub fn kind(element: Element) -> String

Get the element’s kind (widget type).

pub fn local_id(element: Element) -> String

Get the local ID (last segment after “/” and “#”).

pub fn prop(
  element: Element,
  key: String,
) -> option.Option(node.PropValue)

Get a prop value by key.

pub fn resolved_a11y(
  element: Element,
) -> dict.Dict(String, node.PropValue)

Return the resolved a11y dict for this element.

Layers render-pipeline inference (placeholder -> description for text-entry widgets, alt -> label for media widgets) on top of the normalized a11y prop. Kept aligned with the Rust SDK’s resolve_a11y_for_node so cross-SDK parity holds.

pub fn text(element: Element) -> option.Option(String)

Extract text content from an element. Checks props in order: “content”, “label”, “value”, “placeholder”.

Search Document