watirgrid 0.0.3b → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/EXAMPLES.rdoc CHANGED
@@ -91,10 +91,10 @@ Watir has been extended with a Grid class that can be used as follows:
91
91
  require 'rubygems'
92
92
  require 'watirgrid'
93
93
 
94
- grid = Watir::Grid.new(:ring_server_port => 12358)
95
- grid.start(:quantity => 1, :read_all => true, :browser_type => 'ie')
94
+ browsers = Watir::Grid.new(:ring_server_port => 12358)
95
+ @browsers = browsers.start(:quantity => 1, :read_all => true, :browser_type => 'ie')
96
96
  threads = []
97
- grid.browsers.each do |browser|
97
+ @browsers.each do |browser|
98
98
  threads << Thread.new do
99
99
  b = browser[:object].new_browser
100
100
  b.goto("http://www.google.com")
@@ -105,13 +105,13 @@ Watir has been extended with a Grid class that can be used as follows:
105
105
  threads.each {|thread| thread.join}
106
106
 
107
107
  Stepping through this example we first instantiate a browsers object, specifying which ring server port to broadcast on when looking for available providers:
108
- grid = Watir::Grid.new(:ring_server_port => 12358)
108
+ browsers = Watir::Grid.new(:ring_server_port => 12358)
109
109
 
110
110
  You may also need to tell the code which host the ring server is on:
111
- grid = Watir::Grid.new(:ring_server_port => 12358, :ring_server_host => 143.238.105.61)
111
+ browsers = Watir::Grid.new(:ring_server_port => 12358, :ring_server_host => 143.238.105.61)
112
112
 
113
113
  Next we start up the grid, specifying the number of browsers we wish to use, and the method of accessing the tuple space:
114
- grid.start(:quantity => 1, :read_all => true)
114
+ browsers.start(:quantity => 1, :read_all => true)
115
115
 
116
116
  There are two methods for accessing the tuple space.
117
117
  :read_all => true
data/README.rdoc CHANGED
@@ -40,10 +40,10 @@ This should find the recently started Ring Server and register a tuple for the W
40
40
  You will now be able to execute commands across remote browsers on your grid network.
41
41
 
42
42
  e.g.
43
- grid = Watir::Grid.new(:ring_server_port => 12358)
44
- grid.start(:quantity => 1, :read_all => true)
43
+ browsers = Watir::Grid.new(:ring_server_port => 12358)
44
+ @browsers = browsers.start(:quantity => 1, :read_all => true)
45
45
  threads = []
46
- grid.browsers.each do |browser|
46
+ @browsers.each do |browser|
47
47
  threads << Thread.new do
48
48
  b = browser[:object].new_browser
49
49
  b.goto("http://www.google.com")
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/90kts/watirgrid"
12
12
  gem.authors = ["Tim Koopmans"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
- gem.version = "0.0.3b"
14
+ gem.version = "0.0.3"
15
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
16
  end
17
17
  rescue LoadError
data/examples/simple.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'rubygems'
2
2
  require '../lib/watirgrid'
3
3
 
4
- grid = Watir::Grid.new(:ring_server_port => 12358,
5
- :ring_server_host => '192.168.1.101', :loglevel => Logger::DEBUG)
6
- grid.start(:quantity => 1, :read_all => true)
4
+ browsers = Watir::Grid.new(:ring_server_port => 12358,
5
+ :ring_server_host => '192.168.1.122', :loglevel => Logger::DEBUG)
6
+ @browsers = browsers.start(:quantity => 2, :read_all => true)
7
7
 
8
8
  threads = []
9
- grid.browsers.each do |browser|
9
+ @browsers.each do |browser|
10
10
  threads << Thread.new do
11
11
  b = browser[:object].new_browser
12
12
  b.goto("http://www.google.com")
data/lib/watirgrid.rb CHANGED
@@ -23,14 +23,11 @@ module Watir
23
23
  @log = Logger.new(logfile, 'daily')
24
24
  @log.level = params[:loglevel] || Logger::ERROR
25
25
  @log.datetime_format = "%Y-%m-%d %H:%M:%S "
26
-
27
- @browsers = []
28
- @tuples = []
29
26
  end
30
27
 
31
28
  ##
32
29
  # Start required services
33
- def start(params = {})
30
+ def start(params = {})
34
31
  start_drb_server
35
32
  find_ring_server
36
33
  get_tuples(params)
@@ -75,37 +72,15 @@ module Watir
75
72
  ##
76
73
  # Get all tuple spaces on ringserver
77
74
  def get_tuples(params = {})
78
- quantity = calculate_quantity(params[:quantity])
79
- read_tuples(params[:architecture], params[:browser_type])
80
- @log.info("Found #{@tuples.size} tuples.")
81
- if @tuples.size > -1 then
82
- @tuples[0..quantity].each do |tuple|
83
- if params[:hostnames]
84
- filter_tuple_by_hostname(tuple, params)
85
- else
86
- add_tuple_to_browsers(tuple)
87
- take_tuple(tuple) if params[:take_all] == true
88
- end
89
- end
90
- end
91
- end
92
-
93
- ##
94
- # Sets the quantity (upper limit of array) of tuples to retrieve
95
- # This is because some users prefer not to specify a zero based
96
- # index when asking for n browsers
97
- def calculate_quantity(quantity)
98
- if (quantity.nil? or quantity == 0) then
75
+ if (params[:quantity].nil? or params[:quantity] == 0) then
99
76
  quantity = -1
100
77
  else
101
- quantity -= 1
78
+ quantity = params[:quantity] - 1
102
79
  end
103
- end
104
-
105
- ##
106
- # Read all tuples filtered by architecture and browser type
107
- # then populate the tuples accessor
108
- def read_tuples(architecture, browser_type)
80
+ architecture = params[:architecture] || nil
81
+ browser_type = params[:browser_type] || nil
82
+
83
+ @browsers = []
109
84
  @tuples = @ring_server.read_all([
110
85
  :name,
111
86
  nil, # watir provider
@@ -114,30 +89,29 @@ module Watir
114
89
  nil, # hostname
115
90
  architecture,
116
91
  browser_type])
117
- end
118
92
 
119
- ##
120
- # Filter tuple by hostnames
121
- def filter_tuple_by_hostname(tuple, params={})
122
- hostname = tuple[4]
123
- if (params[:hostnames][hostname]) then
124
- add_tuple_to_browsers(tuple)
125
- take_tuple(tuple) if params[:take_all] == true
93
+ @log.info("Found #{@tuples.size} tuples.")
94
+ if @tuples.size > -1 then
95
+ @log.debug("Iterating from 0 to #{quantity}")
96
+ @tuples[0..quantity].each do |tuple|
97
+ @log.debug("Iterating through #{@tuples.size} tuples")
98
+ hostname = tuple[4]
99
+ if params[:hostnames] then
100
+ if params[:hostnames][hostname] then
101
+ @browsers << tuple_to_hash(tuple)
102
+ @ring_server.take(tuple)if params[:take_all] == true
103
+ end
104
+ else
105
+ @browsers << tuple_to_hash(tuple)
106
+ @ring_server.take(tuple)if params[:take_all] == true
107
+ end
108
+ end
109
+ else
110
+ @browsers
126
111
  end
112
+ @browsers
127
113
  end
128
-
129
- ##
130
- # Add a tuple to the browsers accessor
131
- def add_tuple_to_browsers(tuple)
132
- @browsers << tuple_to_hash(tuple)
133
- end
134
-
135
- ##
136
- # Take a tuple from the tuple space
137
- def take_tuple(tuple)
138
- @ring_server.take(tuple)
139
- end
140
-
114
+
141
115
  ##
142
116
  # Convert tuple into a hash for easier handling
143
117
  def tuple_to_hash(tuple)
@@ -151,7 +125,6 @@ module Watir
151
125
  tuple_hash[:browser_type] = tuple[6]
152
126
  tuple_hash
153
127
  end
154
-
155
128
  end
156
129
 
157
130
  end
data/spec/grid_spec.rb CHANGED
@@ -14,37 +14,37 @@ describe 'WatirGrid' do
14
14
  end
15
15
  end
16
16
 
17
- it 'should return how many grid are available in the tuplespace' do
18
- grid = Watir::Grid.new(:ring_server_port => 12351)
19
- grid.start(:read_all => true)
20
- grid.size.should == 5
17
+ it 'should return how many browsers are available in the tuplespace' do
18
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
19
+ browsers.start(:read_all => true)
20
+ browsers.size.should == 5
21
21
  end
22
22
 
23
- it 'should read any 2 grid in the tuplespace' do
24
- grid = Watir::Grid.new(:ring_server_port => 12351)
25
- grid.start(:quantity => 2, :read_all => true)
26
- grid.size.should == 2
23
+ it 'should read any 2 browsers in the tuplespace' do
24
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
25
+ browsers.start(:quantity => 2, :read_all => true)
26
+ browsers.size.should == 2
27
27
  end
28
28
 
29
29
  it 'should take any 1 browser in the tuplespace' do
30
- grid = Watir::Grid.new(:ring_server_port => 12351)
31
- grid.start(:quantity => 1, :take_all => true)
32
- grid.size.should == 1
30
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
31
+ browsers.start(:quantity => 1, :take_all => true)
32
+ browsers.size.should == 1
33
33
  end
34
34
 
35
- it 'should take all grid remaining in tuplespace' do
36
- grid = Watir::Grid.new(:ring_server_port => 12351)
37
- grid.start(:take_all => true)
38
- grid.size.should == 4
35
+ it 'should take all browsers remaining in tuplespace' do
36
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
37
+ browsers.start(:take_all => true)
38
+ browsers.size.should == 4
39
39
  end
40
40
 
41
- it 'should find no more grid in the tuplespace' do
42
- grid = Watir::Grid.new(:ring_server_port => 12351)
43
- grid.start(:read_all => true)
44
- grid.size.should == 0
41
+ it 'should find no more browsers in the tuplespace' do
42
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
43
+ browsers.start(:read_all => true)
44
+ browsers.size.should == 0
45
45
  end
46
46
 
47
- it 'should register 4 new grid in the tuplespace' do
47
+ it 'should register 4 new browsers in the tuplespace' do
48
48
  1.upto(4) do
49
49
  provider = Provider.new(:ring_server_port => 12351,
50
50
  :loglevel => Logger::ERROR, :browser_type => 'safari')
@@ -53,63 +53,64 @@ describe 'WatirGrid' do
53
53
  end
54
54
 
55
55
  it 'should take any 1 browser based on browser type' do
56
- grid = Watir::Grid.new(:ring_server_port => 12351)
57
- grid.start(:quantity => 1,
56
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
57
+ browsers.start(:quantity => 1,
58
58
  :take_all => true, :browser_type => 'safari')
59
- grid.size.should == 1
59
+ browsers.size.should == 1
60
60
  end
61
61
 
62
- it 'should fail to find any grid based on a specific browser type' do
63
- grid = Watir::Grid.new(:ring_server_port => 12351)
64
- grid.start(:quantity => 1,
62
+ it 'should fail to find any browsers based on a specific browser type' do
63
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
64
+ browsers.start(:quantity => 1,
65
65
  :take_all => true, :browser_type => 'firefox')
66
- grid.size.should == 0
66
+ browsers.size.should == 0
67
67
  end
68
68
 
69
- it 'should fail to find any grid based on a unknown browser type' do
70
- grid = Watir::Grid.new(:ring_server_port => 12351)
71
- grid.start(:quantity => 1,
69
+ it 'should fail to find any browsers based on a unknown browser type' do
70
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
71
+ browsers.start(:quantity => 1,
72
72
  :take_all => true, :browser_type => 'penguin')
73
- grid.size.should == 0
73
+ browsers.size.should == 0
74
74
  end
75
75
 
76
76
  it 'should take any 1 browser based on specific architecture type' do
77
- grid = Watir::Grid.new(:ring_server_port => 12351)
78
- grid.start(:quantity => 1,
77
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
78
+ browsers.start(:quantity => 1,
79
79
  :take_all => true, :architecture => 'universal-darwin10.0')
80
- grid.size.should == 1
80
+ browsers.size.should == 1
81
81
  end
82
82
 
83
- it 'should fail to find any grid based on unknown architecture type' do
84
- grid = Watir::Grid.new(:ring_server_port => 12351)
85
- grid.start(:quantity => 1,
83
+ it 'should fail to find any browsers based on unknown architecture type' do
84
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
85
+ browsers.start(:quantity => 1,
86
86
  :take_all => true, :architecture => 'geos-1992')
87
- grid.size.should == 0
87
+ browsers.size.should == 0
88
88
  end
89
89
 
90
90
  it 'should take any 1 browser based on specific hostname' do
91
91
  hostname = `hostname`.strip
92
- grid = Watir::Grid.new(:ring_server_port => 12351)
93
- grid.start(:quantity => 1,
92
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
93
+ browsers.start(:quantity => 1,
94
94
  :take_all => true,
95
95
  :hostnames => { hostname => "127.0.0.1"}
96
96
  )
97
- grid.size.should == 1
97
+ browsers.size.should == 1
98
98
  end
99
99
 
100
- it 'should fail to find any grid based on unknown hostname' do
101
- grid = Watir::Grid.new(:ring_server_port => 12351)
102
- grid.start(:quantity => 1,
100
+ it 'should fail to find any browsers based on unknown hostname' do
101
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
102
+ browsers.start(:quantity => 1,
103
103
  :take_all => true, :hostnames => {
104
104
  "tokyo" => "127.0.0.1"})
105
- grid.size.should == 0
105
+ browsers.size.should == 0
106
106
  end
107
107
 
108
108
  it 'should take the last browser and execute some watir commands' do
109
- grid = Watir::Grid.new(:ring_server_port => 12351)
110
- grid.start(:quantity => 1, :take_all => true)
109
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
110
+ @browsers = browsers.start(:quantity => 1,
111
+ :take_all => true)
111
112
  threads = []
112
- grid.browsers.each do |browser|
113
+ @browsers.each do |browser|
113
114
  threads << Thread.new do
114
115
  browser[:hostname].should == `hostname`.strip
115
116
  browser[:architecture].should == Config::CONFIG['arch']
@@ -121,18 +122,18 @@ describe 'WatirGrid' do
121
122
  end
122
123
  end
123
124
  threads.each {|thread| thread.join}
124
- grid.size.should == 1
125
+ browsers.size.should == 1
125
126
  end
126
127
 
127
- it 'should find no more grid in the tuplespace' do
128
- grid = Watir::Grid.new(:ring_server_port => 12351)
129
- grid.start(:read_all => true)
130
- grid.size.should == 0
128
+ it 'should find no more browsers in the tuplespace' do
129
+ browsers = Watir::Grid.new(:ring_server_port => 12351)
130
+ browsers.start(:read_all => true)
131
+ browsers.size.should == 0
131
132
  end
132
133
 
133
134
  it 'should register a new browser on a remote provider' do
134
135
  pending('provision of remote registration') do
135
- grid.size.should == 0
136
+ browsers.size.should == 0
136
137
  end
137
138
  end
138
139
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watirgrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3b
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Koopmans
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-05 00:00:00 +11:00
12
+ date: 2009-12-01 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -69,9 +69,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
69
  version:
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">"
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 1.3.1
74
+ version: "0"
75
75
  version:
76
76
  requirements: []
77
77