Class: WatirDrops::PageObject
- Inherits:
-
Object
- Object
- WatirDrops::PageObject
- Defined in:
- lib/watir_drops/page_object.rb
Instance Attribute Summary collapse
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(browser = nil) ⇒ PageObject
constructor
A new instance of PageObject.
- #title ⇒ Object
- #visit ⇒ Object
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
#browser ⇒ Object (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 |
.elements ⇒ Object
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
#title ⇒ Object
52 53 54 |
# File 'lib/watir_drops/page_object.rb', line 52 def title browser.title end |
#visit ⇒ Object
47 48 49 50 |
# File 'lib/watir_drops/page_object.rb', line 47 def visit goto if self.respond_to? :goto self end |