Class: Watir::Grid
- Inherits:
-
Object
- Object
- Watir::Grid
- Defined in:
- lib/watirgrid.rb
Overview
Extend Watir with a Grid class which implements a grid of browsers by connecting to a tuplespace and instatiating remote browser objects on nominated providers.
Instance Attribute Summary collapse
-
#browsers ⇒ Object
Returns the value of attribute browsers.
-
#drb_server_uri ⇒ Object
Returns the value of attribute drb_server_uri.
-
#providers ⇒ Object
Returns the value of attribute providers.
-
#ring_server ⇒ Object
Returns the value of attribute ring_server.
-
#tuples ⇒ Object
Returns the value of attribute tuples.
Class Method Summary collapse
-
.control(params = {}, &block) ⇒ Object
This is a helper method to control a grid.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Grid
constructor
A new instance of Grid.
-
#iterate(&block) ⇒ Object
Iterate with a block over each of the remote providers.
-
#release_tuples ⇒ Object
Write tuple back to tuplespace when finished using it.
-
#setup ⇒ Object
Instantiate new browser object on each of the remote providers.
-
#size ⇒ Object
Return the size (quantity) of browsers started on the grid.
-
#start(params = {}) ⇒ Object
Start required services.
Constructor Details
#initialize(params = {}) ⇒ Grid
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/watirgrid.rb', line 15 def initialize(params = {}) @drb_server_host = params[:drb_server_host] || external_interface @drb_server_port = params[:drb_server_port] || 0 @controller_uri = params[:controller_uri] @ring_server_host = params[:ring_server_host] || external_interface unless @controller_uri @ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT @renewer = params[:renewer] || Rinda::SimpleRenewer.new logfile = params[:logfile] || STDOUT @log = Logger.new(logfile, 'daily') @log.level = params[:loglevel] || Logger::ERROR @log.datetime_format = "%Y-%m-%d %H:%M:%S " @browser_type = params[:browser_type] @browsers = [] @tuples = [] @providers = [] end |
Instance Attribute Details
#browsers ⇒ Object
Returns the value of attribute browsers.
13 14 15 |
# File 'lib/watirgrid.rb', line 13 def browsers @browsers end |
#drb_server_uri ⇒ Object
Returns the value of attribute drb_server_uri.
13 14 15 |
# File 'lib/watirgrid.rb', line 13 def drb_server_uri @drb_server_uri end |
#providers ⇒ Object
Returns the value of attribute providers.
13 14 15 |
# File 'lib/watirgrid.rb', line 13 def providers @providers end |
#ring_server ⇒ Object
Returns the value of attribute ring_server.
13 14 15 |
# File 'lib/watirgrid.rb', line 13 def ring_server @ring_server end |
#tuples ⇒ Object
Returns the value of attribute tuples.
13 14 15 |
# File 'lib/watirgrid.rb', line 13 def tuples @tuples end |
Class Method Details
.control(params = {}, &block) ⇒ Object
This is a helper method to control a grid.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/watirgrid.rb', line 76 def self.control(params = {}, &block) log = Logger.new(STDOUT, 'daily') log.level = params[:loglevel] || Logger::ERROR grid = self.new(params) grid.start(:read_all => true) threads = [] grid.browsers.each_with_index do |browser, index| sleep rampup(grid.size, params) threads << Thread.new do start = ::Time.now @browser = browser[:object].new_browser((params[:browser_type] || browser[:browser_type])) yield @browser, "#{index}" end end threads.each {|thread| thread.join} end |
Instance Method Details
#iterate(&block) ⇒ Object
Iterate with a block over each of the remote providers
64 65 66 67 68 69 70 71 72 |
# File 'lib/watirgrid.rb', line 64 def iterate &block threads = [] @providers.each do |browser| threads << Thread.new do yield browser end end threads.each {|thread| thread.join} end |
#release_tuples ⇒ Object
Write tuple back to tuplespace when finished using it
49 50 51 |
# File 'lib/watirgrid.rb', line 49 def release_tuples @tuples.each { |tuple| @ring_server.write(tuple) } end |
#setup ⇒ Object
Instantiate new browser object on each of the remote providers
55 56 57 58 59 60 |
# File 'lib/watirgrid.rb', line 55 def setup @browsers.each_with_index do |browser, index| sleep 0.15 @providers[index] ||= browser[:object].new_browser((browser[:browser_type] || @browser_type)) end end |
#size ⇒ Object
Return the size (quantity) of browsers started on the grid
43 44 45 |
# File 'lib/watirgrid.rb', line 43 def size @browsers.size end |
#start(params = {}) ⇒ Object
Start required services
34 35 36 37 38 39 |
# File 'lib/watirgrid.rb', line 34 def start(params = {}) start_drb_server find_ring_server(params) get_tuples(params) setup if params[:initiate] end |