I am getting the following exception while writing my first TestFx code.
Exception in thread "main" java.lang.RuntimeException: java.lang.IllegalStateException: Toolkit not initialized
at org.loadui.testfx.utils.FXTestUtils.awaitEvents(FXTestUtils.java:104)
at org.loadui.testfx.FXScreenController.press(FXScreenController.java:123)
at org.loadui.testfx.GuiTest.press(GuiTest.java:1083)
at org.loadui.testfx.GuiTest.type(GuiTest.java:1013)
at org.loadui.testfx.GuiTest.type(GuiTest.java:990)
at login.LoginTester.validCredentials_should_loginSuccessfully(LoginTester.java:38)
at login.LoginTester.main(LoginTester.java:47)
Caused by: java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:158)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:153)
at javafx.application.Platform.runLater(Platform.java:52)
at org.loadui.testfx.utils.FXTestUtils.awaitEvents(FXTestUtils.java:78)
... 6 more
Java Result: 1
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package login;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.loadui.testfx.GuiTest;
/**
*
* @author dinesven
*/
@RunWith(JUnit4.class)
public class LoginTester extends GuiTest {
@Override
protected Parent getRootNode() {
try {
return FXMLLoader.load(LoginForm.class.getResource("FXMLDocument.fxml"));
} catch (IOException ex) {
Logger.getLogger(LoginTester.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
@Test
public void validCredentials_should_loginSuccessfully() {
click("#login);
type("Steve and this is to test");
}
public static void main(String[] args){
System.out.println("TestFX");
LoginTester lt = new LoginTester();
lt.getRootNode();
lt.validCredentials_should_loginSuccessfully();
}
}