Skip to content

Commit b903851

Browse files
committed
Merge branches 'DockerizedEnv' and 'master' of https://github.com/eficode/JavaFXLibrary into DockerizedEnv
2 parents be1b98d + ce55bc7 commit b903851

25 files changed

+132
-111
lines changed

src/main/java/JavaFXLibrary.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public Object runKeyword(String keywordName, Object[] args) {
8181
AtomicReference<RuntimeException> retExcep = new AtomicReference<>();
8282

8383
try {
84-
// timeout + 1 so that underlying timeout has a chance to expire first
85-
WaitForAsyncUtils.waitFor(getWaitUntilTimeout() + 1, TimeUnit.SECONDS, () -> {
84+
// timeout + 100 ms so that underlying timeout has a chance to expire first
85+
WaitForAsyncUtils.waitFor(getWaitUntilTimeout(TimeUnit.MILLISECONDS) + 100, TimeUnit.MILLISECONDS, () -> {
8686

8787
try {
8888
retval.set(super.runKeyword(keywordName, finalArgs));
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2017-2018 Eficode Oy
3+
* Copyright 2018- Robot Framework Foundation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package javafxlibrary.exceptions;
19+
20+
public class JavaFXLibraryQueryException extends JavaFXLibraryNonFatalException {
21+
public JavaFXLibraryQueryException() {
22+
super();
23+
}
24+
25+
public JavaFXLibraryQueryException(String message) {
26+
super(message);
27+
}
28+
}

src/main/java/javafxlibrary/exceptions/JavaFXLibraryTimeoutException.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,7 @@
1818
package javafxlibrary.exceptions;
1919

2020
@SuppressWarnings("serial")
21-
public class JavaFXLibraryTimeoutException extends JavaFXLibraryKeywordException {
22-
23-
/**
24-
* This will be a non-fatal exception
25-
*/
26-
public static final boolean ROBOT_EXIT_ON_FAILURE = false;
27-
28-
/**
29-
* Avoid adding the exception type as a prefix to this failure exception
30-
*/
31-
public static final boolean ROBOT_SUPPRESS_NAME = true;
21+
public class JavaFXLibraryTimeoutException extends JavaFXLibraryNonFatalException {
3222

3323
public JavaFXLibraryTimeoutException() {
3424
super();

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/keywords/AdditionalKeywords/Find.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package javafxlibrary.keywords.AdditionalKeywords;
22

33
import javafx.scene.Parent;
4-
import javafxlibrary.exceptions.JavaFXLibraryFatalException;
54
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
5+
import javafxlibrary.exceptions.JavaFXLibraryQueryException;
66
import javafxlibrary.utils.finder.Finder;
77
import javafxlibrary.utils.RobotLog;
88
import org.robotframework.javalib.annotation.ArgumentNames;
@@ -46,13 +46,12 @@ public Object find(String query, boolean failIfNotFound, Parent root) {
4646
failIfNotFound + "\", root= \"" + root + "\"");
4747
try {
4848
return mapObject(new Finder().find(query, root));
49-
49+
} catch (JavaFXLibraryQueryException e) {
50+
throw e;
5051
} catch (JavaFXLibraryNonFatalException e) {
5152
if (failIfNotFound)
5253
throw new JavaFXLibraryNonFatalException("Unable to find anything with query: \"" + query + "\"");
5354
return "";
54-
} catch (JavaFXLibraryFatalException e) {
55-
throw e;
5655
} catch (Exception e) {
5756
throw new JavaFXLibraryNonFatalException("Find operation failed for query: \"" + query + "\"", e);
5857
}
@@ -65,13 +64,12 @@ public Object find(String query, boolean failIfNotFound) {
6564
failIfNotFound + "\"");
6665
try {
6766
return mapObject(new Finder().find(query));
68-
69-
} catch (JavaFXLibraryNonFatalException e){
67+
} catch (JavaFXLibraryQueryException e) {
68+
throw e;
69+
} catch (JavaFXLibraryNonFatalException e) {
7070
if (failIfNotFound)
7171
throw new JavaFXLibraryNonFatalException("Unable to find anything with query: \"" + query + "\"");
7272
return "";
73-
} catch (JavaFXLibraryFatalException e) {
74-
throw e;
7573
} catch (Exception e) {
7674
throw new JavaFXLibraryNonFatalException("Find operation failed for query: \"" + query + "\"", e);
7775
}
@@ -94,12 +92,12 @@ public Object find(String query) {
9492
public List<Object> findAll(String query, boolean failIfNotFound, Parent root) {
9593
try {
9694
return mapObjects(new Finder().findAll(query, root));
95+
} catch (JavaFXLibraryQueryException e) {
96+
throw e;
9797
} catch (JavaFXLibraryNonFatalException e) {
9898
if (failIfNotFound)
9999
throw new JavaFXLibraryNonFatalException("Unable to find anything with query: \"" + query + "\"");
100100
return new ArrayList<>();
101-
} catch (JavaFXLibraryFatalException e) {
102-
throw e;
103101
} catch (Exception e) {
104102
throw new JavaFXLibraryNonFatalException("Find operation failed for query: \"" + query + "\"", e);
105103
}
@@ -110,12 +108,12 @@ public List<Object> findAll(String query, boolean failIfNotFound, Parent root) {
110108
public List<Object> findAll(String query, boolean failIfNotFound) {
111109
try {
112110
return mapObjects(new Finder().findAll(query));
111+
} catch (JavaFXLibraryQueryException e) {
112+
throw e;
113113
} catch (JavaFXLibraryNonFatalException e) {
114114
if (failIfNotFound)
115115
throw new JavaFXLibraryNonFatalException("Unable to find anything with query: \"" + query + "\"");
116116
return new ArrayList<>();
117-
} catch (JavaFXLibraryFatalException e) {
118-
throw e;
119117
} catch (Exception e) {
120118
throw new JavaFXLibraryNonFatalException("Find operation failed for query: \"" + query + "\"", e);
121119
}

src/main/java/javafxlibrary/keywords/Keywords/BoundsLocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public Object getBounds(Object locator) {
129129
throw new JavaFXLibraryNonFatalException("Could not execute move to using locator \"" + locator + "\": "
130130
+ e.getCause().getMessage());
131131

132-
} catch (JavaFXLibraryTimeoutException | JavaFXLibraryNonFatalException e){
132+
} catch (JavaFXLibraryNonFatalException e){
133133
throw e;
134134

135135
} catch (Exception 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/main/java/javafxlibrary/utils/HelperFunctions.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ public static int getWaitUntilTimeout() {
414414
return waitUntilTimeout;
415415
}
416416

417+
public static long getWaitUntilTimeout(TimeUnit timeUnit) {
418+
return timeUnit.convert(waitUntilTimeout, TimeUnit.SECONDS);
419+
}
420+
417421
public static void checkClickLocation(int x, int y) {
418422
checkClickLocation(new Point2D(x, y));
419423
}
@@ -444,7 +448,7 @@ public static Object checkClickTarget(Object target) {
444448
checkClickLocation(target);
445449
return target;
446450

447-
} catch (JavaFXLibraryTimeoutException | JavaFXLibraryNonFatalException jfxe) {
451+
} catch (JavaFXLibraryNonFatalException jfxe) {
448452
throw jfxe;
449453
} catch (Exception e) {
450454
throw new JavaFXLibraryNonFatalException("Click target check failed: " + e.getMessage(), e);

src/main/java/javafxlibrary/utils/finder/FindOperation.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import javafx.scene.Parent;
2424
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
2525
import javafxlibrary.matchers.InstanceOfMatcher;
26-
import javafxlibrary.utils.RobotLog;
2726
import javafxlibrary.utils.TestFxAdapter;
2827
import org.testfx.api.FxRobotInterface;
2928
import org.testfx.matcher.control.LabeledMatchers;

0 commit comments

Comments
 (0)