2

I've been trying to write a test with TestFX to check if a modal is opened, but can't find any methods to do it.

Below is a View that has openModal() when the button is clicked

class MainView : View("Hello TornadoFX") {
override val root = BorderPane()
init {
    with(root) {
        prefWidth = 1920.0
        prefHeight = 1080.0

        center {

            button("Login") {
                id = "Login"

                action {
                    find<LoginForm>().openModal()
                }
            }
        }
    }
}

}

Here is the TestFX code

class MainViewTest: ApplicationTest() {

lateinit var primaryStage: Stage
private lateinit var loginButton: Button


@Before
fun setUpApplication() {
    primaryStage = FxToolkit.registerPrimaryStage()
    val mainView = MainView()

    interact {
        primaryStage.scene = Scene(mainView.root)
        primaryStage.show()
        primaryStage.toFront()
        loginButton = from(mainView.root).lookup("#Login").query()
    }
}

@Test
fun buttonLabelIsLogin() {
    Assertions.assertThat(loginButton).hasText("Login")
}

@Test
fun clickButtonToOpenModal() {
    clickOn(loginButton)
    //Thread.sleep(5000)
}

When the test code run clickButtonToOpenModal(), it cause the error below.

kotlin.KotlinNullPointerException

I think that I have to somehow add an instance of LoginForm into the primaryStage, but I can't find a way to include or add an instance for openModal().

Ball Tha
  • 27
  • 1
  • 5

0 Answers0