watirgrid 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/EXAMPLES.rdoc +6 -6
- data/README.rdoc +3 -3
- data/Rakefile +1 -1
- data/examples/simple.rb +4 -4
- data/lib/watirgrid.rb +54 -27
- data/spec/grid_spec.rb +54 -55
- metadata +2 -2
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
|
-
|
95
|
-
|
94
|
+
grid = Watir::Grid.new(:ring_server_port => 12358)
|
95
|
+
grid.start(:quantity => 1, :read_all => true, :browser_type => 'ie')
|
96
96
|
threads = []
|
97
|
-
|
97
|
+
grid.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
|
-
|
108
|
+
grid = 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
|
-
|
111
|
+
grid = 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
|
-
|
114
|
+
grid.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
|
-
|
44
|
-
|
43
|
+
grid = Watir::Grid.new(:ring_server_port => 12358)
|
44
|
+
grid.start(:quantity => 1, :read_all => true)
|
45
45
|
threads = []
|
46
|
-
|
46
|
+
grid.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.
|
14
|
+
gem.version = "0.0.4"
|
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
|
-
|
5
|
-
:ring_server_host => '192.168.1.
|
6
|
-
|
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
7
|
|
8
8
|
threads = []
|
9
|
-
|
9
|
+
grid.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,11 +23,14 @@ 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)
|
@@ -72,15 +75,37 @@ module Watir
|
|
72
75
|
##
|
73
76
|
# Get all tuple spaces on ringserver
|
74
77
|
def get_tuples(params = {})
|
75
|
-
|
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
|
76
99
|
quantity = -1
|
77
100
|
else
|
78
|
-
quantity
|
101
|
+
quantity -= 1
|
79
102
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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)
|
84
109
|
@tuples = @ring_server.read_all([
|
85
110
|
:name,
|
86
111
|
nil, # watir provider
|
@@ -89,29 +114,30 @@ module Watir
|
|
89
114
|
nil, # hostname
|
90
115
|
architecture,
|
91
116
|
browser_type])
|
117
|
+
end
|
92
118
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
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
|
111
126
|
end
|
112
|
-
@browsers
|
113
127
|
end
|
114
|
-
|
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
|
+
|
115
141
|
##
|
116
142
|
# Convert tuple into a hash for easier handling
|
117
143
|
def tuple_to_hash(tuple)
|
@@ -125,6 +151,7 @@ module Watir
|
|
125
151
|
tuple_hash[:browser_type] = tuple[6]
|
126
152
|
tuple_hash
|
127
153
|
end
|
154
|
+
|
128
155
|
end
|
129
156
|
|
130
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
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
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
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
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,64 +53,63 @@ describe 'WatirGrid' do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'should take any 1 browser based on browser type' do
|
56
|
-
|
57
|
-
|
56
|
+
grid = Watir::Grid.new(:ring_server_port => 12351)
|
57
|
+
grid.start(:quantity => 1,
|
58
58
|
:take_all => true, :browser_type => 'safari')
|
59
|
-
|
59
|
+
grid.size.should == 1
|
60
60
|
end
|
61
61
|
|
62
|
-
it 'should fail to find any
|
63
|
-
|
64
|
-
|
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
|
-
|
66
|
+
grid.size.should == 0
|
67
67
|
end
|
68
68
|
|
69
|
-
it 'should fail to find any
|
70
|
-
|
71
|
-
|
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
|
-
|
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
|
-
|
78
|
-
|
77
|
+
grid = Watir::Grid.new(:ring_server_port => 12351)
|
78
|
+
grid.start(:quantity => 1,
|
79
79
|
:take_all => true, :architecture => 'universal-darwin10.0')
|
80
|
-
|
80
|
+
grid.size.should == 1
|
81
81
|
end
|
82
82
|
|
83
|
-
it 'should fail to find any
|
84
|
-
|
85
|
-
|
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
|
-
|
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
|
-
|
93
|
-
|
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
|
-
|
97
|
+
grid.size.should == 1
|
98
98
|
end
|
99
99
|
|
100
|
-
it 'should fail to find any
|
101
|
-
|
102
|
-
|
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
|
-
|
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
|
-
|
110
|
-
|
111
|
-
:take_all => true)
|
109
|
+
grid = Watir::Grid.new(:ring_server_port => 12351)
|
110
|
+
grid.start(:quantity => 1, :take_all => true)
|
112
111
|
threads = []
|
113
|
-
|
112
|
+
grid.browsers.each do |browser|
|
114
113
|
threads << Thread.new do
|
115
114
|
browser[:hostname].should == `hostname`.strip
|
116
115
|
browser[:architecture].should == Config::CONFIG['arch']
|
@@ -122,18 +121,18 @@ describe 'WatirGrid' do
|
|
122
121
|
end
|
123
122
|
end
|
124
123
|
threads.each {|thread| thread.join}
|
125
|
-
|
124
|
+
grid.size.should == 1
|
126
125
|
end
|
127
126
|
|
128
|
-
it 'should find no more
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
132
131
|
end
|
133
132
|
|
134
133
|
it 'should register a new browser on a remote provider' do
|
135
134
|
pending('provision of remote registration') do
|
136
|
-
|
135
|
+
grid.size.should == 0
|
137
136
|
end
|
138
137
|
end
|
139
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.
|
4
|
+
version: 0.0.4
|
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-
|
12
|
+
date: 2009-12-05 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|