Skip to content
This repository was archived by the owner on Jul 20, 2026. It is now read-only.

Partials

lkhoward edited this page Mar 11, 2016 · 5 revisions

Partials are simply Pages. They are created under the partials directory.

The idea is that partials will be used to keep you code DRY by defining locators that are common to multiple pages. They could also be used to break complex pages into more manageable components.

The syntax for defining a partial is exactly like a page:

module Moolah
  class Header < Huzzah::Page

    locator(:logout)  { img(class: 'logout') }

  end
end

The only difference is how they are referenced. You link a partial to a page using the include_partial method:

module Moolah
  class UserAccount < Huzzah::Page

    include_partial(Moolah::Header)

    locator(:welcome_message)  { span(class: 'welcome') }
    locator(:email_field)      { text_field(name: 'email') }
    locator(:amount_field)     { text_field(name: 'amount') }
    locator(:send_button)      { button(value: 'Send Payment') }
    locator(:sent_message)     { div(text: 'Payment Sent.') }
    locator(:view_account_activity)  { link(text: 'View Account Activity >>') }

    def send_payment(user, amount)
      email_field.when_present.set(user)
      amount_field.set(amount)
      send_button.click
    end

  end
end

The framework will dynamically generate a method (in the case named header) that will return an instance of the partial.

NOTE: Huzzah only uses the class (page) name to define the method for the partial. It ignores the module (site) name altogether. In fact, the module name of the partial does not need to match the module name of the page.

Usage:

role.moolah.login_page.header.logout.click

Clone this wiki locally