public abstract class ApplicationTest extends org.testfx.api.FxRobot implements ApplicationFixture
@Test
-annotated methods
(individual test cases), can interact with a JavaFX UI using the FxRobot
methods that test
class will inherit (as it extends ApplicationTest
(this class) which extends FxRobot
).
Verifying the state of the UI can be accomplished by using either the Hamcrest
based FxAssert.verifyThat(T, org.hamcrest.Matcher<? super T>)
or the AssertJ
based org.testfx.assertions.api.Assertions#assertThat(Node)
.
Example:
public class ColorSelectorTest extends ApplicationTest {
Stage stage;
ColorPicker colorPicker;
{@literal @}Override
public void start(Stage stage) throws Exception {
this.stage = stage;
}
{@literal @}Before
public void beforeEachTest() throws Exception {
Platform.runLater(() -> {
colorPicker = new ColorPicker(Color.BLUE);
StackPane stackPane = new StackPane(colorPicker);
Scene scene = new Scene(root, 800, 800);
stage.setScene(scene);
stage.show();
});
WaitForAsyncUtils.waitForFxEvents();
}
{@literal @}Test
public void shouldAllowUserToChangeColor() {
// when:
clickOn(colorPicker);
type(KeyCode.DOWN);
type(KeyCode.DOWN);
// then:
assertThat(colorPicker.getValue()).isEqualTo(Color.TEAL);
}
}
Constructor and Description |
---|
ApplicationTest() |
Modifier and Type | Method and Description |
---|---|
void |
init() |
void |
internalAfter() |
void |
internalBefore() |
static void |
launch(java.lang.Class<? extends javafx.application.Application> appClass,
java.lang.String... appArgs) |
void |
start(javafx.stage.Stage stage) |
void |
stop() |
bounds, bounds, bounds, bounds, bounds, bounds, bounds, bounds, bounds, capture, capture, capture, capture, capture, capture, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, closeCurrentWindow, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, drag, drag, drag, drag, drag, drag, drag, drag, drag, drag, drag, drop, dropBy, dropTo, dropTo, dropTo, dropTo, dropTo, dropTo, dropTo, dropTo, dropTo, dropTo, eraseText, from, from, from, fromAll, interact, interact, interactNoWait, interactNoWait, interrupt, interrupt, listTargetWindows, listWindows, lookup, lookup, lookup, moveBy, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, offset, offset, offset, offset, offset, offset, offset, offset, offset, point, point, point, point, point, point, point, point, point, press, press, push, push, release, release, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, robotContext, rootNode, rootNode, rootNode, scroll, scroll, scroll, scroll, scroll, sleep, sleep, targetPos, targetWindow, targetWindow, targetWindow, targetWindow, targetWindow, targetWindow, targetWindow, targetWindow, type, type, window, window, window, window, window, window, write, write, write
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, moveBy, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, offset, offset, offset, offset, offset, offset, offset, offset, offset, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn
public static void launch(java.lang.Class<? extends javafx.application.Application> appClass, java.lang.String... appArgs) throws java.lang.Exception
java.lang.Exception
public final void internalBefore() throws java.lang.Exception
java.lang.Exception
public final void internalAfter() throws java.lang.Exception
java.lang.Exception
public void init() throws java.lang.Exception
init
in interface ApplicationFixture
java.lang.Exception
public void start(javafx.stage.Stage stage) throws java.lang.Exception
start
in interface ApplicationFixture
java.lang.Exception
public void stop() throws java.lang.Exception
stop
in interface ApplicationFixture
java.lang.Exception