25
25
import org .robotframework .javalib .annotation .ArgumentNames ;
26
26
import org .robotframework .javalib .annotation .RobotKeyword ;
27
27
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 ;
28
31
29
32
@ RobotKeywords
30
33
public class ScrollRobot extends TestFxAdapter {
@@ -39,7 +42,13 @@ public class ScrollRobot extends TestFxAdapter {
39
42
public void scrollVertically (String direction , int amount ) {
40
43
try {
41
44
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!" );
43
52
} catch (Exception e ) {
44
53
if (e instanceof JavaFXLibraryNonFatalException )
45
54
throw e ;
@@ -62,9 +71,17 @@ public void scrollVertically(String direction, int amount) {
62
71
public void scrollHorizontally (String direction , int amount ) {
63
72
try {
64
73
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!" );
68
85
} catch (Exception e ) {
69
86
if (e instanceof JavaFXLibraryNonFatalException )
70
87
throw e ;
0 commit comments