Skip to content

Commit 629d976

Browse files
sampesonsoisetupsaikkonen
authored
0.7.1 changes (#58)
* Experimental java agent support JavaFXLibrary can now be attached to process as java agent. * Fix docker-compose up Building the docker demo failed because of missing package versions for the newer Ubuntu image. Base image of the demo is now fixed to bionic tag since Ubuntu updates have broken the build earlier as well. Related Launchpad ticket: https://bugs.launchpad.net/ubuntu/+source/openjfx/+bug/1799946 * Updated documentation (java agent) * Add possibility to configure different directory for log.html in Set Screenshotdir, fixes #17 * java agent documentation fix * Set Classpath failure as warnings and add failIfNotFound argument * Use asyncFx for helperfunctions methods, remove waitForFxEvents usage, failure printout improvements * remove deprecated keywords and methods (enhancement #11) * Set empty string args as nulls, add message for IllegalArgumentException (#53) looks good to me * Development kw asyncfx wrap (#55) * wrap runKeyword to asyncFx so that JavaFX operations are done FX thread * more asyncfx fixes, went through whole code base * new wrapping to asyncfx thread * additional rewrite to have all needed kw's wrapped in FX thread, output and error handling improvements * handle null object properlty, timeout to be generic kw timeout, handle separately wait until kws, kw output improvements * fix hover related kw's * waitUntilExists and waitUntilDoesNotExist improvements * wait until keywords to have overall timeout value, improved printout * fix text prefix to check for quotation marks * fix text prefix to have support for apostrophe (') also * cleanup * fix verifiers hoverable kw's, add test * fix push many times kw * fix osx tests * screenshots to asyncfx thread also in kw failure, fix hover kw's once more * fix osx part and go throught documentation * fix osx part and go throught documentation * fix RunOnFailure to not store screenshot as mapObject to save memory * remove comments * fix moveTo keyword to use asyncFx thread, fixes #57 * fix scroll keywords to do one tick at time from main thread, fix related tests * fix moveTo in osx also Co-authored-by: Turo Soisenniemi <[email protected]> Co-authored-by: Pasi Saikkonen <[email protected]>
1 parent 5d2043c commit 629d976

File tree

7 files changed

+68
-16
lines changed

7 files changed

+68
-16
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<groupId>org.robotframework</groupId>
2222
<artifactId>javafxlibrary</artifactId>
2323
<packaging>jar</packaging>
24-
<version>0.7.0</version>
24+
<version>0.7.1-SNAPSHOT</version>
2525
<properties>
2626
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2727
<jmockit.version>1.44</jmockit.version>

src/main/java/JavaFXLibrary.java

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public class JavaFXLibrary extends AnnotationLibrary {
9494
add("nodeShouldBeHoverable");
9595
add("nodeShouldNotBeHoverable");
9696
add("pushManyTimes");
97+
add("scrollHorizontally");
98+
add("scrollVertically");
9799
add("setImageLogging");
98100
add("setSafeClicking");
99101
add("setScreenshotDirectory");

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/main/java/javafxlibrary/keywords/Keywords/ScrollRobot.java

+21-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import org.robotframework.javalib.annotation.ArgumentNames;
2626
import org.robotframework.javalib.annotation.RobotKeyword;
2727
import org.robotframework.javalib.annotation.RobotKeywords;
28+
import java.util.concurrent.ExecutionException;
29+
import static javafxlibrary.utils.HelperFunctions.sleepFor;
30+
import static org.testfx.util.WaitForAsyncUtils.asyncFx;
2831

2932
@RobotKeywords
3033
public class ScrollRobot extends TestFxAdapter {
@@ -39,7 +42,13 @@ public class ScrollRobot extends TestFxAdapter {
3942
public void scrollVertically(String direction, int amount) {
4043
try {
4144
RobotLog.info("Scrolling \"" + direction + "\" by \"" + amount + "\" ticks.");
42-
robot.scroll(amount, HelperFunctions.getVerticalDirection(direction));
45+
//Scrolling is done one tick at time from main thread as in asyncFx thread it would result only one visible scroll
46+
for (int i = 0; i < amount; i++) {
47+
asyncFx(() -> robot.scroll(1, HelperFunctions.getVerticalDirection(direction))).get();
48+
sleepFor(10);
49+
}
50+
} catch (InterruptedException | ExecutionException iee) {
51+
throw new JavaFXLibraryNonFatalException("Unable to scroll vertically!");
4352
} catch (Exception e) {
4453
if(e instanceof JavaFXLibraryNonFatalException)
4554
throw e;
@@ -62,9 +71,17 @@ public void scrollVertically(String direction, int amount) {
6271
public void scrollHorizontally(String direction, int amount) {
6372
try {
6473
RobotLog.info("Scrolling \"" + direction + "\" by \"" + amount + "\" ticks.");
65-
robot.press(KeyCode.SHIFT);
66-
robot.scroll(amount, HelperFunctions.getHorizontalDirection(direction));
67-
robot.release(KeyCode.SHIFT);
74+
//Scrolling is done one tick at time from main thread as in asyncFx thread it would result only one visible scroll
75+
for (int i = 0; i < amount; i++) {
76+
asyncFx(() -> {
77+
robot.press(KeyCode.SHIFT);
78+
robot.scroll(1, HelperFunctions.getHorizontalDirection(direction));
79+
robot.release(KeyCode.SHIFT);
80+
}).get();
81+
sleepFor(10);
82+
}
83+
} catch (InterruptedException | ExecutionException iee) {
84+
throw new JavaFXLibraryNonFatalException("Unable to scroll horizontally!");
6885
} catch (Exception e) {
6986
if(e instanceof JavaFXLibraryNonFatalException)
7087
throw e;

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 ***

src/test/robotframework/acceptance/ScrollRobotTest.robot

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Scroll down
2424
Scroll Vertically DOWN 25
2525
Verify String ${VERTICAL_TOTAL} ${TARGET_DISTANCE}
2626
Verify String ${VERTICAL_ACTUAL} -${TARGET_DISTANCE}
27-
Verify String ${VERTICAL_EVENTS} 1
27+
Verify String ${VERTICAL_EVENTS} 25
2828
2929
Scroll up
3030
[Tags] smoke
@@ -34,7 +34,7 @@ Scroll up
3434
Scroll Vertically UP 25
3535
Verify String ${VERTICAL_TOTAL} ${TARGET_DISTANCE}
3636
Verify String ${VERTICAL_ACTUAL} ${TARGET_DISTANCE}
37-
Verify String ${VERTICAL_EVENTS} 1
37+
Verify String ${VERTICAL_EVENTS} 25
3838
3939
Scroll Once Vertically
4040
[Tags] smoke
@@ -54,7 +54,7 @@ Scroll Left
5454
Scroll Horizontally LEFT 25
5555
Verify String ${HORIZONTAL_TOTAL} ${TARGET_DISTANCE}
5656
Verify String ${HORIZONTAL_ACTUAL} ${TARGET_DISTANCE}
57-
Verify String ${HORIZONTAL_EVENTS} 1
57+
Verify String ${HORIZONTAL_EVENTS} 25
5858
5959
Scroll Right
6060
[Tags] smoke
@@ -65,7 +65,7 @@ Scroll Right
6565
Scroll Horizontally RIGHT 10
6666
Verify String ${HORIZONTAL_TOTAL} ${TARGET_DISTANCE}
6767
Verify String ${HORIZONTAL_ACTUAL} -${TARGET_DISTANCE}
68-
Verify String ${HORIZONTAL_EVENTS} 1
68+
Verify String ${HORIZONTAL_EVENTS} 10
6969
7070
*** Keywords ***
7171
Setup all tests

0 commit comments

Comments
 (0)