From 629d9767b293f45330f513a05d68c60198d3ac95 Mon Sep 17 00:00:00 2001 From: Sami Pesonen Date: Wed, 11 Nov 2020 08:23:27 +0200 Subject: [PATCH 1/6] 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 Co-authored-by: Pasi Saikkonen --- pom.xml | 2 +- src/main/java/JavaFXLibrary.java | 2 + .../keywords/Keywords/MoveRobot.java | 43 ++++++++++++++++--- .../keywords/Keywords/ScrollRobot.java | 25 +++++++++-- .../robotframework/acceptance/FindTest.robot | 2 +- .../acceptance/MoveRobotTest.robot | 2 +- .../acceptance/ScrollRobotTest.robot | 8 ++-- 7 files changed, 68 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 319bb43..8a0a4ed 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ org.robotframework javafxlibrary jar - 0.7.0 + 0.7.1-SNAPSHOT UTF-8 1.44 diff --git a/src/main/java/JavaFXLibrary.java b/src/main/java/JavaFXLibrary.java index 13adf21..a7c4b4d 100644 --- a/src/main/java/JavaFXLibrary.java +++ b/src/main/java/JavaFXLibrary.java @@ -94,6 +94,8 @@ public class JavaFXLibrary extends AnnotationLibrary { add("nodeShouldBeHoverable"); add("nodeShouldNotBeHoverable"); add("pushManyTimes"); + add("scrollHorizontally"); + add("scrollVertically"); add("setImageLogging"); add("setSafeClicking"); add("setScreenshotDirectory"); diff --git a/src/main/java/javafxlibrary/keywords/Keywords/MoveRobot.java b/src/main/java/javafxlibrary/keywords/Keywords/MoveRobot.java index 4016449..9d72377 100644 --- a/src/main/java/javafxlibrary/keywords/Keywords/MoveRobot.java +++ b/src/main/java/javafxlibrary/keywords/Keywords/MoveRobot.java @@ -30,8 +30,10 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.concurrent.ExecutionException; import static javafxlibrary.utils.HelperFunctions.*; +import static org.testfx.util.WaitForAsyncUtils.asyncFx; @RobotKeywords public class MoveRobot extends TestFxAdapter { @@ -46,18 +48,49 @@ public class MoveRobot extends TestFxAdapter { + "| ${point} | Create Point | ${x} | ${y} | \n" + "| Move To | ${POINT} | VERTICAL_FIRST | | # moves mouse on top of given Point object by moving first vertically and then horizontally |") @ArgumentNames({ "locator", "motion=DIRECT" }) - public FxRobotInterface moveTo(Object locator, String motion) { + public void moveTo(Object locator, String motion) { checkObjectArgumentNotNull(locator); try { RobotLog.info("Moving to target \"" + locator + "\" using motion: \"" + getMotion(motion) + "\""); + Object node; if (locator instanceof String) { - locator = objectToNode(locator); + node = asyncFx(() -> { + try { + return objectToNode(locator); + } catch (Exception e) { + RobotLog.info("Locator not found: " + e.getCause()); + return null; + } + }).get(); + if (node == null) + throw new JavaFXLibraryNonFatalException("Given locator \"" + locator + "\" was not found."); + } else node = locator; + if (isMac()) { + // TODO: why asyncFx thread does not work in mac? + Method method = MethodUtils.getMatchingAccessibleMethod(robot.getClass(), "moveTo", node.getClass(), Motion.class); + method.invoke(robot, node, getMotion(motion)); + } else { + boolean success = asyncFx(() -> { + try { + Method method = MethodUtils.getMatchingAccessibleMethod(robot.getClass(), "moveTo", node.getClass(), Motion.class); + method.invoke(robot, node, getMotion(motion)); + return true; + } catch (IllegalAccessException | InvocationTargetException e) { + RobotLog.trace("failed in asyncFx thread moveTo"); + return false; + } + }).get(); + if (!success) throw new JavaFXLibraryNonFatalException("moveTo: Could not execute move to using locator \"" + locator + "\" " + + "and motion " + motion); } - Method method = MethodUtils.getMatchingAccessibleMethod(robot.getClass(), "moveTo", locator.getClass(), Motion.class); - return (FxRobotInterface) method.invoke(robot, locator, getMotion(motion)); + } catch (InterruptedException | ExecutionException iee) { + throw new JavaFXLibraryNonFatalException("moveTo: Could not execute move to using locator \"" + locator + "\" " + + "and motion " + motion + " (asyncFx thread): " + iee.getCause()); + } catch (JavaFXLibraryNonFatalException e) { + throw e; } catch (IllegalAccessException | InvocationTargetException e) { throw new JavaFXLibraryNonFatalException("moveTo: Could not execute move to using locator \"" + locator + "\" " + - "and motion " + motion + ": " + e.getCause().getMessage(), e); + "and motion " + motion + ": " + e.getCause()); } } diff --git a/src/main/java/javafxlibrary/keywords/Keywords/ScrollRobot.java b/src/main/java/javafxlibrary/keywords/Keywords/ScrollRobot.java index 80e09c1..22af20e 100644 --- a/src/main/java/javafxlibrary/keywords/Keywords/ScrollRobot.java +++ b/src/main/java/javafxlibrary/keywords/Keywords/ScrollRobot.java @@ -25,6 +25,9 @@ import org.robotframework.javalib.annotation.ArgumentNames; import org.robotframework.javalib.annotation.RobotKeyword; import org.robotframework.javalib.annotation.RobotKeywords; +import java.util.concurrent.ExecutionException; +import static javafxlibrary.utils.HelperFunctions.sleepFor; +import static org.testfx.util.WaitForAsyncUtils.asyncFx; @RobotKeywords public class ScrollRobot extends TestFxAdapter { @@ -39,7 +42,13 @@ public class ScrollRobot extends TestFxAdapter { public void scrollVertically(String direction, int amount) { try { RobotLog.info("Scrolling \"" + direction + "\" by \"" + amount + "\" ticks."); - robot.scroll(amount, HelperFunctions.getVerticalDirection(direction)); + //Scrolling is done one tick at time from main thread as in asyncFx thread it would result only one visible scroll + for (int i = 0; i < amount; i++) { + asyncFx(() -> robot.scroll(1, HelperFunctions.getVerticalDirection(direction))).get(); + sleepFor(10); + } + } catch (InterruptedException | ExecutionException iee) { + throw new JavaFXLibraryNonFatalException("Unable to scroll vertically!"); } catch (Exception e) { if(e instanceof JavaFXLibraryNonFatalException) throw e; @@ -62,9 +71,17 @@ public void scrollVertically(String direction, int amount) { public void scrollHorizontally(String direction, int amount) { try { RobotLog.info("Scrolling \"" + direction + "\" by \"" + amount + "\" ticks."); - robot.press(KeyCode.SHIFT); - robot.scroll(amount, HelperFunctions.getHorizontalDirection(direction)); - robot.release(KeyCode.SHIFT); + //Scrolling is done one tick at time from main thread as in asyncFx thread it would result only one visible scroll + for (int i = 0; i < amount; i++) { + asyncFx(() -> { + robot.press(KeyCode.SHIFT); + robot.scroll(1, HelperFunctions.getHorizontalDirection(direction)); + robot.release(KeyCode.SHIFT); + }).get(); + sleepFor(10); + } + } catch (InterruptedException | ExecutionException iee) { + throw new JavaFXLibraryNonFatalException("Unable to scroll horizontally!"); } catch (Exception e) { if(e instanceof JavaFXLibraryNonFatalException) throw e; diff --git a/src/test/robotframework/acceptance/FindTest.robot b/src/test/robotframework/acceptance/FindTest.robot index 9c291e0..4264684 100644 --- a/src/test/robotframework/acceptance/FindTest.robot +++ b/src/test/robotframework/acceptance/FindTest.robot @@ -133,7 +133,7 @@ Find With Pseudo Class ${root} Find css=VBox HBox VBox HBox StackPane ${target} Find xpath=//Text[@text="150x150"] Move To ${target} - Wait Until Element Exists pseudo=hover + Wait Until Element Exists pseudo=hover ${result} Find pseudo=hover false ${root} Should Be Equal ${result} ${target} diff --git a/src/test/robotframework/acceptance/MoveRobotTest.robot b/src/test/robotframework/acceptance/MoveRobotTest.robot index e0a74b3..d9384c0 100644 --- a/src/test/robotframework/acceptance/MoveRobotTest.robot +++ b/src/test/robotframework/acceptance/MoveRobotTest.robot @@ -87,7 +87,7 @@ Move To Window Move To Nonexistent Location [Tags] smoke - Run Keyword And Expect Error unable to find node for query "id=rectangleNOTfound" + Run Keyword And Expect Error Given locator "id=rectangleNOTfound" was not found. ... Move To id=rectangleNOTfound *** Keywords *** diff --git a/src/test/robotframework/acceptance/ScrollRobotTest.robot b/src/test/robotframework/acceptance/ScrollRobotTest.robot index cc114ed..e081994 100644 --- a/src/test/robotframework/acceptance/ScrollRobotTest.robot +++ b/src/test/robotframework/acceptance/ScrollRobotTest.robot @@ -24,7 +24,7 @@ Scroll down Scroll Vertically DOWN 25 Verify String ${VERTICAL_TOTAL} ${TARGET_DISTANCE} Verify String ${VERTICAL_ACTUAL} -${TARGET_DISTANCE} - Verify String ${VERTICAL_EVENTS} 1 + Verify String ${VERTICAL_EVENTS} 25 Scroll up [Tags] smoke @@ -34,7 +34,7 @@ Scroll up Scroll Vertically UP 25 Verify String ${VERTICAL_TOTAL} ${TARGET_DISTANCE} Verify String ${VERTICAL_ACTUAL} ${TARGET_DISTANCE} - Verify String ${VERTICAL_EVENTS} 1 + Verify String ${VERTICAL_EVENTS} 25 Scroll Once Vertically [Tags] smoke @@ -54,7 +54,7 @@ Scroll Left Scroll Horizontally LEFT 25 Verify String ${HORIZONTAL_TOTAL} ${TARGET_DISTANCE} Verify String ${HORIZONTAL_ACTUAL} ${TARGET_DISTANCE} - Verify String ${HORIZONTAL_EVENTS} 1 + Verify String ${HORIZONTAL_EVENTS} 25 Scroll Right [Tags] smoke @@ -65,7 +65,7 @@ Scroll Right Scroll Horizontally RIGHT 10 Verify String ${HORIZONTAL_TOTAL} ${TARGET_DISTANCE} Verify String ${HORIZONTAL_ACTUAL} -${TARGET_DISTANCE} - Verify String ${HORIZONTAL_EVENTS} 1 + Verify String ${HORIZONTAL_EVENTS} 10 *** Keywords *** Setup all tests From e158741b5c5b077908dac4f45734b12ef2febbf3 Mon Sep 17 00:00:00 2001 From: Sami Pesonen Date: Wed, 11 Nov 2020 08:32:59 +0200 Subject: [PATCH 2/6] version to 0.7.1 --- BUILD.md | 1 + README.md | 4 ++-- docs/javafxlibrary.html | 4 ++-- pom.xml | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/BUILD.md b/BUILD.md index 7265cc9..34497f5 100644 --- a/BUILD.md +++ b/BUILD.md @@ -25,6 +25,7 @@ JavaFXLibrary uses Apache Maven as a build tool. * update library version to x.x.x in pom.xml * run tests ``mvn clean verify`` * copy target/robotframework/libdoc/javafxlibrary.html under docs directory (check that README.md links to correct file) +* update links in README.md to point correct version in maven central * ``git commit -m "version to x.x.x" pom.xml docs/javafxlibrary.html`` * create tag ``git tag -a x.x.x`` * push ``git push origin master`` and ``git push origin x.x.x`` diff --git a/README.md b/README.md index 57c71b4..6d74771 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ JavaFXLibrary works with both Jython (local and remote use) and Python (remote o JavaFXLibrary is tested to work with Java 8 and Robot Framework 3.2.1 or later. ## Keyword documentation -See keyword [documentation](https://repo1.maven.org/maven2/org/robotframework/javafxlibrary/0.7.0/javafxlibrary-0.7.0.html). +See keyword [documentation](https://repo1.maven.org/maven2/org/robotframework/javafxlibrary/0.7.1/javafxlibrary-0.7.1.html). -For editors (IDEs) keyword documentation can be obtained from [here](https://repo1.maven.org/maven2/org/robotframework/javafxlibrary/0.7.0/javafxlibrary-0.7.0.xml). +For editors (IDEs) keyword documentation can be obtained from [here](https://repo1.maven.org/maven2/org/robotframework/javafxlibrary/0.7.1/javafxlibrary-0.7.1.xml). ## Taking the library into use ### As a local library diff --git a/docs/javafxlibrary.html b/docs/javafxlibrary.html index ae25031..b2179aa 100644 --- a/docs/javafxlibrary.html +++ b/docs/javafxlibrary.html @@ -5,7 +5,7 @@ - +