Skip to content

kliuchnikau/tooth

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 

tooth

Simple page objects for Capybara

=====

Build Status

How to install

gem install tooth

or with bundler add the following line to your Gemfile:

gem 'tooth'

You can create page objects and page components using simple DSL. These page objects will incapsulate all selectors and remove duplication from you tests:

class NavigationComponent
  extend PageObject # inject page object 'role' for component

  element :logo, '.logo'
end

class HomePage
  extend PageObject

  # simple_divs
  element :headline, 'div#some-id'
  element :some_div_lambda, ->(id){ "div#some-#{id}" }
  element :not_existing, '#not-existing-element'
  elements :all_divs, 'div'

  # components_divs
  within 'div#component1-id' do
    element :inside_div, '.second-lvl'
    element :inside_div_lambda, ->(lvl){".second-#{lvl}"}
  end

  # components_divs
  component :component1, NavigationComponent, 'div#component1-id'
  component :component1_lambda, NavigationComponent, ->(id){ "div#component1-#{id}" }

  # components2_divs
  within '#scope-two' do
    component :component2, NavigationComponent, 'div#component1-id'
  end
end

Then inside tests you can use these objects (methods return Capybara elements):

expect(HomePage.headline.text).to eq 'Headline text'