Skip to content

Commit 6ef7323

Browse files
committed
Fix exception handling in Wait For Events In Fx Application Thread
Wait For Events In Fx Application Thread passed even if an exception due to exceeding the timeout was thrown. Exceptions in the anonymous thread are now handled with an UncaughtExceptionHandler, so the keyword will fail when the timeout is exceeded.
1 parent ce55bc7 commit 6ef7323

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,8 +1144,9 @@ public static Object getProgressBarValue(Object locator) {
11441144
+ "``timeout`` is the maximum time in seconds that the events will be waited for. If the timeout is "
11451145
+ "exceeded the keyword will fail. Default timeout is 5 seconds.\n\n")
11461146
@ArgumentNames({ "timeout=" })
1147-
public static void waitForEventsInFxApplicationThread(int timeout) {
1147+
public static void waitForEventsInFxApplicationThread(int timeout) throws Throwable {
11481148

1149+
final Throwable[] threadException = new JavaFXLibraryNonFatalException[1];
11491150
try {
11501151
Semaphore semaphore = new Semaphore(0);
11511152
Platform.runLater(() -> semaphore.release());
@@ -1165,16 +1166,21 @@ public static void waitForEventsInFxApplicationThread(int timeout) {
11651166
"Fx Application Thread: " + e.getMessage());
11661167
}
11671168
});
1169+
t.setUncaughtExceptionHandler((thread, e) -> threadException[0] = e);
11681170
t.start();
11691171
semaphore.acquire();
1172+
1173+
if (threadException[0] != null)
1174+
throw threadException[0];
1175+
11701176
} catch (InterruptedException e) {
11711177
throw new JavaFXLibraryNonFatalException("Wait For Events in Fx Application Thread was interrupted: "
11721178
+ e.getMessage());
11731179
}
11741180
}
11751181

11761182
@RobotKeywordOverload
1177-
public static void waitForEventsInFxApplicationThread() {
1183+
public static void waitForEventsInFxApplicationThread() throws Throwable {
11781184
waitForEventsInFxApplicationThread(HelperFunctions.getWaitUntilTimeout());
11791185
}
11801186
}

src/test/robotframework/acceptance/MiscTests.robot

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Set Node Visibility (Call Method With Argument Types That Require Casting)
103103
Wait For Events In Fx Application Thread
104104
[Tags] smoke demo-set
105105
Set Test Application javafxlibrary.testapps.TestBoundsLocation
106+
Set Timeout 3
106107
${node} Find id=red
107108
Call Object Method In Fx Application Thread ${node} changeFillAfterTwoSeconds
108109
Wait For Events In Fx Application Thread
@@ -113,6 +114,7 @@ Wait For Events In Fx Application Thread
113114
Wait For Events In Fx Application Thread
114115
${result} Find id=red
115116
Should End With ${result} fill=0xff0000ff]
117+
Set Timeout 0
116118

117119
Find From Node
118120
[Tags] smoke

src/test/robotframework/acceptance/NodeLookupTest.robot

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ Root Node Of XPath Query
4343
Should Be Equal ${ROOT_NODE} ${TARGET}
4444
4545
Root Node Of Node That Does Not Exist
46-
[Tags] smoke
46+
[Tags] smoke negative
4747
${MSG} Run Keyword And Expect Error * Get Root Node Of id=non-existent-node-id
4848
Should Contain ${MSG} Unable to find any node with query: "id=non-existent-node-id"
4949
5050
*** Keywords ***
5151
Setup all tests
52-
Launch Javafx Application ${TEST_APPLICATION}
53-
Set Screenshot Directory ${OUTPUT_DIR}${/}report-images
52+
Launch Javafx Application ${TEST_APPLICATION}
53+
Set Screenshot Directory ${OUTPUT_DIR}${/}report-images
54+
Set Timeout 1
5455
5556
Teardown all tests
56-
Close Javafx Application
57+
Close Javafx Application

0 commit comments

Comments
 (0)