Skip to content

Commit

Permalink
Fix selenium issue with fieldset nested in disabled fieldset not bein…
Browse files Browse the repository at this point in the history
…g disabled
  • Loading branch information
twalpole committed Jun 27, 2018
1 parent 83172fd commit 06265ce
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
2 changes: 2 additions & 0 deletions lib/capybara/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
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
Expand Down
3 changes: 1 addition & 2 deletions lib/capybara/selenium/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ def selected?; boolean_attr(native.selected?); end
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?
Expand Down
4 changes: 3 additions & 1 deletion lib/capybara/selenium/nodes/marionette_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def click(keys = [], **options)
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?
Expand Down
6 changes: 6 additions & 0 deletions lib/capybara/spec/session/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@
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
Expand Down
56 changes: 26 additions & 30 deletions lib/capybara/spec/views/form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -370,46 +370,42 @@ New line after and before textarea tag
</label>
</p>


<p>
<label for="form_disabled_file">
Disabled File
<input type="file" name="form[disabled_file]" value="/should/not/see/me" id="form_disabled_file" disabled="disabled" />
</label>
</p>

<p>
<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>
<input name="form[enabled_fieldset_child]" id="form_enabled_fieldset_child"/>
</fieldset>

<fieldset disabled="disabled">
<legend>
Nested Disabled
<input type="checkbox" name="form[disabled_fieldeset_legend_child]" id="form_disabled_fieldset_legend_child"/>
</legend>
<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>
<legend>
Another Legend
<input type="checkbox" name="form[disabled_fieldeset_second_legend_child]" id="form_disabled_fieldset_second_legend_child"/>
Disabled?
<input id="form_disabled_fieldset_descendant_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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 06265ce

Please sign in to comment.