Class: Capybara::PageObject::Page

Inherits:
Object
  • Object
show all
Includes:
CapybaraHelper, RSpecMatchers, RSpec::Matchers
Defined in:
lib/capybara-pageobject/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, page_data) ⇒ Page

Returns a new instance of Page.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/capybara-pageobject/page.rb', line 12

def initialize page, page_data
  @page = page
  @page_data = page_data
  page_data["attributes"].present? and page_data["attributes"].each do |attribute, selector|
    self.class.send(:define_method, attribute) do |value=nil|
      Capybara::PageObject::Attribute.new(page, attribute, selector).tap { |node| node.set(value) if value }
    end
  end

  page_data["actions"].present? and page_data["actions"].each do |attribute, selector|
    self.class.send(:define_method, attribute) { Action.new(page, attribute, selector) }
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



46
47
48
# File 'lib/capybara-pageobject/page.rb', line 46

def method_missing method, *args
  page.respond_to?(method) ? page.send(method, *args) : super
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



10
11
12
# File 'lib/capybara-pageobject/page.rb', line 10

def context
  @context
end

Instance Method Details

#has_content?(content) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/capybara-pageobject/page.rb', line 34

def has_content? content
  page.has_content?(content.to_s)
end

#page_titleObject



38
39
40
# File 'lib/capybara-pageobject/page.rb', line 38

def page_title
  if_absent("") { page.find("head title").text }
end

#to_sObject



42
43
44
# File 'lib/capybara-pageobject/page.rb', line 42

def to_s
  "'page: #{@page_data["name"]}'"
end

#visible?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/capybara-pageobject/page.rb', line 30

def visible?
  @page_data["id"] ? if_absent(false) { page.find(@page_data["id"]).visible? } : raise("id not defined for page")
end

#visit(url_params = {}) ⇒ Object



26
27
28
# File 'lib/capybara-pageobject/page.rb', line 26

def visit url_params={}
  page.visit(UrlParser.new(@page_data["url"]).format(url_params))
end