0

我想测试我的 javafx UI。我有一个具有主要功能并加载场景(登录屏幕)的 Application.class。我的测试代码

@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);
}

添加此文本后,loginButtonWithNoInputShowsErrorText我总是收到以下错误

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

为什么会这样。我的代码基于我在互联网上找到的 openjfx 示例,因为我还没有找到关于 jemmyfx 的分析文档和参考。你能帮我一点吗?

4

1 回答 1

0

好吧,我发现出了什么问题... AppExecutor 必须在 @BeforeClass 带注释的方法(静态)中调用,而不是在 @Before 方法中。现在可以了。

于 2015-05-28T08:14:47.940 回答