Skip to content
View abstraction for integration testing
Find file
New pull request

Domino Build Status

View abstraction for integration testing


To create a basic Domino class, inherit from Domino and define a selector and attributes:

module Dom
  class Post < Domino
    selector '#posts .post'
    attribute :title # selector defaults to .title
    attribute :author_name # selector defaults to .author-name
    attribute :body, '.post-body' # example of selector override

    # pass a block if you want to modify the value
    attribute :comments do |text|

    attribute :posted_at do |text|

Now in your integration test you can use some of Domino's methods:

assert_equal 4, Dom::Post.count
refute_nil Dom::Post.find_by_title('First Post')

# Multiple attributes, returns first match if any
refute_nil Dom::Post.find_by(title: 'First Post', author: 'Jane Doe')

# Multiple attributes with exception if no match is found
refute_nil Dom::Post.find_by!(title: 'First Post', author: 'Jane Doe')

# Multiple attributes, returns all matches if any
assert_equal ["12/06/2014", "12/01/2014"], Dom::Post.where(author: 'Jane Doe').map(&:posted_on)

What makes it really powerful is defining scoped actions:

module Dom
  class Post < Domino
    def delete
      within(id) { click_button 'Delete' }

refute_nil Dom::Post.find_by_title('First Post')
Dom::Post.find_by_title('First Post').delete
assert_nil Dom::Post.find_by_title('First Post')

Integration with capybara

Domino uses capybara internally to search html for nodes and attributes. If you need to do something special, you can have direct access to the capybara node.

module Dom
  class Account < Domino
    selector "#accounts li"
    # Returns this node text
    def text

For more information about using Capybara nodes, check Capybara Documentation.

Dealing with Asynchronous Behavior

When working with Capybara drivers that support JavaScript, it may be necessary to wait for elements to appear. Note that the following code simply collects all Account dominos currently on the page and returns the first:

Dom::Account.first # returns nil if account is displayed asynchronously

When you are waiting for a unique domino to appear, you can instead use the find! method:

Dom::Account.find! # waits for matching element to appear

If no matching element appears, Capybara will raise an error telling you about the expected selector. Depending on the Capybara.match option, this will also raise an error if the selector matches multiple nodes.

Integration with Cucumber

Add a features/support/dominos.rb file, in which you define your dominos.

Use them in your steps.

Integration with Test::Unit

Include "domino" in your Gemfile if using bundler, or simply

require 'domino'

If you're not using Bundler.

Now, define your Dominos anywhere you want. The easiest place to start is in your test_helper.rb (doesn't have to be inside a Rails test class).


Check out Domino Example for an example of using Test::Unit and Cucumber with Domino.


Copyright (c) 2011 Nick Gauthier, released under the MIT license

Something went wrong with that request. Please try again.