From f0c908d48810146ddde0fd37a72b08c0b14b1e23 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 30 Oct 2020 17:14:39 +0800 Subject: [PATCH 1/2] Fix Rubocop warnings about unneeded # rubocop:disable instructions --- lib/capybara/spec/session/find_spec.rb | 2 +- lib/capybara/spec/spec_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/capybara/spec/session/find_spec.rb b/lib/capybara/spec/session/find_spec.rb index fd6190b32..150786d4b 100644 --- a/lib/capybara/spec/session/find_spec.rb +++ b/lib/capybara/spec/session/find_spec.rb @@ -60,7 +60,7 @@ end end - context 'with frozen time', requires: [:js] do # rubocop:disable RSpec/EmptyExampleGroup + context 'with frozen time', requires: [:js] do if defined?(Process::CLOCK_MONOTONIC) it 'will time out even if time is frozen' do @session.visit('/with_js') diff --git a/lib/capybara/spec/spec_helper.rb b/lib/capybara/spec/spec_helper.rb index 3ee4e8731..7a3eb2ea4 100644 --- a/lib/capybara/spec/spec_helper.rb +++ b/lib/capybara/spec/spec_helper.rb @@ -84,7 +84,7 @@ def run_specs(session, name, **options, &filter_block) end specs.each do |spec_name, spec_options, block| - describe spec_name, *spec_options do # rubocop:disable RSpec/EmptyExampleGroup + describe spec_name, *spec_options do class_eval(&block) end end From b31d067ac841719cd6197444c3584d640b2bc6d2 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 30 Oct 2020 17:40:52 +0800 Subject: [PATCH 2/2] Added `Capybara.disable_animation_extra_css` option, which can be used to add additional CSS rules to the AnimationDisabler middleware --- .vscode/settings.json | 3 +++ History.md | 2 ++ lib/capybara/server/animation_disabler.rb | 7 ++++++- lib/capybara/session/config.rb | 6 ++++-- lib/capybara/spec/spec_helper.rb | 1 + spec/shared_selenium_session.rb | 18 ++++++++++++++++++ 6 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..53124f58f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "files.trimTrailingWhitespace": true +} \ No newline at end of file diff --git a/History.md b/History.md index 2110b4e35..c1c0d9515 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,8 @@ Release date: unreleased ### Added * Ability to fill in with emoji when using Chrome with selenium driver (Firefox already worked) +* Added `Capybara.disable_animation_extra_css` option, which can be used to add additional CSS rules + to the AnimationDisabler middleware [Nathan Broadbent] ### Fixed diff --git a/lib/capybara/server/animation_disabler.rb b/lib/capybara/server/animation_disabler.rb index 86d86596e..4e5188538 100644 --- a/lib/capybara/server/animation_disabler.rb +++ b/lib/capybara/server/animation_disabler.rb @@ -16,7 +16,11 @@ def self.selector_for(css_or_bool) def initialize(app) @app = app - @disable_markup = format(DISABLE_MARKUP_TEMPLATE, selector: self.class.selector_for(Capybara.disable_animation)) + @disable_markup = format( + DISABLE_MARKUP_TEMPLATE, + selector: self.class.selector_for(Capybara.disable_animation), + extra_css: Capybara.disable_animation_extra_css || '' + ) end def call(env) @@ -51,6 +55,7 @@ def insert_disable(html) animation-duration: 0s !important; animation-delay: 0s !important; scroll-behavior: auto !important; + %s } HTML diff --git a/lib/capybara/session/config.rb b/lib/capybara/session/config.rb index 3ccdf5b50..d401f9d07 100644 --- a/lib/capybara/session/config.rb +++ b/lib/capybara/session/config.rb @@ -7,8 +7,8 @@ class SessionConfig OPTIONS = %i[always_include_port run_server default_selector default_max_wait_time ignore_hidden_elements automatic_reload match exact exact_text raise_server_errors visible_text_only automatic_label_click enable_aria_label save_path asset_host default_host app_host - server_host server_port server_errors default_set_options disable_animation test_id - predicates_wait default_normalize_ws w3c_click_offset enable_aria_role].freeze + server_host server_port server_errors default_set_options disable_animation disable_animation_extra_css + test_id predicates_wait default_normalize_ws w3c_click_offset enable_aria_role].freeze attr_accessor(*OPTIONS) @@ -57,6 +57,8 @@ class SessionConfig # See {Capybara.configure} # @!method disable_animation # See {Capybara.configure} + # @!method disable_animation_extra_css + # See {Capybara.configure} # @!method test_id # See {Capybara.configure} # @!method default_normalize_ws diff --git a/lib/capybara/spec/spec_helper.rb b/lib/capybara/spec/spec_helper.rb index 7a3eb2ea4..9e503a01a 100644 --- a/lib/capybara/spec/spec_helper.rb +++ b/lib/capybara/spec/spec_helper.rb @@ -33,6 +33,7 @@ def reset! Capybara.enable_aria_role = false Capybara.default_set_options = {} Capybara.disable_animation = false + Capybara.disable_animation_extra_css = nil Capybara.test_id = nil Capybara.predicates_wait = true Capybara.default_normalize_ws = false diff --git a/spec/shared_selenium_session.rb b/spec/shared_selenium_session.rb index d6dc023d8..94f4779eb 100644 --- a/spec/shared_selenium_session.rb +++ b/spec/shared_selenium_session.rb @@ -475,6 +475,24 @@ end end end + + describe 'Capybara#disable_animation_extra_css' do + before(:context) do # rubocop:disable RSpec/BeforeAfterAll + skip "Safari doesn't support multiple sessions" if safari?(session) + # NOTE: Although Capybara.SpecHelper.reset! sets Capybara.disable_animation to false, + # it doesn't affect any of these tests because the settings are applied per-session + Capybara.disable_animation = true + Capybara.disable_animation_extra_css = 'color: rgba(0, 0, 249, 1);' + @animation_session = Capybara::Session.new(session.mode, TestApp.new) + end + + it 'should add custom CSS rules to the selector' do + @animation_session.visit('with_animation') + rgba_color = @animation_session.find(:css, '#with_animation .animation').native.css_value('color') + expect(rgba_color).to eq 'rgba(0, 0, 249, 1)' + end + end + # rubocop:enable RSpec/InstanceVariable describe ':element selector' do