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

operate with values before manipulating them

This commit is contained in:
Sean Doyle 2020-09-29 21:03:22 -04:00
parent ec467af08d
commit b21c92f4ed

View file

@ -9,26 +9,24 @@ Capybara.add_selector(:button, locator_type: [String, Symbol]) do
unless locator.nil?
locator = locator.to_s
locator_matchers = XPath.attr(:id).equals(locator) |
XPath.attr(:name).equals(locator) |
XPath.attr(:value).is(locator) |
XPath.attr(:title).is(locator) |
(XPath.attr(:id) == XPath.anywhere(:label)[XPath.string.n.is(locator)].attr(:for))
attr_matchers = XPath.attr(:id).equals(locator) |
XPath.attr(:name).equals(locator) |
XPath.attr(:value).is(locator) |
XPath.attr(:title).is(locator) |
(XPath.attr(:id) == XPath.anywhere(:label)[XPath.string.n.is(locator)].attr(:for))
attr_matchers |= XPath.attr(:'aria-label').is(locator) if enable_aria_label
attr_matchers |= XPath.attr(test_id) == locator if test_id
locator_matchers |= XPath.attr(:'aria-label').is(locator) if enable_aria_label
locator_matchers |= XPath.attr(test_id) == locator if test_id
input_btn_xpath = input_btn_xpath[attr_matchers] +
XPath.descendant(:label)[XPath.string.n.is(locator)].descendant(input_btn_xpath)
input_btn_xpath = input_btn_xpath[locator_matchers]
input_btn_xpath += XPath.descendant(:label)[XPath.string.n.is(locator)].descendant(input_btn_xpath)
btn_xpath = btn_xpath[locator_matchers |
XPath.string.n.is(locator) |
XPath.descendant(:img)[XPath.attr(:alt).is(locator)]]
btn_xpath += XPath.descendant(:label)[XPath.string.n.is(locator)].descendant(btn_xpath)
btn_xpath = btn_xpath[attr_matchers | XPath.string.n.is(locator) | XPath.descendant(:img)[XPath.attr(:alt).is(locator)]] +
XPath.descendant(:label)[XPath.string.n.is(locator)].descendant(btn_xpath)
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]
image_btn_xpath = image_btn_xpath[alt_matches] +
XPath.descendant(:label)[XPath.string.n.is(locator)].descendant(image_btn_xpath)
end
%i[value title type].inject(input_btn_xpath.union(btn_xpath).union(image_btn_xpath)) do |memo, ef|