Class: BasePage

Inherits:
Object
  • Object
show all
Defined in:
lib/rutl/base_page.rb

Overview

Base page class. It’s used to call the magical method_messing stuff to parse the page object files into actual objects.

Constant Summary collapse

@@children =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBasePage

TODO: DO I REALLY WANT TO PASS IN DRIVER LIKE THAT?



22
23
24
25
26
27
28
29
# File 'lib/rutl/base_page.rb', line 22

def initialize
  # Call a class's layout method the first time it's loaded

  # and put the class name in a list of children, which is a

  # list of all actual page objects in this case.

  return if @@children.include?(self.class)
  layout
  @@children << self.class
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(element, *args, &_block) ⇒ Object

Called by layout method on pages.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rutl/base_page.rb', line 40

def method_missing(element, *args, &_block)
  name, selector, rest = args
  name = "#{name}_#{element.downcase}"

  case element
  when /button/, /checkbox/, /link/
    # self.class.class_exec do

    #   define_method(name) do

    #     Module.const_get(element.capitalize).new(selector, rest)

    #   end

    # end

    self.class.class_exec do
      foo = Module.const_get(element.capitalize).new(selector, rest)
      define_method(name) do
        foo
      end
    end
  when /text/
    self.class.class_exec do
      # foo = Module.const_get(element.capitalize).new(selector, rest)

      # define_method("_#{name}") do

      #   foo.get

      # end

      define_method(name) do
        Module.const_get(element.capitalize).new(selector, rest)
      end
      # define_method(name.to_s) do

      #   foo.get

      # end

      # define_method((name + '=').to_s) do

      #   foo.set

      # end

      # foo.define_method(:get) do

      #   foo.get

      # end

      # foo.define_method(:set) do

      #   foo.set

      # end

    end
  else
    # TODO: replace with a super call. This is useful for debugging for now.

    raise "#{element} NOT FOUND WITH ARGS #{args}!!!"
  end
end

Instance Attribute Details

#driverObject

Returns the value of attribute driver.



19
20
21
# File 'lib/rutl/base_page.rb', line 19

def driver
  @driver
end

Class Method Details

.childrenObject



17
# File 'lib/rutl/base_page.rb', line 17

def self.children; @@children; end

.urlObject

BUGBUG: Kludgy. What do I really want to do here? Make it easy to define a page’s default url and also matchers for page urls for pages with variable urls?



12
# File 'lib/rutl/base_page.rb', line 12

def self.url; @url; end

Instance Method Details

#loaded?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/rutl/base_page.rb', line 31

def loaded?
  @url = @driver.current_url
end

#respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rutl/base_page.rb', line 85

def respond_to_missing?(*args)
  # Is this right at all???

  case args[0].to_s
  when /button/, /checkbox/, /link/, /text/,
       'driver', 'url', 'children', 'loaded?'
    true
  when 'ok_link'
    raise 'OK LINK WAY DOWN HERE IN BASE PAGE!!!'
  else
    # I think it's good to raise but change the message.

    raise 'Drew, you hit this most often when checking current page ' \
          'rather than current page class'
    # I think I want to raise instead of returningn false.

  end
end

#urlObject



14
# File 'lib/rutl/base_page.rb', line 14

def url; self.class.url; end