SwingWindowInteraction

A lazy handle to the single top-level window targeted by a window query. The target is resolved against the live set of realized windows each time it is needed, so it always reflects windows appearing and disappearing across recomposition.

A window matches while its native peer is realized, whether or not it is currently shown, so a window declared visible = false is still matched once its peer is realized - AWT realizes a window when it is shown, and when it is packed to its content's preferred size. A window that leaves the composition is disposed, which retires its peer and drops it out of the match set; a disposed peer lingering in the global AWT window list is likewise excluded because it is no longer realized.

Beyond asserting on the window itself, the interaction scopes node queries to that window's own content - its content pane and its menu bar - so a test can assert on the content of each top-level peer independently:

onWindowWithTitle("Settings").onNodeWithText("Apply").assertIsEnabled()

All methods are intended to be called from a org.jetbrains.compose.swing.test.runComposeSwingTest body, which runs on the EDT.

Functions

Link copied to clipboard

Asserts that no realized window matches.

Link copied to clipboard

Asserts that exactly one realized window matches. Returns this interaction for chaining.

Link copied to clipboard

Asserts the matched window is not visible.

Link copied to clipboard

Asserts the matched window is visible.

Link copied to clipboard
inline fun <T : Window> fetch(): T

Resolves the matched window and returns it typed as T, for driving the window's own API directly (e.g. a JFrame's extended state, a JDialog's modality):

Link copied to clipboard

Finds all nodes matching matcher inside this window's content.

Link copied to clipboard

Finds all nodes inside this window's content tagged with tag via SwingModifier.testTag.

Link copied to clipboard

Finds all nodes inside this window's content whose text equals text (or contains it when substring is true).

Link copied to clipboard

Finds the single node matching matcher inside this window's content. Both the window and the node are resolved lazily when the returned interaction is first used.

Link copied to clipboard

Finds the single node inside this window's content whose java.awt.Component.getName equals name.

Link copied to clipboard

Finds the single node inside this window's content tagged with tag via SwingModifier.testTag.

Link copied to clipboard
fun onNodeWithText(text: @Nls String, substring: Boolean = false): SwingNodeInteraction<Component>

Finds the single node inside this window's content whose text equals text (or contains it when substring is true).