SwingNodeInteraction

A lazy handle to the single component targeted by a query. The target is resolved against the live AWT tree each time it is needed, so it always reflects the current tree after recomposition.

T is the component type the query names: onNodeOfType<JTable>() targets a JTable, and every step that keeps targeting the same node keeps that type, so fetch returns it without being told it again. A query that names no type - onNodeWithText, onNodeWithTag, onParent - targets a Component, and a narrower type is named at the fetch that needs it.

All methods are intended to be called from a org.jetbrains.compose.swing.test.runComposeSwingTest body, which runs on the EDT. Resolution fails with a readable tree dump when the query does not resolve to a single component.

Functions

Link copied to clipboard

Asserts that the matched node satisfies matcher, and returns this interaction for chaining.

Link copied to clipboard

Asserts that the query resolves to no node.

Link copied to clipboard

Asserts that the query resolves to a node. Returns this interaction for chaining.

Link copied to clipboard
fun SwingNodeInteraction<*>.assertImageAgainstGolden(goldenIdentifier: String, threshold: Double = MSSIMMatcher.DEFAULT_THRESHOLD)

Captures the matched component and asserts it matches the stored golden image identified by goldenIdentifier, failing the test on a visual difference.

Link copied to clipboard
fun SwingNodeInteraction<*>.assertImageMatches(expected: BufferedImage, threshold: Double = MSSIMMatcher.DEFAULT_THRESHOLD)

Captures the matched component and asserts it matches expected by structural similarity at threshold, without involving any golden file.

Link copied to clipboard

Asserts the matched node is displayed, with off-screen semantics.

Link copied to clipboard

Asserts the matched node is enabled.

Link copied to clipboard

Asserts that the matched node is the current focus owner, and returns this interaction for chaining.

Link copied to clipboard

Asserts the matched node is not enabled.

Link copied to clipboard

Asserts that the matched node is not the current focus owner, and returns this interaction for chaining. See assertIsFocusOwner for what ownership means.

Link copied to clipboard

Asserts the matched node is not visible - it, or an ancestor up to the query's root, is hidden. See assertIsVisible for what visibility means here.

Link copied to clipboard

Asserts the matched node is visible: neither it nor any ancestor up to the query's root has been hidden with java.awt.Component.setVisible. That is the state a container's own layout drives when it shows one child at a time - a CardPanel shows a card by hiding the others - so it is what to assert on for anything a layout switches between.

Link copied to clipboard

Asserts the matched node is placed under the layout constraint expected by its parent, and returns this interaction for chaining.

Link copied to clipboard
fun <T : Component, V> SwingNodeInteraction<T>.assertProperty(expected: V, message: String? = null, actual: T.() -> V): SwingNodeInteraction<T>

Asserts that the value actual reads off the matched node equals expected, and returns this interaction for chaining.

Link copied to clipboard

Asserts the matched node's text equals expected. A password field carries no readable text, so this assertion always fails against one.

Link copied to clipboard
suspend fun <T : Component> SwingNodeInteraction<T>.assertTreeMatches(expected: Component, allowSubclasses: Boolean = true): SwingNodeInteraction<T>

Asserts that the matched node and expected describe the same user interface - the same widgets, nested the same way, holding the same state - and returns this interaction for chaining.

Link copied to clipboard

Renders the matched component, together with everything drawn inside it, to an off-screen image.

Link copied to clipboard
fun fetch(): T

Resolves the matched component and returns it as the T the query named, for driving the component's own API directly (e.g. a JTable's model, a JTree's selection, a JList's model). A query that named the type does not name it again:

@JvmName(name = "fetchOfType")
inline fun <R : Component> fetch(): R

Resolves the matched component and returns it typed as R, for a query that named no type of its own, or that named a wider one than the component to be driven.

Link copied to clipboard

Returns a handle to the matched node's ancestors, nearest first, up to and including the root the node was found under. A node that is itself a root yields an empty collection.

Link copied to clipboard

Returns a handle to the matched node's only direct child. Resolution fails unless the node holds exactly one child.

Link copied to clipboard

Returns a handle to the matched node's direct child at index. Convenience for onChildren()[index].

Link copied to clipboard

Returns a handle to the matched node's children, in their container's order. A node with no children yields an empty collection.

Link copied to clipboard

Returns a handle to every component below the matched node, at any depth, in depth-first pre-order. The node itself is excluded, which is how a query scopes to one subtree:

Link copied to clipboard

Returns a handle to the parent of the matched node.

Link copied to clipboard

Returns a handle to the matched node's only sibling. Resolution fails unless the node's parent holds exactly two children.

Link copied to clipboard

Returns a handle to the matched node's siblings: every other child of its parent, in the parent's order. A node with no parent yields an empty collection.

Link copied to clipboard
suspend fun <T : Component> SwingNodeInteraction<T>.performClick(position: Point? = null, button: Int = MouseEvent.BUTTON1, clicks: Int = 1, modifiers: Int = 0): SwingNodeInteraction<T>

Clicks the primary mouse button on the matched node at position, then settles the composition. position defaults to the middle of the node, in the node's own coordinates.

Link copied to clipboard

Makes the platform's context-menu gesture on the matched node at position, then settles the composition. position defaults to the middle of the node, in the node's own coordinates.

Link copied to clipboard

Delivers the event event builds for the matched node, then settles the composition.

Link copied to clipboard

Delivers a focus-gained notification to the matched node and settles the composition.

Link copied to clipboard

Delivers a focus-lost notification to the matched node and settles the composition.

Link copied to clipboard
suspend fun <T : Component> SwingNodeInteraction<T>.performKeyPress(keyCode: Int, modifiers: Int = 0): SwingNodeInteraction<T>

Presses and releases the key keyCode on the matched node, holding modifiers for both, then settles the composition. keyCode is a KeyEvent.VK_* constant and modifiers a mask of InputEvent.*_DOWN_MASK values, empty by default.

Link copied to clipboard

Drags the primary mouse button across the matched node from from to to, then settles the composition. Both points are in the node's own coordinates.

Link copied to clipboard

Brings the pointer onto the matched node at position and settles the composition. position defaults to the middle of the node, in the node's own coordinates.

Link copied to clipboard

Takes the pointer off the matched node at position and settles the composition. position defaults to the middle of the node, in the node's own coordinates.

Link copied to clipboard

Moves the pointer to position over the matched node, then settles the composition. position is in the node's own coordinates.

Link copied to clipboard

Presses the primary mouse button on the matched node at position, then settles the composition. position defaults to the middle of the node, in the node's own coordinates.

Link copied to clipboard

Releases the primary mouse button on the matched node at position, then settles the composition. position defaults to the middle of the node, in the node's own coordinates.

Link copied to clipboard
suspend fun <T : Component> SwingNodeInteraction<T>.performMouseWheel(rotation: Int, position: Point? = null): SwingNodeInteraction<T>

Turns the mouse wheel over the matched node by rotation notches - negative away from the user, positive toward them - then settles the composition. position defaults to the middle of the node, in the node's own coordinates.

Link copied to clipboard

Clicks the tab at index on the matched JTabbedPane and settles the composition.

Link copied to clipboard

Types text onto the end of the matched JTextComponent's current content, then settles the composition.

Link copied to clipboard

Pastes text into the matched JTextComponent over its current selection, then settles the composition.

Link copied to clipboard

Replaces the matched JTextComponent's entire content with text, then settles the composition.

Link copied to clipboard

Types text on the matched node one character at a time, then settles the composition.