21
21
import java .net .InetAddress ;
22
22
import java .net .UnknownHostException ;
23
23
import java .util .*;
24
+ import java .util .concurrent .TimeUnit ;
25
+ import java .util .concurrent .TimeoutException ;
26
+ import java .util .concurrent .atomic .AtomicReference ;
27
+
24
28
import javafxlibrary .exceptions .JavaFXLibraryFatalException ;
25
29
import javafxlibrary .exceptions .JavaFXLibraryNonFatalException ;
30
+ import javafxlibrary .exceptions .JavaFXLibraryTimeoutException ;
26
31
import javafxlibrary .keywords .AdditionalKeywords .RunOnFailure ;
27
32
import javafxlibrary .utils .HelperFunctions ;
28
33
import javafxlibrary .utils .RobotLog ;
32
37
import org .robotframework .javalib .annotation .Autowired ;
33
38
import org .robotframework .javalib .library .AnnotationLibrary ;
34
39
import org .robotframework .remoteserver .RemoteServer ;
40
+ import org .testfx .util .WaitForAsyncUtils ;
41
+
35
42
import javax .script .ScriptEngine ;
36
43
import javax .script .ScriptEngineManager ;
37
44
import javax .script .ScriptException ;
@@ -70,10 +77,32 @@ public Object runKeyword(String keywordName, Object[] args) {
70
77
else
71
78
finalArgs = args ;
72
79
80
+ AtomicReference <Object > retval = new AtomicReference <>();
81
+ AtomicReference <RuntimeException > retExcep = new AtomicReference <>();
82
+
73
83
try {
74
- return super .runKeyword (keywordName , finalArgs );
75
- } catch (RuntimeException e ) {
84
+ // timeout + 1 so that underlying timeout has a chance to expire first
85
+ WaitForAsyncUtils .waitFor (getWaitUntilTimeout () + 1 , TimeUnit .SECONDS , () -> {
86
+
87
+ try {
88
+ retval .set (super .runKeyword (keywordName , finalArgs ));
89
+ return true ;
90
+
91
+ } catch (JavaFXLibraryTimeoutException jfxte ){
92
+ // timeout already expired, catch exception and jump out
93
+ retExcep .set (jfxte );
94
+ throw jfxte ;
95
+
96
+ } catch (RuntimeException e ){
97
+ // catch exception and continue trying
98
+ retExcep .set (e );
99
+ return false ;
100
+ }
101
+ });
102
+ } catch (TimeoutException te ) {
103
+ RuntimeException e = retExcep .get ();
76
104
runOnFailure .runOnFailure ();
105
+
77
106
if (e .getCause () instanceof JavaFXLibraryFatalException ) {
78
107
RobotLog .trace ("JavaFXLibrary: Caught JavaFXLibrary FATAL exception: \n " + Throwables .getStackTraceAsString (e ));
79
108
throw e ;
@@ -84,7 +113,11 @@ public Object runKeyword(String keywordName, Object[] args) {
84
113
RobotLog .trace ("JavaFXLibrary: Caught JavaFXLibrary RUNTIME exception: \n " + Throwables .getStackTraceAsString (e ));
85
114
throw e ;
86
115
}
116
+ } catch (JavaFXLibraryTimeoutException jfxte ){
117
+ RobotLog .trace ("JavaFXLibrary: Caught JavaFXLibrary TIMEOUT exception: \n " + Throwables .getStackTraceAsString (jfxte ));
118
+ throw jfxte ;
87
119
}
120
+ return retval .get ();
88
121
}
89
122
90
123
@ Override
0 commit comments