File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
### Added
4
4
5
- ` Ferrum::Network::Request#headers ` are enhanced and supplemented with ` Network.requestWillBeSentExtraInfo ` [ #506 ]
6
- ` Ferrum::Page#off ` to unsubscribe from CDP events [ #455 ]
5
+ - ` Ferrum::Network::Request#headers ` are enhanced and supplemented with ` Network.requestWillBeSentExtraInfo ` [ #506 ]
6
+ - ` Ferrum::Page#off ` to unsubscribe from CDP events [ #455 ]
7
+ - ` Ferrum::Mouse#scroll_by ` to be able to scroll by, as alternative to ` scroll_to ` [ #514 ]
7
8
8
9
### Changed
9
10
Original file line number Diff line number Diff line change @@ -18,6 +18,23 @@ def initialize(page)
18
18
@buttons = 0
19
19
end
20
20
21
+ #
22
+ # Scroll page by the given amount x, y.
23
+ #
24
+ # @param [Integer] x
25
+ # The horizontal pixel value that you want to scroll by.
26
+ #
27
+ # @param [Integer] y
28
+ # The vertical pixel value that you want to scroll by.
29
+ #
30
+ # @example
31
+ # browser.go_to("https://www.google.com/search?q=Ruby+headless+driver+for+Capybara")
32
+ # browser.mouse.scroll_by(0, 400)
33
+ #
34
+ def scroll_by ( x , y )
35
+ tap { @page . execute ( "window.scrollBy(#{ x } , #{ y } )" ) }
36
+ end
37
+
21
38
#
22
39
# Scroll page to a given x, y coordinates.
23
40
#
Original file line number Diff line number Diff line change 32
32
end
33
33
end
34
34
35
+ describe "#scroll_by" do
36
+ it "allows the page to be scrolled" do
37
+ browser . go_to ( "/ferrum/long_page" )
38
+ browser . resize ( width : 10 , height : 10 )
39
+ browser . mouse . scroll_by ( 30 , 70 )
40
+ browser . mouse . scroll_by ( 40 , -50 )
41
+ browser . mouse . scroll_by ( -60 , 0 )
42
+ expect (
43
+ browser . evaluate ( "[window.scrollX, window.scrollY]" )
44
+ ) . to eq ( [ 10 , 20 ] )
45
+ end
46
+ end
47
+
35
48
describe "#scroll_to" do
36
49
it "allows the page to be scrolled" do
37
50
browser . go_to ( "/ferrum/long_page" )
You can’t perform that action at this time.
0 commit comments