Fix selenium issue with fieldset nested in disabled fieldset not being disabled

This commit is contained in:
Thomas Walpole 2018-06-27 12:53:58 -07:00
parent 83172fddab
commit 06265cefd5
5 changed files with 38 additions and 33 deletions

View File

@ -74,6 +74,8 @@ Capybara.add_selector(:fieldset) do
xpath = xpath[XPath.child(:legend)[XPath.string.n.is(legend)]] if legend
xpath
end
node_filter(:disabled, :boolean) { |node, value| !(value ^ node.disabled?) }
end
Capybara.add_selector(:link) do

View File

@ -142,8 +142,7 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
def disabled?
return true unless native.enabled?
# WebDriver only defines `disabled?` for form controls but fieldset makes sense too
return boolean_attr(self[:disabled]) if tag_name == 'fieldset'
false
tag_name == 'fieldset' && find_xpath("ancestor-or-self::fieldset[@disabled]").any?
end
def content_editable?

View File

@ -13,8 +13,10 @@ class Capybara::Selenium::MarionetteNode < Capybara::Selenium::Node
end
def disabled?
return true if super
# Not sure exactly what version of FF fixed the below issue, but it is definitely fixed in 61+
return super unless driver.browser.capabilities[:browser_version].to_f < 61.0
return true if super
# workaround for selenium-webdriver/geckodriver reporting elements as enabled when they are nested in disabling elements
if %w[option optgroup].include? tag_name
find_xpath("parent::*[self::optgroup or self::select]")[0].disabled?

View File

@ -208,6 +208,12 @@ Capybara::SpecHelper.spec "node" do
expect(@session.find('//select[@id="form_disabled_select2"]/option').disabled?).to be true
expect(@session.find('//select[@id="form_title"]/option[1]').disabled?).to be false
end
it "should be disabled for all elements that are CSS :disabled" do
@session.visit('/form')
# sanity check
expect(@session.all(:css, ':disabled')).to all(be_disabled)
end
end
describe "#visible?" do

View File

@ -370,7 +370,6 @@ New line after and before textarea tag
</label>
</p>
<p>
<label for="form_disabled_file">
Disabled File
@ -378,38 +377,35 @@ New line after and before textarea tag
</label>
</p>
<p>
<fieldset>
<input name="form[enabled_fieldset_child]" id="form_enabled_fieldset_child"/>
</fieldset>
<fieldset disabled="disabled" id="form_disabled_fieldset">
<legend>Disabled Child</legend>
<input name="form[disabled_fieldset_child]" id="form_disabled_fieldset_child"/>
<select>
<option>Disabled Child Option</option>
</select>
</fieldset>
<fieldset disabled="disabled">
<legend>
Nested Disabled
<input type="checkbox" name="form[disabled_fieldeset_legend_child]" id="form_disabled_fieldset_legend_child"/>
</legend>
<legend>
Another Legend
<input type="checkbox" name="form[disabled_fieldeset_second_legend_child]" id="form_disabled_fieldset_second_legend_child"/>
</legend>
<fieldset>
<input name="form[enabled_fieldset_child]" id="form_enabled_fieldset_child"/>
</fieldset>
</p>
<p>
<fieldset disabled="disabled" id="form_disabled_fieldset">
<legend>Disabled Child</legend>
<input name="form[disabled_fieldset_child]" id="form_disabled_fieldset_child"/>
<select>
<option>Disabled Child Option</option>
</select>
</fieldset>
<fieldset disabled="disabled">
<legend>
Nested Disabled
<input type="checkbox" name="form[disabled_fieldeset_legend_child]" id="form_disabled_fieldset_legend_child"/>
Disabled?
<input id="form_disabled_fieldset_descendant_legend_child">
</legend>
<legend>
Another Legend
<input type="checkbox" name="form[disabled_fieldeset_second_legend_child]" id="form_disabled_fieldset_second_legend_child"/>
</legend>
<p>
<fieldset>
<input name="form[disabled_fieldset_descendant]" id="form_disabled_fieldset_descendant"/>
</fieldset>
</p>
<input name="form[disabled_fieldset_descendant]" id="form_disabled_fieldset_descendant"/>
</fieldset>
</p>
</fieldset>
<p>
<select>
@ -461,7 +457,7 @@ New line after and before textarea tag
</form>
<form id="form2" action="/form" method="post">
<input type="text" name="form[which_form]" value="form2" id="form_which_form"/>
<input type="text" name="form[which_form]" value="form2" id="form_which_form2"/>
<input type="submit" name="form[unused]" value="unused"/>
<button type="submit" name="form[other_form_button]" value="other_form_button" form="form1">Form1</button>
</form>