Class: SeleniumProxy::Server
- Inherits:
-
Object
- Object
- SeleniumProxy::Server
- Defined in:
- lib/selenium-proxy.rb
Constant Summary collapse
- @@default_browser =
'*chrome'
- @@default_drb_uri =
'druby://localhost:12445'
- @@default_serenium_host =
'localhost'
- @@default_serenium_port =
4444
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(opts = {}) ⇒ Object
Constructor Details
#initialize(stream = $stdout) ⇒ Server
Returns a new instance of Server.
71 72 73 74 75 76 |
# File 'lib/selenium-proxy.rb', line 71 def initialize(stream = $stdout) @stream = stream @current_browser = @@default_browser @current_url = nil @browsers = {} end |
Instance Attribute Details
#current_browser ⇒ Object
Returns the value of attribute current_browser.
27 28 29 |
# File 'lib/selenium-proxy.rb', line 27 def current_browser @current_browser end |
#stream ⇒ Object
Returns the value of attribute stream.
27 28 29 |
# File 'lib/selenium-proxy.rb', line 27 def stream @stream end |
Class Method Details
.browser(opts = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/selenium-proxy.rb', line 34 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
50 51 52 |
# File 'lib/selenium-proxy.rb', line 50 def self.default_drb_uri @@default_drb_uri end |
.drb_uri(opts = {}) ⇒ Object
54 55 56 |
# File 'lib/selenium-proxy.rb', line 54 def self.drb_uri(opts = {}) opts[:drb_uri] || ENV['SELENIUM_PROXY_DRB_URI'] || self.default_drb_uri end |
.start_service(opts = {}, &block) ⇒ Object
58 59 60 61 |
# File 'lib/selenium-proxy.rb', line 58 def self.start_service(opts = {}, &block) DRb.start_service(self.drb_uri(opts), self.new) yield if block end |
.stop_service(&block) ⇒ Object
63 64 65 |
# File 'lib/selenium-proxy.rb', line 63 def self.stop_service(&block) DRb.stop_service end |
.thread ⇒ Object
67 68 69 |
# File 'lib/selenium-proxy.rb', line 67 def self.thread DRb.thread end |
Instance Method Details
#browser(opts = {}) ⇒ Object
82 83 84 85 86 |
# File 'lib/selenium-proxy.rb', line 82 def browser(opts = {}) opts[:type] = @current_browser = opts[:type] || @current_browser opts[:url] = @current_url = opts[:url] || @current_url @browsers[@current_url.to_s + @current_browser.to_s] ||= new_browser(opts) end |
#browser_call(opts, name, *args) ⇒ Object
78 79 80 |
# File 'lib/selenium-proxy.rb', line 78 def browser_call(opts, name, *args) self.browser(opts).send name, *args end |
#new_browser(opts = {}) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/selenium-proxy.rb', line 88 def new_browser(opts = {}) browser = Selenium::SeleniumDriver.new( opts[:serenium_host] || ENV['SELENIUM_PROXY_SERENIUM_HOST'] || @@default_serenium_host, opts[:serenium_port] || ENV['SELENIUM_PROXY_SERENIUM_PORT'] || @@default_serenium_port, opts[:type], opts[:url], opts[:serenium_timeout] || ENV['SELENIUM_PROXY_SERENIUM_TIMEOUT'] || nil ) browser.start browser end |