Class: Capybara::PageObject::Website

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara-pageobject/website.rb

Instance Method Summary collapse

Constructor Details

#initialize(page, page_file) ⇒ Website

Returns a new instance of Website.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/capybara-pageobject/website.rb', line 5

def initialize page, page_file
  @page = page

  raise "Please specify page file path" unless page_file.present?
  @pages_data = YAML.load_file(page_file)

  @pages_data.each do |page, page_data|
    page_class = (page_data["class"] || "Capybara::PageObject::Page").constantize
    unless page_class.ancestors.include?(Capybara::PageObject::Page)
      raise "Custom page class '#{page_class}' should extend Capybara::PageObject::Page"
    end
    wrapper = lambda { |&page_actions| on_page_perform(page_actions) { page_class.new(@page, page_data.merge("name" => page)) } }
    self.class.send(:define_method, page, wrapper)
  end
end