Skip to content

Commit 01cbec6

Browse files
committed
Fix the order of windows in TestMultipleWindows
Stages 2 and 3 are now created after the primaryStage, so the order is 1, 2, 3 instead of the earlier 2, 3, 1. Keyword Bring stage to front also sets the stage as the targeted window of the current robot instance.
1 parent a5abee0 commit 01cbec6

File tree

4 files changed

+44
-62
lines changed

4 files changed

+44
-62
lines changed

src/main/java/javafxlibrary/keywords/AdditionalKeywords/ConvenienceKeywords.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public Object findWithPath(String query) {
9292
public void bringStageToFront(Stage stage) {
9393
RobotLog.info("Bringing following Stage to front: \"" + stage + "\"");
9494
try {
95+
robot.targetWindow(stage);
9596
Platform.runLater(() -> stage.toFront());
9697
} catch (Exception e) {
9798
throw new JavaFXLibraryNonFatalException("Unable to bring stage to front.", e);

src/main/java/javafxlibrary/testapps/TestMultipleWindows.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import javafx.application.Application;
2121
import javafx.fxml.FXMLLoader;
22+
import javafx.geometry.Rectangle2D;
2223
import javafx.scene.Parent;
2324
import javafx.scene.Scene;
2425
import javafx.stage.Screen;
@@ -27,6 +28,8 @@
2728
import javafxlibrary.testapps.controllers.TestMultipleWindowsController;
2829
import org.testfx.api.FxToolkit;
2930

31+
import java.io.IOException;
32+
3033
public class TestMultipleWindows extends Application {
3134

3235
Stage stage;
@@ -58,6 +61,37 @@ public void start(Stage primaryStage) throws Exception {
5861

5962
stage.show();
6063
stage.centerOnScreen();
64+
65+
try {
66+
Stage secondWindow = new Stage();
67+
Stage thirdWindow = new Stage();
68+
Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
69+
70+
// Second Window
71+
fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/javafxlibrary/ui/MultipleWindowsSubUIs/SecondUI.fxml"));
72+
Parent secondRoot = fxmlLoader.load();
73+
secondWindow.setScene(new Scene(secondRoot));
74+
secondWindow.setTitle("Second window");
75+
secondWindow.setX(screenBounds.getMinX() + 200);
76+
secondWindow.initStyle(StageStyle.DECORATED);
77+
secondWindow.getScene().setOnKeyPressed(event -> controller.keyCombinationListener(event));
78+
secondWindow.getScene().setOnKeyReleased(event -> controller.keyReleaseListener(event));
79+
secondWindow.show();
80+
81+
// Third Window
82+
fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/javafxlibrary/ui/MultipleWindowsSubUIs/ThirdUI.fxml"));
83+
Parent thirdRoot = fxmlLoader.load();
84+
thirdWindow.setScene(new Scene(thirdRoot));
85+
thirdWindow.setTitle("Third window");
86+
thirdWindow.setX(screenBounds.getMinX() + 600);
87+
thirdWindow.initStyle(StageStyle.DECORATED);
88+
thirdWindow.getScene().setOnKeyPressed(event -> controller.keyCombinationListener(event));
89+
thirdWindow.getScene().setOnKeyReleased(event -> controller.keyReleaseListener(event));
90+
thirdWindow.show();
91+
92+
} catch (IOException | NullPointerException e) {
93+
e.printStackTrace();
94+
}
6195
}
6296

6397
@Override

src/main/java/javafxlibrary/testapps/controllers/TestMultipleWindowsController.java

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,72 +17,22 @@
1717

1818
package javafxlibrary.testapps.controllers;
1919

20-
import javafx.fxml.FXMLLoader;
2120
import javafx.fxml.Initializable;
22-
import javafx.geometry.Rectangle2D;
23-
import javafx.scene.Parent;
2421
import javafx.scene.Scene;
2522
import javafx.scene.input.KeyCode;
2623
import javafx.scene.input.KeyEvent;
27-
import javafx.stage.Screen;
28-
import javafx.stage.Stage;
29-
import javafx.stage.StageStyle;
30-
import java.io.IOException;
3124
import java.net.URL;
3225
import java.util.ResourceBundle;
3326

3427
public class TestMultipleWindowsController implements Initializable {
3528

3629
private boolean combinationPressed;
37-
private Stage secondWindow;
38-
private Stage thirdWindow;
3930

4031
@Override
4132
public void initialize(URL location, ResourceBundle resources) {
42-
openOtherWindows();
4333
combinationPressed = false;
4434
}
4535

46-
private void openOtherWindows() {
47-
Parent root;
48-
try {
49-
secondWindow = new Stage();
50-
thirdWindow = new Stage();
51-
Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
52-
53-
// Load FXML for secondWindow
54-
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(
55-
"/fxml/javafxlibrary/ui/MultipleWindowsSubUIs/SecondUI.fxml"));
56-
root = fxmlLoader.load();
57-
58-
// Second window settings
59-
secondWindow.setScene(new Scene(root));
60-
secondWindow.setTitle("Second window");
61-
secondWindow.setX(screenBounds.getMinX() + 200);
62-
secondWindow.initStyle(StageStyle.DECORATED);
63-
secondWindow.getScene().setOnKeyPressed(event -> keyCombinationListener(event));
64-
secondWindow.getScene().setOnKeyReleased(event -> keyReleaseListener(event));
65-
secondWindow.show();
66-
67-
// Load FXML for thirdWindow
68-
fxmlLoader = new FXMLLoader(getClass().getResource(
69-
"/fxml/javafxlibrary/ui/MultipleWindowsSubUIs/ThirdUI.fxml"));
70-
root = fxmlLoader.load();
71-
72-
// Third window settings
73-
thirdWindow.setScene(new Scene(root));
74-
thirdWindow.setTitle("Third window");
75-
thirdWindow.setX(screenBounds.getMinX() + 600);
76-
thirdWindow.initStyle(StageStyle.DECORATED);
77-
thirdWindow.getScene().setOnKeyPressed(event -> keyCombinationListener(event));
78-
thirdWindow.getScene().setOnKeyReleased(event -> keyReleaseListener(event));
79-
thirdWindow.show();
80-
81-
} catch (IOException | NullPointerException e) {
82-
e.printStackTrace();
83-
}
84-
}
85-
8636
public void keyCombinationListener(KeyEvent event) {
8737
// Close the current window when CMD + W is pressed
8838
if (event.isMetaDown() && event.getCode() == KeyCode.W && !combinationPressed) {

src/test/robotframework/acceptance/WindowLookupTest.robot

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ Window By Pattern
4545
Window By Index
4646
[Tags] smoke
4747
${TARGET} Get Window First window
48-
${WINDOW} Get Window 2
48+
${WINDOW} Get Window 0
4949
${TITLE} Get Window Title ${WINDOW}
5050
Should Be Equal ${TARGET} ${WINDOW} msg=Window searched with title and index (string) does not match!
51-
5251
${TARGET} Get Window Second window
53-
${WINDOW} Get Window ${0}
52+
${WINDOW} Get Window 1
5453
${TITLE} Get Window Title ${WINDOW}
5554
Should Be Equal ${TARGET} ${WINDOW} msg=Window searched with title and index (integer) does not match!
5655
@@ -75,16 +74,14 @@ List Target Windows
7574
# Keyword is located in ConvenienceKeywords
7675
Bring Stage To Front
7776
[Tags] smoke
78-
${SECOND_WINDOW} Get Window Second window
79-
${THIRD_WINDOW} Get Window Third window
77+
${second_window} Get Window Second window
8078
Bring Stage To Front ${SECOND_WINDOW}
81-
Sleep 1 SECONDS
82-
${SECOND_ISFOCUSED} Call Object Method ${SECOND_WINDOW} isFocused
83-
Should Be True ${SECOND_ISFOCUSED} msg=Second window was not focused!
84-
Bring Stage To Front ${THIRD_WINDOW}
85-
Sleep 1 SECONDS
86-
${THIRD_ISFOCUSED} Call Object Method ${THIRD_WINDOW} isFocused
87-
Should Be True ${THIRD_ISFOCUSED} msg=Third window was not focused!
79+
${target} Get Target Window
80+
Should Be Equal ${second_window} ${target}
81+
${third_window} Get Window Third window
82+
Bring Stage To Front ${third_window}
83+
${target} Get Target Window
84+
Should Be Equal ${third_window} ${target}
8885
8986
# On Mac the testing application had to be modified to register CMD + W.
9087
# Close Current Window uses ALT + F4 on Windows, so it should work with no changes to the testing application.

0 commit comments

Comments
 (0)