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

Skip to content

Commit fd3eba1

Browse files
committed
fix scroll keywords to do one tick at time from main thread, fix related tests
1 parent 8b3a17e commit fd3eba1

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/main/java/JavaFXLibrary.java

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

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/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)