Apostolos
Apostolos

Reputation: 8121

jemmy fx testing fx ui gives me an IllegalStateException when clicking a button

I want to test my javafx UI. I have an Application.class that has the main function and loads a scene (a login screen). My testing code

@Before
public void startApp() throws InterruptedException {
    startApp(Application.class);
    scene = new SceneDock();
    this.username = new TextInputControlDock(scene.asParent(), "txtFieldUsername");
    this.password = new TextInputControlDock(scene.asParent(), "txtFieldPassword");
    this.btnLogin = new LabeledDock(scene.asParent(), "Login", StringComparePolicy.EXACT);
    this.btnCancel = new LabeledDock(scene.asParent(), "Cancel", StringComparePolicy.EXACT);

}

@Test
public void loginScreenMustContainTwoButtonsCancelAndLogin() throws Exception {
    assertEquals(Button.class, new LabeledDock(scene.asParent(), "Cancel",
            StringComparePolicy.EXACT).wrap().getControl().getClass());
    assertEquals(Button.class, new LabeledDock(scene.asParent(), "Login",
            StringComparePolicy.EXACT).wrap().getControl().getClass());
}

@Test
public void loginScreenMustContainTwoTextFieldsUsernameAndPassword() throws Exception {
    TextInputControlDock username = new TextInputControlDock(scene.asParent(), "txtFieldUsername");
    TextInputControlDock password = new TextInputControlDock(scene.asParent(), "txtFieldPassword");
    assertTrue(username.wrap().getControl() instanceof TextField);
    assertTrue(password.wrap().getControl() instanceof PasswordField);      
}


@Ignore
@Test(expected=TimeoutExpiredException.class)
public void loginWindowHasAnErrorLabel() throws Exception {
    NodeDock errorLabel = new NodeDock(scene.asParent(), Label.class, "lblErrorMessage");
    assertTrue(errorLabel.wrap().getControl() instanceof Label);
}

@Test
public void loginButtonWithNoInputShowsErrorText() throws Exception {
    log.debug("Clicking login button");
    btnLogin.wrap().mouse().click(1);
    log.debug(scene);

}

private void startApp(Class<AvalancheClient> app) {
    // TODO Auto-generated method stub
    AppExecutor.executeNoBlock(app);
}

After I added this text loginButtonWithNoInputShowsErrorText I always get the following error

Exception in thread "Thread-7" java.lang.IllegalStateException: Application launch must not be called more than once

Why is it happening. I am basing my code at the samples of openjfx I found on the internet, because I haven't found an analytic documentation and reference on jemmyfx yet. Could you help me a bit?

Upvotes: 0

Views: 170

Answers (1)

Apostolos
Apostolos

Reputation: 8121

Well I found what was wrong...The AppExecutor must be called in @BeforeClass annotated method(static) and not in @Before method. It works now.

Upvotes: 0

Related Questions