howitzer icon indicating copy to clipboard operation
howitzer copied to clipboard

Reduce methods amount in a page via proxying one-line methods

Open romikoops opened this issue 7 years ago • 0 comments

Meta

Howitzer Version: 2+

Regarding Howitzer and Page Object Pattern conception it is forbidden to work with low level ui elements (Capybara elements) on step definitions layer. Instead of that we work with pages public API. It allows us to implement tests on business language without knowledge about HTML structure. Example:

LoginPage.open
LoginPage.on do
  fill_form(email: '[email protected]', password: 'test1234')
  submit_form
end

The problem here happens when we deal with pages where we have a lot of elements, like graphs, tables, reports. Typically, it is single page applications based on React.js or similar. Our pages become huge due to we have to implement different methods including one-line methods on pages and sections.

Here are examples

class ArticlePage < DemoAppPage
  element :article_button, :xpath, ->(title) { "//a[contains(.,'#{title}')]" }

  def click_article_button(text)
    Howitzer::Log.info "Open '#{text}' article"
    article_button_element(text).click
  end
end
class ChangePasswordPage < DemoAppPage
  element :submit_form, :button, 'Change my password'

  def submit_form
    Howitzer::Log.info 'Submit Change Password form'
    submit_form_element.click
  end
end
class FlashSection < Howitzer::Web::Section
  me '.alert'

  element :flash_message, '#flash_notice'
  element :flash_alert, '#flash_alert'

  def flash_message
    flash_message_element.text
  end
end

It will be nice to find a solution to build such methods dynamically and do not clutter up pages and sections with these proxied methods

romikoops avatar Jul 09 '17 10:07 romikoops