Class: Vapir::Browser
- Inherits:
-
Object
- Object
- Vapir::Browser
- 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
-
.__new__ ⇒ Object
:nodoc:.
-
.attach(how, what, options = {}) ⇒ Object
(also: find)
Attach to an existing browser window.
- .browser_class ⇒ Object
- .default ⇒ Object
-
.default=(default_browser) ⇒ Object
Specifies a default browser.
-
.inherited(subclass) ⇒ Object
:nodoc:.
-
.new(*args, &block) ⇒ Object
(also: new_window)
Create a new instance of a browser driver, as determined by the configuration settings.
-
.start(url = 'about:blank', options = {}) ⇒ Object
(also: start_window)
Create a new browser instance, starting at the specified url.
Instance Method Summary collapse
- #configuration_parent ⇒ Object
- #inspect ⇒ Object
-
#locate(options = {}) ⇒ Object
locate is used by stuff that uses container.
- #locate!(options = {}) ⇒ Object
Methods included from Waiter::WaitUntil
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, ={}) new(.merge(:attach => [how, what])) end |
.browser_class ⇒ Object
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 |
.default ⇒ Object
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.
31 32 33 34 |
# File 'lib/vapir-common/browser.rb', line 31 def start(url='about:blank', ={}) raise ArgumentError, "URL must be a string; got #{url.inspect}" unless url.is_a?(String) new(.merge(:goto => url)) end |
Instance Method Details
#configuration_parent ⇒ Object
75 76 77 |
# File 'lib/vapir-common/browser.rb', line 75 def configuration_parent browser_class.config end |
#inspect ⇒ Object
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(={}) exists? end |
#locate!(options = {}) ⇒ Object
84 85 86 |
# File 'lib/vapir-common/browser.rb', line 84 def locate!(={}) locate() || raise(Vapir::Exception::WindowGoneException, "The browser window seems to be gone") end |