Class: Capybara::Wheel::Page

Inherits:
Object
  • Object
show all
Extended by:
Includes::ClassIncludes
Includes:
Includes
Defined in:
lib/capybara/wheel/page.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Includes::ClassIncludes

make_const, underscore

Methods included from Includes

#capybara

Class Method Details

.element(name, selector, options = {}, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/capybara/wheel/page.rb', line 44

def self.element(name, selector, options = {}, &block)
  begin
    element_klass = const_set("#{name}", Capybara::Wheel::ElementFactory.create_element_klass(selector, options, block))
  rescue NameError
    puts "We recommend using capitalized element and subelement names"
    name = name.capitalize!
    retry
  end

  define_method(underscore(name).to_sym) { element_klass.new(selector) }
  self
end

Instance Method Details

#has_title?(expected_title) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/capybara/wheel/page.rb', line 40

def has_title?(expected_title)
  capybara.has_css?("head title", text: expected_title)
end

#on {|_self| ... } ⇒ Object

execute a block in the context of this page

Yields:

  • (_self)

Yield Parameters:



22
23
24
25
26
27
28
# File 'lib/capybara/wheel/page.rb', line 22

def on
  unless on_page?
    raise "We don't appear to be on the #{self.class}"
  end
  yield self if block_given?
  self
end

#on_page?Boolean

Return true if the browser is on this page

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/capybara/wheel/page.rb', line 36

def on_page?
  raise NotImplementedError, "implement me, e.g. using #has_title?"
end

#pathObject

Returns the path (relative URI) of this page

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/capybara/wheel/page.rb', line 31

def path
  raise NotImplementedError, "implement to support page.visit"
end

#visit(&block) ⇒ Object

actively visits page and executes block in context



11
12
13
14
15
16
17
18
19
# File 'lib/capybara/wheel/page.rb', line 11

def visit(&block)
  capybara.visit(path)
  if block_given?
    on(&block)
  else
    on_page?
  end
  return self
end