Class: WatirDrops::PageObject

Inherits:
Object
  • Object
show all
Defined in:
lib/watir_drops/page_object.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(browser = nil) ⇒ PageObject

Returns a new instance of PageObject.



43
44
45
# File 'lib/watir_drops/page_object.rb', line 43

def initialize(browser=nil)
  @browser = browser || WatirDrops::Session.instance.browser
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



41
42
43
# File 'lib/watir_drops/page_object.rb', line 41

def browser
  @browser
end

Class Method Details

.element(name, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/watir_drops/page_object.rb', line 15

def element(name, &block)
  define_method(name) do |*args|
    self.instance_exec(*args, &block)
  end

  define_method("#{name}=") do |val|
    watir_element = self.instance_exec &block
    case watir_element
      when Watir::Radio
        watir_element.set val
      when Watir::CheckBox
        val ? watir_element.set : watir_element.clear
      when Watir::Select
        watir_element.select val
      when Watir::Button
        watir_element.click
      else
        watir_element.value = val
    end
  end

  elements << {name.to_sym => block}
end

.elementsObject



11
12
13
# File 'lib/watir_drops/page_object.rb', line 11

def elements
  @elements ||= []
end

.page_url(url) ⇒ Object



5
6
7
8
9
# File 'lib/watir_drops/page_object.rb', line 5

def page_url url
  define_method("goto") do
    browser.goto url
  end
end

Instance Method Details

#titleObject



52
53
54
# File 'lib/watir_drops/page_object.rb', line 52

def title
  browser.title
end

#visitObject



47
48
49
50
# File 'lib/watir_drops/page_object.rb', line 47

def visit
  goto if self.respond_to? :goto
  self
end