Class FxToolkit
Overview
This class methods cover three different kinds of fixtures:
- Container fixtures, which are registered as
registeredStage. - Content fixtures, which are attached to the registered
registeredStage. - Individual fixtures, which do not require a
registeredStage.
1. Container Fixtures
They can be registered as registeredStage and provide a top-level container, i.e.
Stages.
The primary stage can be registered as registeredStage using registerPrimaryStage().
This call is mandatory before any other JavaFX fixture can be created.
Other stages can be registered as registeredStage using registerStage(Supplier<Stage>).
2. Content Fixtures
They can be attached to the registeredStage.
Either constructed by calling an Application.start(), by
supplying Scenes, Parents, or by consuming a Stage.
Use: setupStage(Consumer<Stage>),
setupApplication(Class<? extends Application>),
setupScene(Supplier<Scene>) or
setupSceneRoot(Supplier<Parent>)
3. Individual Fixtures
To setup individual Stages, Scenes or Nodes use setupFixture(Runnable) and
setupFixture(Callable).
Internal Context
Is internally responsible for handle the registered Stage for attachments, handle timeouts, provide the Application for the Toolkit launch and execute the setup in the JavaFX thread. The primary Stage is constructed by the platform.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ApplicationLauncherprivate static final ApplicationServiceprivate static final FxToolkitContext(package private) static final Stringprivate static final ToolkitService(package private) static final String(package private) static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanupAfterTest(FxRobot robot, javafx.application.Application application) static voidcleanupApplication(javafx.application.Application application) Performs the cleanup of the application.static voidcleanupInput(FxRobot robot) Runs on theJavaFX Application Thread: Releases remaining mouse and keyboard events.static voidRuns on theJavaFX Application Thread: Hides all windows returned fromJavaVersionAdapter.getWindows()and returns once finished.(package private) static voidhandleCommonRuntimeExceptions(RuntimeException exception) static voidRuns on theJavaFX Application Thread: Hides the registered stage viaWindow.hide()and returns once finished.static booleanDetects if the JavaFx Application Thread is currently running.static javafx.stage.StageSets up thePrimaryStageApplicationto use in tests, prevents it from shutting down when the last window is closed, and returns theStagefromApplication.start(Stage).static javafx.stage.StageregisterStage(Supplier<javafx.stage.Stage> stageSupplier) Runs the stageSupplier on theJavaFX Application Thread, registers the supplied stage, and returns that stage.static javafx.application.ApplicationsetupApplication(Class<? extends javafx.application.Application> applicationClass, String... applicationArgs) Sets up the given application with its given arguments and returns that application once finished.static javafx.application.ApplicationsetupApplication(Supplier<javafx.application.Application> applicationSupplier) Sets up the supplied application and returns that application once finished.static voidsetupFixture(Runnable runnable) Runs the givenrunnableon theJavaFX Application Threadand returns once finished.static <T> TsetupFixture(Callable<T> callable) Runs the givencallableon theJavaFX Application Threadand returns once finished.static javafx.scene.ScenesetupScene(Supplier<javafx.scene.Scene> sceneSupplier) Runs thesceneSupplieron theJavaFX Application Thread, sets the registered stage's scene to the supplied scene, and returns the supplied scene once finished.static javafx.scene.ParentsetupSceneRoot(Supplier<javafx.scene.Parent> sceneRootSupplier) Runs thesceneRootSupplieron theJavaFX Application Thread, sets the registered stage's scene's root node to the supplied root node, and returns the supplied root node once finished.static javafx.stage.StagesetupStage(Consumer<javafx.stage.Stage> stageConsumer) Sets up the registered stage by passing it into the givenstageConsumeron theJavaFX Application Threadand returns the stage once finished.static voidRuns on theJavaFX Application Thread: Shows the registered stage viaStage.show(), moves it to the front viaStage.toFront(), and returns once finished.static FxToolkitContextReturns the internal context.private static <T> TwaitForSetup(Future<T> future) Waits for the given future to be set before returning or times out afterFxToolkitContext.getSetupTimeoutInMillis()is reached.
-
Field Details
-
APP_LAUNCHER
-
APP_SERVICE
-
CONTEXT
-
SERVICE
-
UNSUPPORTED_OPERATION_ERROR_MESSAGE
- See Also:
-
UNSUPPORTED_OPERATION_CALLING_CLASS
- See Also:
-
MISSING_LIBGTK_3_0_USER_MESSAGE
- See Also:
-
-
Constructor Details
-
FxToolkit
private FxToolkit()
-
-
Method Details
-
registerPrimaryStage
Sets up thePrimaryStageApplicationto use in tests, prevents it from shutting down when the last window is closed, and returns theStagefromApplication.start(Stage).- Throws:
TimeoutException- if execution is not finished beforeFxToolkitContext.getLaunchTimeoutInMillis()
-
registerStage
public static javafx.stage.Stage registerStage(Supplier<javafx.stage.Stage> stageSupplier) throws TimeoutException Runs the stageSupplier on theJavaFX Application Thread, registers the supplied stage, and returns that stage.- Throws:
TimeoutException- if execution is not finished beforeFxToolkitContext.getSetupTimeoutInMillis()
-
setupStage
public static javafx.stage.Stage setupStage(Consumer<javafx.stage.Stage> stageConsumer) throws TimeoutException Sets up the registered stage by passing it into the givenstageConsumeron theJavaFX Application Threadand returns the stage once finished.- Throws:
TimeoutException- if execution is not finished beforeFxToolkitContext.getSetupTimeoutInMillis()
-
setupApplication
public static javafx.application.Application setupApplication(Class<? extends javafx.application.Application> applicationClass, String... applicationArgs) throws TimeoutException Sets up the given application with its given arguments and returns that application once finished.- Throws:
TimeoutException- if execution is not finished beforeFxToolkitContext.getSetupTimeoutInMillis()
-
setupApplication
public static javafx.application.Application setupApplication(Supplier<javafx.application.Application> applicationSupplier) throws TimeoutException Sets up the supplied application and returns that application once finished.- Throws:
TimeoutException- if execution is not finished beforeFxToolkitContext.getSetupTimeoutInMillis()
-
cleanupApplication
public static void cleanupApplication(javafx.application.Application application) throws TimeoutException Performs the cleanup of the application. This is done by callingToolkitService.cleanupApplication(Application)(which usually calls thestopmethod of the application).- Parameters:
application- the application to clean up- Throws:
TimeoutException- if cleanup is not finished beforeFxToolkitContext.getSetupTimeoutInMillis()or the FX Application Thread is not running
-
cleanupAfterTest
public static void cleanupAfterTest(FxRobot robot, javafx.application.Application application) throws TimeoutException - Throws:
TimeoutException
-
setupScene
public static javafx.scene.Scene setupScene(Supplier<javafx.scene.Scene> sceneSupplier) throws TimeoutException Runs thesceneSupplieron theJavaFX Application Thread, sets the registered stage's scene to the supplied scene, and returns the supplied scene once finished.- Throws:
TimeoutException- if execution is not finished beforeFxToolkitContext.getSetupTimeoutInMillis()
-
setupSceneRoot
public static javafx.scene.Parent setupSceneRoot(Supplier<javafx.scene.Parent> sceneRootSupplier) throws TimeoutException Runs thesceneRootSupplieron theJavaFX Application Thread, sets the registered stage's scene's root node to the supplied root node, and returns the supplied root node once finished.- Throws:
TimeoutException
-
setupFixture
Runs the givenrunnableon theJavaFX Application Threadand returns once finished.- Throws:
TimeoutException
-
setupFixture
Runs the givencallableon theJavaFX Application Threadand returns once finished.- Throws:
TimeoutException
-
showStage
Runs on theJavaFX Application Thread: Shows the registered stage viaStage.show(), moves it to the front viaStage.toFront(), and returns once finished.- Throws:
TimeoutException
-
hideStage
Runs on theJavaFX Application Thread: Hides the registered stage viaWindow.hide()and returns once finished.- Throws:
TimeoutException
-
cleanupStages
Runs on theJavaFX Application Thread: Hides all windows returned fromJavaVersionAdapter.getWindows()and returns once finished.- Throws:
TimeoutException
-
cleanupInput
Runs on theJavaFX Application Thread: Releases remaining mouse and keyboard events. Not cleaning these events may have side effects on the next UI tests -
toolkitContext
Returns the internal context. -
waitForSetup
Waits for the given future to be set before returning or times out afterFxToolkitContext.getSetupTimeoutInMillis()is reached.- Throws:
TimeoutException
-
isFXApplicationThreadRunning
public static boolean isFXApplicationThreadRunning()Detects if the JavaFx Application Thread is currently running.- Returns:
- true if the FX Application Thread is running, false otherwise
-
handleCommonRuntimeExceptions
-