user3822236
user3822236

Reputation: 3

Using SitePrism's page object elements to perform page assertions

I want to know if there's a way to perform a page.should assertion with a page object element directly, instead of giving the xpath or CSS selector string as a parameter.

i.e.:

Page class:

class FooClass < SitePrism::Page
  element :action_select, '.autocomplete.medium'
end

Step definition:

page.should have_css('.autocomplete.medium')

#Sort of thing desired:

page.should have_css(action_select.get_css)

That .get_css does not exist but it's used to illustrate what's desired.

Upvotes: 0

Views: 876

Answers (1)

Justin Ko
Justin Ko

Reputation: 46836

The element method creates a has_<element name>? method that can check the existence of the element.

For example, for your page:

page.has_action_select?
#=> returns true if it exists, false if it doesn't

This allows your assertion to be:

page.should have_action_select

For more details, you can see the site prism page.

Upvotes: 2

Related Questions