Repository navigation
Pages
Pages are Huzzah's implementation of the page-object pattern. They are standard Ruby classes that extend the Huzzah::Page class, which provides a few extra features.
Pages a created under that pages directory and are defined by the following syntax:
module Moolah
class LoginPage < Huzzah::Page
end
endNOTE: Huzzah only supports a single module namesapce, which should be your site name.
The framework uses the module and class names to dynamically generate methods that return instances of those objects. In the above example, it would generate a moolah method within all Huzzah::Role instances and a login_page method within the Moolah Huzzah::Site instance. The dynamically generated methods are the snake case version of the camel case constant names of the module & class.
You would call an instance of this page as follows:
role = Huzzah::Role.new
role.moolah.login_pageNOTE: Huzzah will not allow you to save state (e.g. setting instance variables) within a page-object. This is to prevent data corruption which could lead to flapping scenarios.
The framework provides a shorthand way of defining element locators. The locator method takes two arguments: a name & a block. The name is used to dynamically generate a method with that name that will execute the block (the second argument) when called. While you can execute any Ruby code within the block, we highly recommend that you only ever return page elements when using the locator method.
module Moolah
class LoginPage < Huzzah::Page
locator(:email_field) { text_field(name: 'email') }
locator(:password_field) { text_field(name: 'password') }
locator(:login_button) { button(value: 'Login') }
end
endCalling a locator:
role.moolah.login_page.email_field.set('john.doe@email.net')NOTE: The code within the block is standard Watir-WebDriver element locator syntax. You do not need to pre-pend this code with brower (e.g. { browser.text_field(name: 'email') } ). Huzzah knows that you are calling methods within the Watir::Browser class. Also, to prevent naming collisions, the framework will not allow you to name locators with the same name as any method within the Watir::Container class ( e.g. button, table, etc).
You can define locators that take arguments with the following syntax:
module Moolah
class UserAccount < Huzzah::Page
locator(:message) { |message_text| div(text: message_text) }
end
endIn the above example, message_text becomes an argument to the message method. It would be called as follows:
role.moolah.user_account.message('Payment Sent.').present?Along with your locators, you can define normal methods within your page-objects. These methods can reference your locator names.
module Moolah
class UserAccount < Huzzah::Page
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
enduser.some_site.some_page do
some_locator.action
some_locator.action
some_locator.action
end