Created
December 26, 2011 16:44
-
-
Save samullen/1521583 to your computer and use it in GitHub Desktop.
User defined finders for Capybara
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Capybara.add_selector(:link) do | |
xpath {|rel| ".//a[contains(@rel, '#{rel}')]"} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="javascript:void(0);" rel="toggle-chart">Toggle chart</a> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When /^I toggle the charts$/ do | |
page.find(:link, "toggle-chart").click | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@shinzui offered up via Twitter the "contains" option from XPath. Using that method allows you to have multiple values set in the "rel" attribute (e.g. rel="foo bar baz"). You can then do find(:link, "foo") and not have to match all the values in the "rel" attribute. You can find other XPath functions here: http://www.w3.org/TR/xpath/#corelib
Another note: If you are up to date on Capybara, you can use css matchers instead and avoid all this mess.