So I have setup a Capybara, Cucumber project with SitePrism for POM and for the most part it works. When I use:
Then('Find object name') do
expect(@page).to have_object_name
end
it works just fine but when I come to use:
Then('Assign object names text to a variable') do
expect(@page).to have_object_name
valueA = @page.find('object_name').text
end
this doesnt work and throws an error
Unable to find css "object_name" (Capybara::ElementNotFound)
However, if I use:
Then('Assign object names text to a variable') do
expect(@page).to have_object_name
valueA = @page.find(:xpath, 'object_name_XPath').text
end
this works out just fine as well, but this sort of defeats the point of POM as it would greatly increase maintenance.
I assume I must be missing something to get the page.find locate the object_name from my page but I have danced around it and searched high and low but can't seem to figure the problem out. Help? :)
@page.find
takes a CSS selector (by default - it's actually just the Capybara find
method), not the name of a SitePrism element
.
If @page is a SitePrism::Page
or SitePrism::Section
object and you have defined elements on it, then you just access that element as a method on @page
- See https://github.com/natritmeyer/site_prism#accessing-the-individual-element
@page.object_name