Class: MediawikiSelenium::BrowserFactory::Base
- Inherits:
-
Object
- Object
- MediawikiSelenium::BrowserFactory::Base
- Defined in:
- lib/mediawiki_selenium/browser_factory/base.rb
Overview
Browser factories instantiate browsers of a certain type, configure them according to bound environmental variables, and cache them according to the uniqueness of that configuration.
Instance Attribute Summary collapse
-
#browser_name ⇒ Object
readonly
Returns the value of attribute browser_name.
Class Method Summary collapse
-
.bind {|values, browser_options| ... } ⇒ Object
deprecated
Deprecated.
Use Base.configure instead.
-
.bindings ⇒ Hash
All bindings for this factory class combined with those of super classes.
-
.configure(*names) {|values, browser_options| ... } ⇒ Object
Binds environmental configuration to any browser created by factories of this type.
-
.default_bindings ⇒ Hash
Bindings for this factory class.
Instance Method Summary collapse
-
#all_binding_keys ⇒ Array
Returns a unique set of all the binding keys.
-
#bindings ⇒ Hash
Effective bindings for this factory, those defined at the class level and those defined for this instance.
-
#browser_for(config) ⇒ Watir::Browser
Instantiate a browser using the given environmental configuration.
-
#browser_options(config) ⇒ Hash
Browser options for the given configuration.
-
#configure(*names) {|values, browser_options| ... } ⇒ Object
(also: #bind)
Binds environmental configuration to any browser created by this factory instance.
-
#each {|browser| ... } ⇒ Object
Iterate over each browser created by this factory.
-
#initialize(browser_name) ⇒ Base
constructor
Initializes new factory instances.
-
#new_browser_for(config) ⇒ Watir::Browser
A new browser for the given environmental configuration.
-
#override(config) ⇒ Object
Always use the given configuration when setting up a new browser, regardless of what has been previously configured.
-
#teardown(_env, _status) ⇒ Hash{String => String}
Executes additional teardown tasks.
Constructor Details
#initialize(browser_name) ⇒ Base
Initializes new factory instances.
70 71 72 73 74 75 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 70 def initialize(browser_name) @browser_name = browser_name @bindings = {} @browser_cache = {} @overrides = {} end |
Instance Attribute Details
#browser_name ⇒ Object (readonly)
Returns the value of attribute browser_name.
62 63 64 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 62 def browser_name @browser_name end |
Class Method Details
.bind {|values, browser_options| ... } ⇒ Object
Use configure instead.
Binds environmental configuration to any browser created by factories of this type. Use of this method should generally be reserved for macro-style invocation in derived classes.
38 39 40 41 42 43 44 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 38 def configure(*names, &blk) raise ArgumentError, 'no block given' unless block_given? key = names.length == 1 ? names.first : names default_bindings[key] ||= [] default_bindings[key] << blk end |
.bindings ⇒ Hash
All bindings for this factory class combined with those of super classes.
45 46 47 48 49 50 51 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 45 def bindings if superclass <= Base default_bindings.merge(superclass.bindings) { |_key, old, new| old + new } else default_bindings end end |
.configure(*names) {|values, browser_options| ... } ⇒ Object
Binds environmental configuration to any browser created by factories of this type. Use of this method should generally be reserved for macro-style invocation in derived classes.
29 30 31 32 33 34 35 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 29 def configure(*names, &blk) raise ArgumentError, 'no block given' unless block_given? key = names.length == 1 ? names.first : names default_bindings[key] ||= [] default_bindings[key] << blk end |
.default_bindings ⇒ Hash
Bindings for this factory class.
57 58 59 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 57 def default_bindings @default_bindings ||= {} end |
Instance Method Details
#all_binding_keys ⇒ Array
Returns a unique set of all the binding keys.
81 82 83 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 81 def all_binding_keys bindings.keys.flatten.uniq end |
#bindings ⇒ Hash
Effective bindings for this factory, those defined at the class level and those defined for this instance.
125 126 127 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 125 def bindings self.class.bindings.merge(@bindings) { |_key, old, new| old + new } end |
#browser_for(config) ⇒ Watir::Browser
Instantiate a browser using the given environmental configuration. Browsers are cached and reused as long as the configuration is the same.
139 140 141 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 139 def browser_for(config) @browser_cache[config] ||= new_browser_for(config) end |
#browser_options(config) ⇒ Hash
Browser options for the given configuration.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 149 def (config) config = config.merge(@overrides) = .tap do || bindings.each do |(names, bindings_for_option)| bindings_for_option.each do |binding| values = config.values_at(*Array(names)) unless values.any? { |value| value.nil? || value.to_s.empty? } binding.call(*values, ) end end end end () end |
#configure(*names) {|values, browser_options| ... } ⇒ Object Also known as: bind
Binds environmental configuration to any browser created by this factory instance.
111 112 113 114 115 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 111 def configure(*names, &blk) key = names.length == 1 ? names.first : names @bindings[key] ||= [] @bindings[key] << (blk || proc {}) end |
#each {|browser| ... } ⇒ Object
Iterate over each browser created by this factory.
173 174 175 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 173 def each(&blk) @browser_cache.values.each(&blk) end |
#new_browser_for(config) ⇒ Watir::Browser
A new browser for the given environmental configuration.
185 186 187 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 185 def new_browser_for(config) new_browser((config)) end |
#override(config) ⇒ Object
Always use the given configuration when setting up a new browser, regardless of what has been previously configured.
194 195 196 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 194 def override(config) @overrides.merge!(config) end |
#teardown(_env, _status) ⇒ Hash{String => String}
Executes additional teardown tasks.
207 208 209 |
# File 'lib/mediawiki_selenium/browser_factory/base.rb', line 207 def teardown(_env, _status) {} end |