Skip to content

Commit f308536

Browse files
authored
Merge pull request #170 from rubycdp/animations
Implement Animations
2 parents 1561ae2 + 9a37de7 commit f308536

File tree

7 files changed

+90
-2
lines changed

7 files changed

+90
-2
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Web design by [Evrone](https://evrone.com/), what else
4949
* [Frames](https://github.com/rubycdp/ferrum#frames)
5050
* [Frame](https://github.com/rubycdp/ferrum#frame)
5151
* [Dialog](https://github.com/rubycdp/ferrum#dialog)
52+
* [Animation](https://github.com/rubycdp/ferrum#animation)
5253
* [Thread safety](https://github.com/rubycdp/ferrum#thread-safety)
5354
* [Development](https://github.com/rubycdp/ferrum#development)
5455
* [Contributing](https://github.com/rubycdp/ferrum#contributing)
@@ -978,6 +979,28 @@ end
978979
browser.go_to("https://google.com")
979980
```
980981

982+
## Animation
983+
984+
You can slow down or speed up CSS animations.
985+
986+
#### playback_rate : `Integer`
987+
988+
Returns playback rate for CSS animations, defaults to `1`.
989+
990+
991+
#### playback_rate = value
992+
993+
Sets playback rate of CSS animations
994+
995+
* value `Integer`
996+
997+
```ruby
998+
browser = Ferrum::Browser.new
999+
browser.playback_rate = 2000
1000+
browser.go_to("https://google.com")
1001+
browser.playback_rate # => 2000
1002+
```
1003+
9811004

9821005
## Thread safety ##
9831006

lib/ferrum/browser.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class Browser
2626
frames frame_by main_frame
2727
evaluate evaluate_on evaluate_async execute evaluate_func
2828
add_script_tag add_style_tag bypass_csp
29-
on goto position position=] => :page
29+
on goto position position=
30+
playback_rate playback_rate=] => :page
3031
delegate %i[default_user_agent] => :process
3132

3233
attr_reader :client, :process, :contexts, :logger, :js_errors, :pending_connection_errors,

lib/ferrum/page.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require "ferrum/network"
1010
require "ferrum/page/frames"
1111
require "ferrum/page/screenshot"
12+
require "ferrum/page/animation"
1213
require "ferrum/browser/client"
1314

1415
module Ferrum
@@ -35,7 +36,7 @@ def reset
3536
execution_id evaluate evaluate_on evaluate_async execute evaluate_func
3637
add_script_tag add_style_tag] => :main_frame
3738

38-
include Frames, Screenshot
39+
include Frames, Screenshot, Animation
3940

4041
attr_accessor :referrer
4142
attr_reader :target_id, :browser,

lib/ferrum/page/animation.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
module Ferrum
4+
class Page
5+
module Animation
6+
def playback_rate
7+
command("Animation.getPlaybackRate")["playbackRate"]
8+
end
9+
10+
11+
def playback_rate=(value)
12+
command("Animation.setPlaybackRate", playbackRate: value)
13+
end
14+
end
15+
end
16+
end

spec/page/animation_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module Ferrum
4+
describe Page::Animation do
5+
it "gets default playback rate" do
6+
browser.go_to("/animation")
7+
8+
expect(browser.playback_rate).to eq(1)
9+
end
10+
11+
it "sets playback rate" do
12+
browser.playback_rate = 2000
13+
14+
browser.go_to("/animation")
15+
16+
expect(browser.playback_rate).to eq(2000)
17+
end
18+
end
19+
end

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
config.before(:all) do
3131
base_url = Ferrum::Server.server.base_url
3232
options = { base_url: base_url }
33+
options.merge!(headless: false) if ENV["HEADLESS"] == "false"
3334

3435
if ENV["CI"]
3536
FERRUM_LOGGER = StringIO.new

spec/support/views/animation.erb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style>
5+
.animated {
6+
width: 100px;
7+
height: 100px;
8+
background-color: red;
9+
position: relative;
10+
animation-name: example;
11+
animation-duration: 2s;
12+
animation-iteration-count: infinite;
13+
}
14+
15+
@keyframes example {
16+
0% {background-color:red; left:0px; top:0px;}
17+
25% {background-color:yellow; left:200px; top:0px;}
18+
50% {background-color:blue; left:200px; top:200px;}
19+
75% {background-color:green; left:0px; top:200px;}
20+
100% {background-color:red; left:0px; top:0px;}
21+
}
22+
</style>
23+
</head>
24+
<body>
25+
<div class="animated"></div>
26+
</body>
27+
</html>

0 commit comments

Comments
 (0)