I'm mucking around with the site_prism to implement a Page Object Model in capybara. It looks very interesting.
How would I specify a selector such as "[data-id='x']" where x is an integer? Something like this:
class Home < SitePrism::Page
set_url "http://www.example.com"
element :row, "[data-id='@id']"
end
And then in my tests:
Then /^the home page should contain a row$/ do
@home.should have_row 1234
end
Because SitePrism sets the element locator when the element is defined, what you've suggested doesn't work. To achieve what you've asked for, take a look at the following:
Instead of mapping a single row, they're all mapped (using
elements
instead ofelement
). A separate method calledrow_ids
collects all of the rows that have 'data-id' value, maps all those values into a new array, and returns that new array.The tests would then contain something like:
...which will check that there is a row with an ID that matches
@id
.Not as pretty, but it should work.