Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd4549f

Browse files
committed
fix moveTo in osx also
1 parent fd3eba1 commit cd4549f

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

src/main/java/JavaFXLibrary.java

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class JavaFXLibrary extends AnnotationLibrary {
9090
add("launchSwingApplicationInSeparateThread");
9191
add("logApplicationClasspath");
9292
add("logSystemProperties");
93+
add("moveTo");
9394
add("nodeShouldBeHoverable");
9495
add("nodeShouldNotBeHoverable");
9596
add("pushManyTimes");

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

+38-5
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030

3131
import java.lang.reflect.InvocationTargetException;
3232
import java.lang.reflect.Method;
33+
import java.util.concurrent.ExecutionException;
3334

3435
import static javafxlibrary.utils.HelperFunctions.*;
36+
import static org.testfx.util.WaitForAsyncUtils.asyncFx;
3537

3638
@RobotKeywords
3739
public class MoveRobot extends TestFxAdapter {
@@ -46,18 +48,49 @@ public class MoveRobot extends TestFxAdapter {
4648
+ "| ${point} | Create Point | ${x} | ${y} | \n"
4749
+ "| Move To | ${POINT} | VERTICAL_FIRST | | # moves mouse on top of given Point object by moving first vertically and then horizontally |")
4850
@ArgumentNames({ "locator", "motion=DIRECT" })
49-
public FxRobotInterface moveTo(Object locator, String motion) {
51+
public void moveTo(Object locator, String motion) {
5052
checkObjectArgumentNotNull(locator);
5153
try {
5254
RobotLog.info("Moving to target \"" + locator + "\" using motion: \"" + getMotion(motion) + "\"");
55+
Object node;
5356
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);
5585
}
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;
5891
} catch (IllegalAccessException | InvocationTargetException e) {
5992
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());
6194
}
6295
}
6396

src/test/robotframework/acceptance/FindTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Find With Pseudo Class
133133
${root} Find css=VBox HBox VBox HBox StackPane
134134
${target} Find xpath=//Text[@text="150x150"]
135135
Move To ${target}
136-
Wait Until Element Exists pseudo=hover
136+
Wait Until Element Exists pseudo=hover
137137
${result} Find pseudo=hover false ${root}
138138
Should Be Equal ${result} ${target}
139139

src/test/robotframework/acceptance/MoveRobotTest.robot

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Move To Window
8787
8888
Move To Nonexistent Location
8989
[Tags] smoke
90-
Run Keyword And Expect Error unable to find node for query "id=rectangleNOTfound"
90+
Run Keyword And Expect Error Given locator "id=rectangleNOTfound" was not found.
9191
... Move To id=rectangleNOTfound
9292
9393
*** Keywords ***

0 commit comments

Comments
 (0)