Class: Vapir::Browser

Inherits:
Object
  • Object
show all
Extended by:
Waiter::WaitUntil
Includes:
Configurable, Waiter::WaitUntil
Defined in:
lib/vapir-common/browser.rb,
lib/vapir-common/waiter.rb

Overview

The common Browser class from which classes specific to Firefox or IE browsers inherit.

Calls to this class are delegated to a browser inheriting from this, which is set using config.default_browser

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Waiter::WaitUntil

wait_until

Methods included from Configurable

#config, #with_config, #without_waiting

Class Method Details

.__new__Object

:nodoc:



13
# File 'lib/vapir-common/browser.rb', line 13

alias __new__ new

.attach(how, what, options = {}) ⇒ Object Also known as: find

Attach to an existing browser window. Returns an instance of the current default browser class.

the window to be attached to can be referenced by url, title, or window handle (‘how’ argument)

The ‘what’ argument can be either a string or a regular expression, in the case of of :url or :title.

Vapir::Browser.attach(:url, 'http://www.google.com')
Vapir::Browser.attach(:title, 'Google')
Vapir::Browser.attach(:hwnd, 528140)

see the implementing browser’s new method for more details on what may be passed.



50
51
52
# File 'lib/vapir-common/browser.rb', line 50

def attach(how, what, options={})
  new(options.merge(:attach => [how, what]))
end

.browser_classObject



55
56
57
58
59
60
# File 'lib/vapir-common/browser.rb', line 55

def browser_class
  key = Vapir.config.default_browser
  browser_class=SupportedBrowsers[key.to_sym][:class_name].split('::').inject(Object) do |namespace, name_part|
    namespace.const_get(name_part) # this triggers autoload if it's not loaded 
  end
end

.defaultObject



63
64
65
66
# File 'lib/vapir-common/browser.rb', line 63

def default
  # deprecate
  Vapir.config.default_browser
end

.default=(default_browser) ⇒ Object

Specifies a default browser. Must be specified before options are parsed.



68
69
70
71
# File 'lib/vapir-common/browser.rb', line 68

def default= default_browser
  # deprecate
  Vapir.config.default_browser = default_browser
end

.inherited(subclass) ⇒ Object

:nodoc:



14
15
16
17
18
# File 'lib/vapir-common/browser.rb', line 14

def inherited(subclass) # :nodoc:
  class << subclass
    alias new __new__
  end
end

.new(*args, &block) ⇒ Object Also known as: new_window

Create a new instance of a browser driver, as determined by the configuration settings. (Don’t be fooled: this is not actually an instance of Browser class.)



23
24
25
26
# File 'lib/vapir-common/browser.rb', line 23

def new *args, &block
  browser=browser_class.new *args, &block
  browser
end

.start(url = 'about:blank', options = {}) ⇒ Object Also known as: start_window

Create a new browser instance, starting at the specified url. If no url is given, start at about:blank.

Raises:

  • (ArgumentError)


31
32
33
34
# File 'lib/vapir-common/browser.rb', line 31

def start(url='about:blank', options={})
  raise ArgumentError, "URL must be a string; got #{url.inspect}" unless url.is_a?(String)
  new(options.merge(:goto => url))
end

Instance Method Details

#configuration_parentObject



75
76
77
# File 'lib/vapir-common/browser.rb', line 75

def configuration_parent
  browser_class.config
end

#inspectObject



87
88
89
# File 'lib/vapir-common/browser.rb', line 87

def inspect
  "#<#{self.class}:0x#{(self.hash*2).to_s(16)} " + (exists? ? "url=#{url.inspect} title=#{title.inspect}" : "exists?=false") + '>'
end

#locate(options = {}) ⇒ Object

locate is used by stuff that uses container. this doesn’t actually locate the browser but checks if it (still) exists.



81
82
83
# File 'lib/vapir-common/browser.rb', line 81

def locate(options={})
  exists?
end

#locate!(options = {}) ⇒ Object



84
85
86
# File 'lib/vapir-common/browser.rb', line 84

def locate!(options={})
  locate(options) || raise(Vapir::Exception::WindowGoneException, "The browser window seems to be gone")
end