<label> elements don't associate aria-role buttons
This commit is contained in:
parent
244cc6be78
commit
d3fdbfbac0
|
@ -3,29 +3,30 @@
|
|||
Capybara.add_selector(:button, locator_type: [String, Symbol]) do
|
||||
xpath(:value, :title, :type, :name) do |locator, **options|
|
||||
input_btn_xpath = XPath.descendant(:input)[XPath.attr(:type).one_of('submit', 'reset', 'image', 'button')]
|
||||
btn_xpaths = [XPath.descendant(:button)]
|
||||
btn_xpaths << XPath.descendant[XPath.attr(:role).equals('button')] if enable_aria_role
|
||||
btn_xpath = XPath.descendant(:button)
|
||||
aria_btn_xpath = XPath.descendant[XPath.attr(:role).equals('button')]
|
||||
image_btn_xpath = XPath.descendant(:input)[XPath.attr(:type) == 'image']
|
||||
|
||||
unless locator.nil?
|
||||
locator = locator.to_s
|
||||
locator_matchers = combine_locators(locator, config: self)
|
||||
btn_matchers = locator_matchers |
|
||||
XPath.string.n.is(locator) |
|
||||
XPath.descendant(:img)[XPath.attr(:alt).is(locator)]
|
||||
|
||||
input_btn_xpath = input_btn_xpath[locator_matchers] + locate_label(locator).descendant(input_btn_xpath)
|
||||
|
||||
btn_xpaths = btn_xpaths.map do |btn_xpath|
|
||||
btn_xpath[locator_matchers |
|
||||
XPath.string.n.is(locator) |
|
||||
XPath.descendant(:img)[XPath.attr(:alt).is(locator)]
|
||||
] + locate_label(locator).descendant(btn_xpath)
|
||||
end
|
||||
btn_xpath = btn_xpath[btn_matchers] + locate_label(locator).descendant(btn_xpath)
|
||||
aria_btn_xpath = aria_btn_xpath[btn_matchers]
|
||||
|
||||
alt_matches = XPath.attr(:alt).is(locator)
|
||||
alt_matches |= XPath.attr(:'aria-label').is(locator) if enable_aria_label
|
||||
image_btn_xpath = image_btn_xpath[alt_matches] + locate_label(locator).descendant(image_btn_xpath)
|
||||
end
|
||||
|
||||
%i[value title type].inject([input_btn_xpath, *btn_xpaths, image_btn_xpath].inject(&:union)) do |memo, ef|
|
||||
btn_xpaths = [input_btn_xpath, btn_xpath, image_btn_xpath]
|
||||
btn_xpaths << aria_btn_xpath if enable_aria_role
|
||||
|
||||
%i[value title type].inject(btn_xpaths.inject(&:union)) do |memo, ef|
|
||||
memo.where(find_by_attr(ef, options[ef]))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,8 +46,8 @@ Capybara::SpecHelper.spec '#has_button?' do
|
|||
expect(@session).to have_button('ARIA button', enable_aria_role: true)
|
||||
end
|
||||
|
||||
it 'should be true for a role=button within a label when enable_aria_role: true' do
|
||||
expect(@session).to have_button('role=button within label', enable_aria_role: true)
|
||||
it 'should be false for a role=button within a label when enable_aria_role: true' do
|
||||
expect(@session).not_to have_button('role=button within label', enable_aria_role: true)
|
||||
end
|
||||
|
||||
it 'should be false for role=button when enable_aria_role: false' do
|
||||
|
@ -105,8 +105,9 @@ Capybara::SpecHelper.spec '#has_no_button?' do
|
|||
expect(@session).not_to have_no_button('ARIA button', enable_aria_role: true)
|
||||
end
|
||||
|
||||
it 'should be false for a role=button within a label when enable_aria_role: true' do
|
||||
expect(@session).not_to have_no_button('role=button within label', enable_aria_role: true)
|
||||
it 'should be true for a role=button within a label when enable_aria_role: true' do
|
||||
# label element does not associate with aria button
|
||||
expect(@session).to have_no_button('role=button within label', enable_aria_role: true)
|
||||
end
|
||||
|
||||
it 'should not affect other selectors when enable_aria_role: true' do
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
<p><a href="#" id="clickable">Click me</a></p>
|
||||
<p><a href="#" id="slow-click">Slowly</a></p>
|
||||
<p><span id="aria-button" role="button">ARIA button</span></p>
|
||||
<p><span role="button">ARIA button2</span></p>
|
||||
|
||||
<p>
|
||||
<select id="waiter">
|
||||
|
|
Loading…
Reference in New Issue