Site Prism has been really helpful with implementing the Page Model Pattern using Capybara. It's helped make our Cucumber steps more reusable and does a better job of describing what the page should look like. Take for example the following page.
class LoginPage < SitePrism::Page element :email, "#login_email" element :password, "#login_password" element :login_button, "input[type=submit]" end
Pretty straightforward. Combine that with the awesome helpers you get from Site Prism, and that is a pretty great tool.
The bummer for me, is that we are selecting on a very implementation-centric selector. From the perspective of a Cucmber test, it shouldn't matter what the name of the input is. The ID isn't a user-observable attribute; however the text in the label is, so lets use that.
After a quick look at
SitePrism::Page, it looks like it is just delegating down to Capybara's
#find. Capybara has
#find_field which also delegates to
#find. Looks like this should just work from Site Prism.
class LoginPage < SitePrism::Page element :email, :field, 'Email Address' element :password, :field, 'Password' element :login_button, :button, 'Login' end
Sure enough! It works. You can get fancier by using translations to find the fields, but opinions vary on if that is too far.