Class: WatirProxy::Server
- Inherits:
-
Object
- Object
- WatirProxy::Server
- Defined in:
- lib/watir-proxy.rb
Constant Summary collapse
- @@default_browser =
:firefox
- @@default_drb_uri =
'druby://localhost:12444'
Instance Attribute Summary collapse
-
#current_browser ⇒ Object
Returns the value of attribute current_browser.
-
#stream ⇒ Object
Returns the value of attribute stream.
Class Method Summary collapse
- .browser(opts = {}) ⇒ Object
- .default_drb_uri ⇒ Object
- .drb_uri(opts = {}) ⇒ Object
- .start_service(opts = {}, &block) ⇒ Object
- .stop_service(&block) ⇒ Object
- .thread ⇒ Object
Instance Method Summary collapse
- #browser(opts = {}) ⇒ Object
- #browser_call(opts, name, *args) ⇒ Object
-
#initialize(stream = $stdout) ⇒ Server
constructor
A new instance of Server.
- #new_browser(type, driver) ⇒ Object
Constructor Details
#initialize(stream = $stdout) ⇒ Server
Returns a new instance of Server.
69 70 71 72 73 |
# File 'lib/watir-proxy.rb', line 69 def initialize(stream = $stdout) @stream = stream @current_browser = @@default_browser @browsers = {} end |
Instance Attribute Details
#current_browser ⇒ Object
Returns the value of attribute current_browser.
27 28 29 |
# File 'lib/watir-proxy.rb', line 27 def current_browser @current_browser end |
#stream ⇒ Object
Returns the value of attribute stream.
27 28 29 |
# File 'lib/watir-proxy.rb', line 27 def stream @stream end |
Class Method Details
.browser(opts = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/watir-proxy.rb', line 32 def self.browser(opts = {}) drb, browser = nil, nil begin drb = DRbObject.new_with_uri(self.drb_uri(opts)) drb.alive? if drb.respond_to?(:alive?) rescue DRb::DRbConnError => e browser = self.new(StringIO.new).browser(opts) end Browser.new({ :drb => drb, :browser => browser, :options => opts, }) end |
.default_drb_uri ⇒ Object
48 49 50 |
# File 'lib/watir-proxy.rb', line 48 def self.default_drb_uri @@default_drb_uri end |
.drb_uri(opts = {}) ⇒ Object
52 53 54 |
# File 'lib/watir-proxy.rb', line 52 def self.drb_uri(opts = {}) opts[:drb_uri] || ENV['WATIR_PROXY_DRB_URI'] || self.default_drb_uri end |
.start_service(opts = {}, &block) ⇒ Object
56 57 58 59 |
# File 'lib/watir-proxy.rb', line 56 def self.start_service(opts = {}, &block) DRb.start_service(self.drb_uri(opts), self.new) yield if block end |
.stop_service(&block) ⇒ Object
61 62 63 |
# File 'lib/watir-proxy.rb', line 61 def self.stop_service(&block) DRb.stop_service end |
.thread ⇒ Object
65 66 67 |
# File 'lib/watir-proxy.rb', line 65 def self.thread DRb.thread end |
Instance Method Details
#browser(opts = {}) ⇒ Object
79 80 81 82 |
# File 'lib/watir-proxy.rb', line 79 def browser(opts = {}) @current_browser = opts[:type] || @current_browser @browsers[@current_browser] ||= new_browser(@current_browser, opts[:driver]) end |
#browser_call(opts, name, *args) ⇒ Object
75 76 77 |
# File 'lib/watir-proxy.rb', line 75 def browser_call(opts, name, *args) self.browser(opts).send name, *args end |
#new_browser(type, driver) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/watir-proxy.rb', line 84 def new_browser(type, driver) driver = case driver when String eval driver when nil type else driver end Watir::Browser.new(driver) end |