Im running a UI system test using java FX, jdk coretto 8. currently Its supposed to mimick opening the application and clicking the addbook button which should open the addbook dialog. This all works manually but while running my test automated clicking of the button doesn't open the addbook dialog.

book manager view fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane prefHeight="700.0" prefWidth="1100.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.BookManagerViewController">
   <children>
   
       <!-- TableView for displaying books -->
       <TableView fx:id="booksTable" layoutX="20" layoutY="20" prefHeight="650" prefWidth="950">
           <columns>
           <!-- Table columns corresponding to book attributes -->
           <TableColumn fx:id="idColumn" prefWidth="50" text="Book ID" />
           <TableColumn fx:id="titleColumn" prefWidth="150" text="Title" />
           <TableColumn fx:id="authorFirstNameColumn" prefWidth="130" text="Author First Name" />
           <TableColumn fx:id="authorSurnameColumn" prefWidth="130" text="Author Surname" />
           <TableColumn fx:id="isbnColumn" prefWidth="130" text="ISBN" />
           <TableColumn fx:id="publishDateColumn" prefWidth="100" text="Publish Date" />
           <TableColumn fx:id="genreColumn" prefWidth="90" text="Genre" />
           <TableColumn fx:id="publisherNameColumn" prefWidth="140" text="Publisher Name" />
           <TableColumn fx:id="availabilityStatusColumn" prefWidth="130" text="Availability Status" />
           <TableColumn fx:id="conditionColumn" prefWidth="80" text="Condition" />
           </columns>
         <columnResizePolicy>
            <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
         </columnResizePolicy>
       </TableView>
   
       <!-- VBox for Add, Edit, Delete operations -->
       <VBox layoutX="980" layoutY="20" spacing="10">
      <children>
              <Button fx:id="addBookButton" onAction="#handleAddBook" prefWidth="100" text="Add" />
              <Button fx:id="editBookButton" onAction="#handleEditBook" prefWidth="100" text="Edit" />
              <Button fx:id="deleteBookButton" onAction="#handleDeleteBook" onMouseExited="#handleDeleteBook" prefWidth="100" text="Delete" />

            <Button fx:id="loanBookButton" onAction="#handleLoanBook" prefWidth="103" text="Loan Book" />

      </children>
       </VBox>
   </children>

</AnchorPane>

add book dialog fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>

<GridPane xmlns="http://javafx.com/javafx/16"  xmlns:fx="http://javafx.com/fxml/1" hgap="10" vgap="10" fx:controller="controllers.MemberAddDialogController">
    <padding>
        <Insets top="10" right="10" bottom="10" left="10" />
    </padding>
    <!-- Member fields -->
    <Label text="First Name:" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
    <TextField fx:id="firstNameField" GridPane.columnIndex="1" GridPane.rowIndex="0"/>
    <Label text="Last Name:" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
    <TextField fx:id="lastNameField" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
    <!-- ... Add other member fields in a similar manner ... -->
    <Label text="Email:" GridPane.columnIndex="0" GridPane.rowIndex="2"/>
    <TextField fx:id="emailField" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
    <Label text="Phone:" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
    <TextField fx:id="phoneField" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
    <Label text="Address Line 1:" GridPane.columnIndex="0" GridPane.rowIndex="4"/>
    <TextField fx:id="addressLine1Field" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
    <Label text="Address Line 2:" GridPane.columnIndex="0" GridPane.rowIndex="5"/>
    <TextField fx:id="addressLine2Field" GridPane.columnIndex="1" GridPane.rowIndex="5"/>
    <Label text="Town/City:" GridPane.columnIndex="0" GridPane.rowIndex="6"/>
    <TextField fx:id="townOrCityField" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
    <Label text="County:" GridPane.columnIndex="0" GridPane.rowIndex="7"/>
    <TextField fx:id="countyField" GridPane.columnIndex="1" GridPane.rowIndex="7"/>
    <Label text="Post Code:" GridPane.columnIndex="0" GridPane.rowIndex="8"/>
    <TextField fx:id="postCodeField" GridPane.columnIndex="1" GridPane.rowIndex="8"/>
    <Label text="Date Registered:" GridPane.columnIndex="0" GridPane.rowIndex="10"/>
    <DatePicker fx:id="dateRegisteredPicker" GridPane.columnIndex="1" GridPane.rowIndex="10"/>

    <!-- Buttons for the dialog -->
    <HBox spacing="10" GridPane.columnIndex="1" GridPane.rowIndex="11">
        <Button text="Save" onAction="#handleSave"/>
        <Button text="Cancel" onAction="#handleCancel"/>
    </HBox>
</GridPane>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>LibraryManagementSystem</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- SQLite JDBC Driver -->
        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.42.0.0</version>
        </dependency>

        <!-- JUnit 5 dependencies -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.8.0</version> <!-- Use the latest version available -->
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.8.0</version> <!-- Use the same version as junit-jupiter-api -->
            <scope>test</scope>
        </dependency>

        <!-- TestFX for UI testing -->
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-core</artifactId>
            <version>4.0.16-alpha</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-junit5</artifactId>
            <version>4.0.16-alpha</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
add book dialog test .java

package views;

import javafx.stage.Stage;
import main.Main;
import org.junit.jupiter.api.Test;
import org.testfx.framework.junit5.ApplicationTest;
import org.testfx.util.WaitForAsyncUtils;

import static org.testfx.api.FxAssert.verifyThat;
import static org.testfx.matcher.control.TextInputControlMatchers.hasText;

public class AddMemberDialogTest extends ApplicationTest {

    @Override
    public void start(Stage stage) throws Exception {
        new Main().start(stage); // Start the JavaFX application
    }

    @Test
    public void testOpenAddBookDialog() {
      
        clickOn("#addBookButton");

        // Wait for the dialog to open
        WaitForAsyncUtils.waitForFxEvents();


        verifyThat("#titleField", hasText(""));

        
    }
}

I'm not sure if its a dependency version problem or something else

0

There are 0 best solutions below