SwingWindowInteraction

A lazy handle to the single top-level window targeted by a window query. The target is resolved against the current 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()

T is the window type the query names: onWindowOfType<JFrame>() targets a JFrame, and every step that keeps targeting the same window keeps that type. A query that names no type targets a Window, 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.

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 that the matched window is an R, and returns this interaction typed as R so the assertions and properties after it are written against R:

Link copied to clipboard

Asserts the matched window is visible.

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

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

Link copied to clipboard
suspend fun awaitWindowSystemIdle(quietPeriod: Duration = 250.milliseconds, timeout: Duration = 10.seconds): SwingWindowInteraction<T>

Suspends until the window system has sent this window no move, resize or paint event for quietPeriod, and returns this interaction. Use it before recording what a window paints.

Link copied to clipboard
fun fetch(): T

Resolves the matched window and returns it typed as T. This is the last resort, for a call only the matched window itself takes (e.g. a JFrame's extended state) or for its identity. To read a value, use assertProperty or an assertion.

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

Resolves the matched window and returns it typed as R, for a query that named no type of its own, or that named a wider one than the window to be driven. Like fetch, it is the last resort; assertProperty or an assertion reads a value.

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).