Skip to content

Commit

Permalink
Upgrade XPath
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicklas committed Jan 3, 2012
1 parent 60ed514 commit 18bc626
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions lib/capybara/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ def filter(name, &block)
end

Capybara.add_selector(:link) do
xpath { |locator, xpath_options| XPath::HTML.link(locator, xpath_options) }
xpath { |locator| XPath::HTML.link(locator) }
failure_message { |node, selector| "no link with title, id or text '#{selector.locator}' found" }
filter(:href) do |node, href|
attribute = XPath.attr(:href).equals(href)
node.first(:xpath, "self::a[#{attribute}]")
node.first(:xpath, XPath.axis(:self)[XPath.attr(:href).equals(href)])
end
end

Expand All @@ -104,26 +103,26 @@ def filter(name, &block)
end

Capybara.add_selector(:fillable_field) do
xpath { |locator, xpath_options| XPath::HTML.fillable_field(locator, xpath_options) }
xpath { |locator| XPath::HTML.fillable_field(locator) }
failure_message { |node, selector| "no text field, text area or password field with id, name, or label '#{selector.locator}' found" }
end

Capybara.add_selector(:radio_button) do
xpath { |locator, xpath_options| XPath::HTML.radio_button(locator, xpath_options) }
xpath { |locator| XPath::HTML.radio_button(locator) }
failure_message { |node, selector| "no radio button with id, name, or label '#{selector.locator}' found" }
filter(:checked) { |node, value| not(value ^ node.checked?) }
filter(:unchecked) { |node, value| (value ^ node.checked?) }
end

Capybara.add_selector(:checkbox) do
xpath { |locator, xpath_options| XPath::HTML.checkbox(locator, xpath_options) }
xpath { |locator| XPath::HTML.checkbox(locator) }
failure_message { |node, selector| "no checkbox with id, name, or label '#{selector.locator}' found" }
filter(:checked) { |node, value| not(value ^ node.checked?) }
filter(:unchecked) { |node, value| (value ^ node.checked?) }
end

Capybara.add_selector(:select) do
xpath { |locator, xpath_options| XPath::HTML.select(locator, xpath_options) }
xpath { |locator| XPath::HTML.select(locator) }
failure_message { |node, selector| "no select box with id, name, or label '#{selector.locator}' found" }
filter(:options) { |node, options| options.all? { |option| node.first(:option, option) } }
filter(:selected) do |node, selected|
Expand All @@ -142,7 +141,7 @@ def filter(name, &block)
end

Capybara.add_selector(:file_field) do
xpath { |locator, xpath_options| XPath::HTML.file_field(locator, xpath_options) }
xpath { |locator| XPath::HTML.file_field(locator) }
failure_message { |node, selector| "no file field with id, name, or label '#{selector.locator}' found" }
end

Expand All @@ -151,5 +150,5 @@ def filter(name, &block)
end

Capybara.add_selector(:table) do
xpath { |locator, xpath_options| XPath::HTML.table(locator, xpath_options) }
xpath { |locator| XPath::HTML.table(locator) }
end
2 changes: 1 addition & 1 deletion xpath
Submodule xpath updated from 422ff0 to 375ec5

0 comments on commit 18bc626

Please sign in to comment.