30
30
31
31
import java .lang .reflect .InvocationTargetException ;
32
32
import java .lang .reflect .Method ;
33
+ import java .util .concurrent .ExecutionException ;
33
34
34
35
import static javafxlibrary .utils .HelperFunctions .*;
36
+ import static org .testfx .util .WaitForAsyncUtils .asyncFx ;
35
37
36
38
@ RobotKeywords
37
39
public class MoveRobot extends TestFxAdapter {
@@ -46,18 +48,49 @@ public class MoveRobot extends TestFxAdapter {
46
48
+ "| ${point} | Create Point | ${x} | ${y} | \n "
47
49
+ "| Move To | ${POINT} | VERTICAL_FIRST | | # moves mouse on top of given Point object by moving first vertically and then horizontally |" )
48
50
@ ArgumentNames ({ "locator" , "motion=DIRECT" })
49
- public FxRobotInterface moveTo (Object locator , String motion ) {
51
+ public void moveTo (Object locator , String motion ) {
50
52
checkObjectArgumentNotNull (locator );
51
53
try {
52
54
RobotLog .info ("Moving to target \" " + locator + "\" using motion: \" " + getMotion (motion ) + "\" " );
55
+ Object node ;
53
56
if (locator instanceof String ) {
54
- locator = objectToNode (locator );
57
+ node = asyncFx (() -> {
58
+ try {
59
+ return objectToNode (locator );
60
+ } catch (Exception e ) {
61
+ RobotLog .info ("Locator not found: " + e .getCause ());
62
+ return null ;
63
+ }
64
+ }).get ();
65
+ if (node == null )
66
+ throw new JavaFXLibraryNonFatalException ("Given locator \" " + locator + "\" was not found." );
67
+ } else node = locator ;
68
+ if (isMac ()) {
69
+ // TODO: why asyncFx thread does not work in mac?
70
+ Method method = MethodUtils .getMatchingAccessibleMethod (robot .getClass (), "moveTo" , node .getClass (), Motion .class );
71
+ method .invoke (robot , node , getMotion (motion ));
72
+ } else {
73
+ boolean success = asyncFx (() -> {
74
+ try {
75
+ Method method = MethodUtils .getMatchingAccessibleMethod (robot .getClass (), "moveTo" , node .getClass (), Motion .class );
76
+ method .invoke (robot , node , getMotion (motion ));
77
+ return true ;
78
+ } catch (IllegalAccessException | InvocationTargetException e ) {
79
+ RobotLog .trace ("failed in asyncFx thread moveTo" );
80
+ return false ;
81
+ }
82
+ }).get ();
83
+ if (!success ) throw new JavaFXLibraryNonFatalException ("moveTo: Could not execute move to using locator \" " + locator + "\" " +
84
+ "and motion " + motion );
55
85
}
56
- Method method = MethodUtils .getMatchingAccessibleMethod (robot .getClass (), "moveTo" , locator .getClass (), Motion .class );
57
- return (FxRobotInterface ) method .invoke (robot , locator , getMotion (motion ));
86
+ } catch (InterruptedException | ExecutionException iee ) {
87
+ throw new JavaFXLibraryNonFatalException ("moveTo: Could not execute move to using locator \" " + locator + "\" " +
88
+ "and motion " + motion + " (asyncFx thread): " + iee .getCause ());
89
+ } catch (JavaFXLibraryNonFatalException e ) {
90
+ throw e ;
58
91
} catch (IllegalAccessException | InvocationTargetException e ) {
59
92
throw new JavaFXLibraryNonFatalException ("moveTo: Could not execute move to using locator \" " + locator + "\" " +
60
- "and motion " + motion + ": " + e .getCause (). getMessage (), e );
93
+ "and motion " + motion + ": " + e .getCause ());
61
94
}
62
95
}
63
96
0 commit comments