Prismatic
Use a naming convention inside your HTML to describe the DOM elements you want to access during tests. Prismatic will set up your SitePrism::Pages with the intended Sections and Elements.
Motivation
SitePrism is a wonderful tool for describing web pages in integration tests. Unfortunately, it requires the creation of classes which use CSS selectors (of XPath expressions) to indicate the elements of interest.
Prismatic aims to allow you skip the use of SitePrism's Page Object Model by indicating in the web page itself which are the objects you want to access in your tests thanks to data attributes.
Installation
Add this line to your application's Gemfile:
gem 'prismatic'
And then execute:
$ bundle
Or install it yourself as:
$ gem install prismatic
Usage
There are two steps:
First, add the following attributes to your HTML markup:
- data-prism-element
- data-prism-elements
- data-prism-section
- data-prism-sections
Given a 'search#index' page containing this:
...
<form data-prism-section="search" method="get" action="search">
<input type="text" data-prism-element="query">
<input type="submit" data-prism-element="start" value="Search">
</form>
...
Second, create a page class:
class SearchIndexPage < Prismatic::Page
set_url '/search'
end
When you load the page, the sections and elements are defined:
search_page = SearchIndexPage.new
search_page.load
expect(search_page.search.start.text).to eq('Search')
Warnings
- all Pages need an
url_matcher
so that Prismatic knows when a page is actually loaded. If you don't specify one, Prismatic will create it (seeauto_create_url_matcher
configuration setting), - be careful with
wait_for_*
: you may need to manually define a section or element you intend to use as a marker that content is loaded - Prismatic won't create them until they are actually present.
Configuration
In your test setup, do this:
Prismatic.configure do
foo :bar
end
Configuration options:
- prefix: (default: 'prism'). By default, prismatic uses data attributes called 'data-prism-*'. Set prefix to another value to allow data attributes to be named differently.
- auto_create_url_matcher: (default: true). If a Page has no
url_matcher
defined, this sets it to a Regexp based on the Page'surl
.
Contributing
- Fork it ( https://github.com/joeyates/prismatic/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request