watirgrid 0.0.2 → 0.0.3b

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,6 +16,7 @@ tmtags
16
16
  ## PROJECT::GENERAL
17
17
  coverage
18
18
  rdoc
19
+ doc
19
20
  pkg
20
21
 
21
22
  ## PROJECT::SPECIFIC
data/EXAMPLES.rdoc CHANGED
@@ -91,22 +91,27 @@ 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
- browsers = Watir::Grid.new(:ring_server_port => 12358)
95
- browsers.start(:quantity => 1, :read_all => true, :browser_type => 'ie')
96
- browsers.each do |browser, browser_id, hostname, arch, type|
97
- browser.goto("http://www.google.com")
98
- browser.text_field(:name, 'q').set("watirgrid")
99
- browser.button(:name, "btnI").click
94
+ grid = Watir::Grid.new(:ring_server_port => 12358)
95
+ grid.start(:quantity => 1, :read_all => true, :browser_type => 'ie')
96
+ threads = []
97
+ grid.browsers.each do |browser|
98
+ threads << Thread.new do
99
+ b = browser[:object].new_browser
100
+ b.goto("http://www.google.com")
101
+ b.text_field(:name, 'q').set("watirgrid")
102
+ b.button(:name, "btnI").click
103
+ end
100
104
  end
105
+ threads.each {|thread| thread.join}
101
106
 
102
107
  Stepping through this example we first instantiate a browsers object, specifying which ring server port to broadcast on when looking for available providers:
103
- browsers = Watir::Grid.new(:ring_server_port => 12358)
108
+ grid = Watir::Grid.new(:ring_server_port => 12358)
104
109
 
105
110
  You may also need to tell the code which host the ring server is on:
106
- browsers = Watir::Grid.new(:ring_server_port => 12358, :ring_server_host => 143.238.105.61)
111
+ grid = Watir::Grid.new(:ring_server_port => 12358, :ring_server_host => 143.238.105.61)
107
112
 
108
113
  Next we start up the grid, specifying the number of browsers we wish to use, and the method of accessing the tuple space:
109
- browsers.start(:quantity => 1, :read_all => true)
114
+ grid.start(:quantity => 1, :read_all => true)
110
115
 
111
116
  There are two methods for accessing the tuple space.
112
117
  :read_all => true
data/README.rdoc CHANGED
@@ -40,14 +40,18 @@ 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
- browsers = Watir::Grid.new(:ring_server_port => 12358)
44
- browsers.start(:quantity => 1, :read_all => true)
45
- browsers.size.should == 1
46
- browsers.each do |browser, browser_id|
47
- browser.goto("http://www.google.com")
48
- browser.text_field(:name, 'q').set("watirgrid")
49
- browser.button(:name, "btnI").click
43
+ grid = Watir::Grid.new(:ring_server_port => 12358)
44
+ grid.start(:quantity => 1, :read_all => true)
45
+ threads = []
46
+ grid.browsers.each do |browser|
47
+ threads << Thread.new do
48
+ b = browser[:object].new_browser
49
+ b.goto("http://www.google.com")
50
+ b.text_field(:name, 'q').set("watirgrid")
51
+ b.button(:name, "btnI").click
52
+ end
50
53
  end
54
+ threads.each {|thread| thread.join}
51
55
 
52
56
  You may wish to host the controller and providers on different machines in a real scenario. You can specify things like server hostnames, ports and access control lists for each of the different types of servers. For more help see:
53
57
  $ controller --help
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.2"
14
+ gem.version = "0.0.3b"
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,10 +1,17 @@
1
1
  require 'rubygems'
2
2
  require '../lib/watirgrid'
3
3
 
4
- browsers = Watir::Grid.new(:ring_server_port => 12358, :loglevel => Logger::DEBUG)
5
- browsers.start(:quantity => 1, :read_all => true, :browser_type => 'ie')
6
- browsers.each do |browser, browser_id, hostname, arch, type|
7
- browser.goto("http://www.google.com")
8
- browser.text_field(:name, 'q').set("watirgrid")
9
- browser.button(:name, "btnI").click
10
- end
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)
7
+
8
+ threads = []
9
+ grid.browsers.each do |browser|
10
+ threads << Thread.new do
11
+ b = browser[:object].new_browser
12
+ b.goto("http://www.google.com")
13
+ b.text_field(:name, 'q').set("watirgrid")
14
+ b.button(:name, "btnI").click
15
+ end
16
+ end
17
+ threads.each {|thread| thread.join}
data/lib/watirgrid.rb CHANGED
@@ -23,32 +23,19 @@ 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 = []
26
29
  end
27
30
 
28
31
  ##
29
32
  # Start required services
30
- def start(params = {})
33
+ def start(params = {})
31
34
  start_drb_server
32
35
  find_ring_server
33
36
  get_tuples(params)
34
37
  end
35
38
 
36
- ##
37
- # Yield a browser object when iterating over the grid of browsers
38
- def each
39
- threads = []
40
- id = 0
41
- @browsers.each do |browser|
42
- threads << Thread.new do
43
- id += 1
44
- @log.debug(browser)
45
- # yields a browser object, ID, hostname, architecture, type
46
- yield(browser[2].new_browser, id, browser[4],browser[5],browser[6])
47
- end
48
- end
49
- threads.each {|thread| thread.join}
50
- end
51
-
52
39
  ##
53
40
  # Return the size (quantity) of browsers started on the grid
54
41
  def size
@@ -88,15 +75,37 @@ module Watir
88
75
  ##
89
76
  # Get all tuple spaces on ringserver
90
77
  def get_tuples(params = {})
91
- if (params[:quantity].nil? or params[:quantity] == 0) then
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
92
99
  quantity = -1
93
100
  else
94
- quantity = params[:quantity] - 1
101
+ quantity -= 1
95
102
  end
96
- architecture = params[:architecture] || nil
97
- browser_type = params[:browser_type] || nil
98
-
99
- @browsers = []
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)
100
109
  @tuples = @ring_server.read_all([
101
110
  :name,
102
111
  nil, # watir provider
@@ -105,28 +114,44 @@ module Watir
105
114
  nil, # hostname
106
115
  architecture,
107
116
  browser_type])
117
+ end
108
118
 
109
- @log.info("Found #{@tuples.size} tuples.")
110
- if @tuples.size > 0 then
111
- @log.debug("Iterating from 0 to #{quantity}")
112
- @tuples[0..quantity].each do |tuple|
113
- @log.debug("Iterating through #{@tuples.size} tuples")
114
- hostname = tuple[4]
115
- if params[:hostnames] then
116
- if params[:hostnames][hostname] then
117
- @browsers << tuple
118
- @ring_server.take(tuple)if params[:take_all] == true
119
- end
120
- else
121
- @browsers << tuple
122
- @ring_server.take(tuple)if params[:take_all] == true
123
- end
124
- end
125
- else
126
- @browsers
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
127
126
  end
128
- @browsers
129
127
  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
+
141
+ ##
142
+ # Convert tuple into a hash for easier handling
143
+ def tuple_to_hash(tuple)
144
+ tuple_hash = {}
145
+ tuple_hash[:name] = tuple[0]
146
+ tuple_hash[:class] = tuple[1]
147
+ tuple_hash[:object] = tuple[2]
148
+ tuple_hash[:description] = tuple[3]
149
+ tuple_hash[:hostname] = tuple[4]
150
+ tuple_hash[:architecture] = tuple[5]
151
+ tuple_hash[:browser_type] = tuple[6]
152
+ tuple_hash
153
+ end
154
+
130
155
  end
131
156
 
132
157
  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 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
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
21
21
  end
22
22
 
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
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
27
27
  end
28
28
 
29
29
  it 'should take any 1 browser in the tuplespace' do
30
- browsers = Watir::Grid.new(:ring_server_port => 12351)
31
- browsers.start(:quantity => 1, :take_all => true)
32
- browsers.size.should == 1
30
+ grid = Watir::Grid.new(:ring_server_port => 12351)
31
+ grid.start(:quantity => 1, :take_all => true)
32
+ grid.size.should == 1
33
33
  end
34
34
 
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
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
39
39
  end
40
40
 
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
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
45
45
  end
46
46
 
47
- it 'should register 4 new browsers in the tuplespace' do
47
+ it 'should register 4 new grid 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,82 +53,86 @@ describe 'WatirGrid' do
53
53
  end
54
54
 
55
55
  it 'should take any 1 browser based on browser type' do
56
- browsers = Watir::Grid.new(:ring_server_port => 12351)
57
- browsers.start(:quantity => 1,
56
+ grid = Watir::Grid.new(:ring_server_port => 12351)
57
+ grid.start(:quantity => 1,
58
58
  :take_all => true, :browser_type => 'safari')
59
- browsers.size.should == 1
59
+ grid.size.should == 1
60
60
  end
61
61
 
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,
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,
65
65
  :take_all => true, :browser_type => 'firefox')
66
- browsers.size.should == 0
66
+ grid.size.should == 0
67
67
  end
68
68
 
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,
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,
72
72
  :take_all => true, :browser_type => 'penguin')
73
- browsers.size.should == 0
73
+ grid.size.should == 0
74
74
  end
75
75
 
76
76
  it 'should take any 1 browser based on specific architecture type' do
77
- browsers = Watir::Grid.new(:ring_server_port => 12351)
78
- browsers.start(:quantity => 1,
77
+ grid = Watir::Grid.new(:ring_server_port => 12351)
78
+ grid.start(:quantity => 1,
79
79
  :take_all => true, :architecture => 'universal-darwin10.0')
80
- browsers.size.should == 1
80
+ grid.size.should == 1
81
81
  end
82
82
 
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,
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,
86
86
  :take_all => true, :architecture => 'geos-1992')
87
- browsers.size.should == 0
87
+ grid.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
- browsers = Watir::Grid.new(:ring_server_port => 12351)
93
- browsers.start(:quantity => 1,
92
+ grid = Watir::Grid.new(:ring_server_port => 12351)
93
+ grid.start(:quantity => 1,
94
94
  :take_all => true,
95
95
  :hostnames => { hostname => "127.0.0.1"}
96
96
  )
97
- browsers.size.should == 1
97
+ grid.size.should == 1
98
98
  end
99
99
 
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,
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,
103
103
  :take_all => true, :hostnames => {
104
104
  "tokyo" => "127.0.0.1"})
105
- browsers.size.should == 0
105
+ grid.size.should == 0
106
106
  end
107
107
 
108
108
  it 'should take the last browser and execute some watir commands' do
109
- browsers = Watir::Grid.new(:ring_server_port => 12351)
110
- browsers.start(:quantity => 1,
111
- :take_all => true)
112
- browsers.each do |browser, browser_id, hostname, arch, type|
113
- browser_id.should == 1
114
- hostname.should == `hostname`.strip
115
- arch.should == Config::CONFIG['arch']
116
- type.should == 'safari'
117
- browser.goto(
118
- "http://localhost:4567/load/#{browser_id}/#{browser.object_id}")
109
+ grid = Watir::Grid.new(:ring_server_port => 12351)
110
+ grid.start(:quantity => 1, :take_all => true)
111
+ threads = []
112
+ grid.browsers.each do |browser|
113
+ threads << Thread.new do
114
+ browser[:hostname].should == `hostname`.strip
115
+ browser[:architecture].should == Config::CONFIG['arch']
116
+ browser[:browser_type].should == 'safari'
117
+ b = browser[:object].new_browser
118
+ b.goto("http://www.google.com")
119
+ b.text_field(:name, 'q').set("watirgrid")
120
+ b.button(:name, "btnI").click
119
121
  end
120
- browsers.size.should == 1
122
+ end
123
+ threads.each {|thread| thread.join}
124
+ grid.size.should == 1
121
125
  end
122
126
 
123
- it 'should find no more browsers in the tuplespace' do
124
- browsers = Watir::Grid.new(:ring_server_port => 12351)
125
- browsers.start(:read_all => true)
126
- browsers.size.should == 0
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
127
131
  end
128
132
 
129
133
  it 'should register a new browser on a remote provider' do
130
134
  pending('provision of remote registration') do
131
- browsers.size.should == 0
135
+ grid.size.should == 0
132
136
  end
133
137
  end
134
138
 
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.2
4
+ version: 0.0.3b
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-11-16 00:00:00 +11:00
12
+ date: 2009-12-05 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,6 @@ files:
40
40
  - LICENSE
41
41
  - README.rdoc
42
42
  - Rakefile
43
- - TODO.rdoc
44
43
  - bin/controller
45
44
  - bin/provider
46
45
  - examples/simple.rb
@@ -70,9 +69,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
69
  version:
71
70
  required_rubygems_version: !ruby/object:Gem::Requirement
72
71
  requirements:
73
- - - ">="
72
+ - - ">"
74
73
  - !ruby/object:Gem::Version
75
- version: "0"
74
+ version: 1.3.1
76
75
  version:
77
76
  requirements: []
78
77
 
data/TODO.rdoc DELETED
@@ -1,16 +0,0 @@
1
- === Grid
2
- - Specify rampup times
3
-
4
- === Providers
5
- - Remote registration of providers
6
- - Re-write tuple space during tear down
7
- - Response times
8
- - Network breakdown times
9
-
10
- === Protocols
11
- - Support for tcp or http?
12
-
13
- === Tests
14
- - How many providers is possible with druby?
15
- - Performance comparison proxied objects (DRbUndumped) vs. copied objects
16
-