Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Capybara.disable_animation_extra_css option to insert extra CSS in Capybara::Server::AnimationDisabler::DISABLE_MARKUP_TEMPLATE #2418

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files.trimTrailingWhitespace": true
}
2 changes: 2 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion lib/capybara/server/animation_disabler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -51,6 +55,7 @@ def insert_disable(html)
animation-duration: 0s !important;
animation-delay: 0s !important;
scroll-behavior: auto !important;
%<extra_css>s
}
</style>
HTML
Expand Down
6 changes: 4 additions & 2 deletions lib/capybara/session/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/spec/session/find_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion lib/capybara/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,7 +85,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
Expand Down
18 changes: 18 additions & 0 deletions spec/shared_selenium_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down