Class: WatirSplash::Page::Base

Inherits:
Object
  • Object
show all
Includes:
SpecHelper
Defined in:
lib/watirsplash/page/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SpecHelper

#method_missing, #p

Constructor Details

#initialize(browser = nil) ⇒ Base

Returns a new instance of Base.



16
17
18
19
20
21
22
23
# File 'lib/watirsplash/page/base.rb', line 16

def initialize(browser=nil)
  if browser
    @browser = browser 
  else
    @browser = WatirSplash::Browser.exists? ? WatirSplash::Browser.current : (WatirSplash::Browser.current = WatirSplash::Browser.new)
    @browser.goto self.class._url
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class WatirSplash::SpecHelper

Class Method Details

._urlObject



11
12
13
# File 'lib/watirsplash/page/base.rb', line 11

def _url
  @url || "about:blank"
end

.url(url) ⇒ Object



7
8
9
# File 'lib/watirsplash/page/base.rb', line 7

def url url
  @url = url
end

Instance Method Details

#modify(element, methodz) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/watirsplash/page/base.rb', line 29

def modify element, methodz
  methodz.each_pair do |meth, return_value|
    element.instance_eval do 
      singleton = class << self; self end

      singleton.send :alias_method, "__#{meth}", meth if respond_to? meth
      singleton.send :define_method, meth do |*args|
        self.send("__#{meth}", *args) if respond_to? "__#{meth}"
        return_value.call(*args)
      end
    end
  end
  element
end

#redirect_to(page, browser = nil) ⇒ Object



25
26
27
# File 'lib/watirsplash/page/base.rb', line 25

def redirect_to page, browser=nil
  page.new browser || WatirSplash::Browser.current
end