1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

reset the style after attaching file

This commit is contained in:
Thomas Walpole 2017-01-09 12:50:56 -08:00
parent c5f3b452b9
commit 4febe3a473
2 changed files with 28 additions and 2 deletions

View file

@ -244,7 +244,11 @@ module Capybara
ff = find(:file_field, locator, options.merge({visible: :all}))
_update_style(ff, style)
if ff.visible?
ff.set(path)
begin
ff.set(path)
ensure
_reset_style(ff)
end
else
raise ExpectationNotMet, "The style changes in :make_visible did not make the file input visible"
end
@ -257,6 +261,7 @@ module Capybara
def _update_style(element, style)
script = <<-JS
var el = arguments[0];
el.capybara_style_cache = el.style.cssText;
var css = arguments[1];
for (var prop in css){
if (css.hasOwnProperty(prop)) {
@ -267,10 +272,25 @@ module Capybara
begin
session.execute_script(script, element, style)
rescue Capybara::NotSupportedByDriverError
warn "The :style option is not supported by the current driver - ignoring"
warn "The :make_visible option is not supported by the current driver - ignoring"
end
end
def _reset_style(element)
script = <<-JS
var el = arguments[0];
if (el.hasOwnProperty('capybara_style_cache')) {
el.style=el.capybara_style_cache;
delete el.capybara_style_cache;
}
JS
begin
session.execute_script(script, element)
rescue
end
end
def _check_with_label(selector, checked, locator, options)
locator, options = nil, locator if locator.is_a? Hash
allow_label_click = options.delete(:allow_label_click) { Capybara.automatic_label_click }

View file

@ -130,5 +130,11 @@ Capybara::SpecHelper.spec "#attach_file" do
@session.attach_file("hidden_file", __FILE__, make_visible: { color: 'red' })
}.to raise_error(Capybara::ExpectationNotMet)
end
it "resets the style when done" do
@session.visit('/with_js')
@session.attach_file("hidden_file", __FILE__, make_visible: true)
expect(@session.evaluate_script("arguments[0].style.display", @session.find(:css, '#hidden_file', visible: :all))).to eq 'none'
end
end
end