Class: Grid
- Inherits:
-
Object
- Object
- Grid
- Defined in:
- lib/grid/grid.rb
Defined Under Namespace
Classes: Helper
Class Method Summary collapse
Instance Method Summary collapse
- #browsers ⇒ Object
-
#initialize(params = {}) ⇒ Grid
constructor
A new instance of Grid.
- #iterate(&block) ⇒ Object
- #iterate_with_index(&block) ⇒ Object
- #providers ⇒ Object
- #setup ⇒ Object
- #size ⇒ Object
- #teardown ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Grid
Returns a new instance of Grid.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/grid/grid.rb', line 13 def initialize(params = {}) @log = Logger.new(STDOUT, 'daily') @log.level = params[:loglevel] || Logger::INFO @exclusive = params[:exclusive] @exclusive ? params[:take_all] = true : params[:read_all] = true @webdriver_browser_type = params[:browser].to_sym if params[:browser] @grid = Watir::Grid.new(params) @grid.start(params) @providers = @grid.browsers @browsers = [] end |
Class Method Details
.control(params = {}, &block) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/grid/grid.rb', line 71 def self.control(params = {}, &block) @exclusive = params[:exclusive] @exclusive ? params[:take_all] = true : params[:read_all] = true @webdriver_browser_type = params[:browser].to_sym if params[:browser] @grid = Watir::Grid.new(params) @grid.start(params) @browsers = [] threads = [] @grid.browsers.each_with_index do |browser, index| sleep rampup(params) threads << Thread.new(@webdriver_browser_type) do |webdriver_browser_type| @browser = browser[:object].new_browser(webdriver_browser_type) yield @browser, index end end threads.each {|thread| thread.join} @grid.release_tuples if @exclusive end |
Instance Method Details
#browsers ⇒ Object
29 30 31 |
# File 'lib/grid/grid.rb', line 29 def browsers @browsers end |
#iterate(&block) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/grid/grid.rb', line 51 def iterate &block threads = [] @browsers.each do |browser| threads << Thread.new do yield browser end end threads.each {|thread| thread.join} end |
#iterate_with_index(&block) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/grid/grid.rb', line 61 def iterate_with_index &block threads = [] @browsers.each_with_index do |browser, index| threads << Thread.new do yield browser, index end end threads.each {|thread| thread.join} end |
#providers ⇒ Object
33 34 35 |
# File 'lib/grid/grid.rb', line 33 def providers @providers end |
#setup ⇒ Object
37 38 39 40 41 42 |
# File 'lib/grid/grid.rb', line 37 def setup @grid.browsers.each_with_index do |browser, index| sleep 0.15 @browsers[index] ||= browser[:object].new_browser(@webdriver_browser_type) end end |
#size ⇒ Object
25 26 27 |
# File 'lib/grid/grid.rb', line 25 def size @grid.size end |
#teardown ⇒ Object
44 45 46 47 48 49 |
# File 'lib/grid/grid.rb', line 44 def teardown @browsers.each do |browser| browser.close end @grid.release_tuples if @exclusive end |