watirgrid 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/EXAMPLES.rdoc ADDED
@@ -0,0 +1,127 @@
1
+ = Common Examples
2
+
3
+ == Starting a Controller
4
+ A controller has the following startup options:
5
+ controller --help
6
+ Usage: controller [options]
7
+ Specific options:
8
+ -H, --drb-server-host HOST Specify DRb Server interface to host on
9
+ -d, --drb-server-port PORT Specify DRb Server port to listen on
10
+ -h, --ring-server-host HOST Specify Ring Server interface to host on
11
+ -r, --ring-server-port PORT Specify Ring Server port to listen on
12
+ -a, --access-control-list ACLS Specify a comma separated Access Control List
13
+ -l, --log-level LEVEL Specify log level {DEBUG|INFO|ERROR}
14
+ --help Show this message
15
+
16
+ === Default
17
+ To start a controller with default settings:
18
+ $ controller
19
+
20
+ This will bind the controller to your external facing interface and register the ring server to listen on port 12358
21
+ e.g.
22
+ DRb server started on : druby://143.238.105.61:11235
23
+ Ring server started on: druby://143.238.105.61:12358
24
+
25
+ === Start on specific interface or ports
26
+ To start a controller on specific interfaces or ports:
27
+ $ controller -H 127.0.0.1 -h 127.0.0.1 -d 12345 -r 54321
28
+
29
+ This will bind the controller to the localhost (127.0.0.1) with the DRb server listening on port 12345 and the ring server listening on port 54321
30
+ e.g.
31
+ DRb server started on : druby://127.0.0.1:12345
32
+ Ring server started on: druby://127.0.0.1:54321
33
+
34
+
35
+ === Start with access control list
36
+ To start a controller with an access control list:
37
+ $ controller -a deny,all,allow,127.0.0.1 -H 127.0.0.1 -h 127.0.0.1
38
+
39
+ This will bind the controller to the localhost (127.0.0.1) and deny all access to the controller by default, whilst allowing access from localhost only. The ACL constructor takes an array of strings. The first string of a pair is always “allow” or “deny”, and it’s followed by the address or addresses to allow or deny access.
40
+
41
+ == Starting a Provider
42
+ A provider has similar startup options:
43
+ provider --help
44
+ # Usage: provider [options]
45
+ # Specific options:
46
+ # -H, --drb-server-host HOST Specify DRb Server interface to host on
47
+ # -d, --drb-server-port PORT Specify DRb Server port to listen on
48
+ # -h, --ring-server-host HOST Specify Ring Server host to connect to
49
+ # -r, --ring-server-port PORT Specify Ring Server port to broadcast on
50
+ # -b, --browser-type TYPE Specify browser type to register {ie|firefox|safari}
51
+ # -a, --access-control-list ACLS Specify a comma separated Access Control List
52
+ # -l, --log-level LEVEL Specify log level {DEBUG|INFO|ERROR}
53
+ # --help Show this message
54
+
55
+ === Default
56
+ To start a controller with default settings:
57
+ $ provider
58
+
59
+ This will bind the provider to your external facing interface attempt to find the ring server on the default port of 12358
60
+ e.g.
61
+ DRb server started on : druby://143.238.105.61:11236
62
+ Ring server found on : druby://143.238.105.61:12358
63
+ New tuple registered : druby://143.238.105.61:12358
64
+
65
+ === Start on specific interface or ports
66
+ To start a provider on specific interfaces or ports:
67
+ $ provider -r 12358 -h 143.238.105.61
68
+
69
+ This will attempt to find the ring server on the port and hostname specifed
70
+ e.g.
71
+ DRb server started on : druby://143.238.105.61:11236
72
+ Ring server found on : druby://143.238.105.61:12358
73
+ New tuple registered : druby://143.238.105.61:12358
74
+
75
+ === Start with access control list
76
+ To start a controller with an access control list:
77
+ $ provider -a deny,all,allow,127.0.0.1
78
+
79
+ This will deny all access by default and allow access to this provider on localhost only.
80
+
81
+ === Start with a specific browser supported
82
+ By default, the provider will try to instantiate a browser object based on availability with your operating system e.g. Internet Explorer, Firefox or Safari. You can force provision of a set browser type as follows:
83
+ $ provider -b safari
84
+
85
+ This will provide a Safari browser object. Other options are:
86
+ $ provider -b ie
87
+ $ provider -b firefox
88
+
89
+ == Consuming Browser Objects on the Grid
90
+ Watir has been extended with a Grid class that can be used as follows:
91
+ require 'rubygems'
92
+ require 'watirgrid'
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
100
+ end
101
+
102
+ 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)
104
+
105
+ 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)
107
+
108
+ 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)
110
+
111
+ There are two methods for accessing the tuple space.
112
+ :read_all => true
113
+ :take_all => true
114
+ *Read* *All* will read all browsers in the tuple space provided by the providers. This leaves the tuple open to other clients.
115
+
116
+ *Take* *All* will take all browsers in the tuple space in a destructive manner. That is, once a tuple has been taken, no other clients will be able to re-use that tuple. This is useful if you do not want concurrent access to the same host, for example, multiple browsers running on the one machine.
117
+
118
+ The quantity attribute will determine how many browsers are accessed.
119
+ :quantity => 10
120
+ Will attempt to access 10 tuples if they are available.
121
+
122
+ Other attributes include:
123
+ :hostnames => { "localhost" => "127.0.0.1"}
124
+ Will determine which providers identified by a hash of hostnames that should be accessed. Useful if trying to limit the test to run from specific hostnames or IP addresses.
125
+
126
+ :browser_type => 'firefox'
127
+ Will determine which providers identified by a browser type should be accessed. Useful if trying to to test with specific browser types.
@@ -1,14 +1,18 @@
1
- = Release Notes
2
- == 0.0.1
1
+ == Release Notes
2
+ === 0.0.1
3
3
  Added access control lists for the controller and provider. This lets the user specify ACLs by way of simple white/blacklist security similar to that used by the Unix /etc/hosts.allow and /etc/hosts.deny files. The ACL constructor takes an array of strings. The first string of a pair is always “allow” or “deny”, and it’s followed by the address or addresses to allow or deny access.
4
4
 
5
- e.g. ./provider.rb -a deny,all,allow,127.0.0.1
5
+ e.g.
6
+ provider.rb -a deny,all,allow,127.0.0.1
6
7
  This would deny all access to this provider by default and allow access only from the localhost (127.0.0.1). This is the default setting if no ACLs are specified from the command line. This would affect all connectivity from the controller to the providers.
7
8
 
8
- e.g. ./controller.rb -a deny,all,allow,192.168.1.*
9
+ e.g.
10
+ controller -a deny,all,allow,192.168.1.*
9
11
  This would deny all access to the controller by default with access allowed from any host in the 192.168.1.* subnet. This would affect all connectivity from the providers to the controller.
10
12
 
11
- ---
12
-
13
13
  Added startup bin scripts for the provider and controller. Ruby Gems will automatically deploy these on installation.
14
14
 
15
+ ---
16
+ === 0.0.2
17
+ Allowed specification of remote host for ring server with -h option on provider.
18
+
data/README.rdoc CHANGED
@@ -1,55 +1,77 @@
1
- = watirgrid
1
+ = WatirGrid
2
2
 
3
3
  WatirGrid allows for distributed testing across a grid network using Watir.
4
4
 
5
- Basic instructions are:
5
+ == Getting Started
6
+ This gem is hosted on Gemcutter. Gemcutter is the next generation of gem hosting for the Ruby community. To get started:
7
+ gem install gemcutter
8
+ gem tumble
9
+
10
+ Then to install WatirGrid:
11
+ gem install watirgrid
12
+
13
+ === The Basics
14
+ WatirGrid is built on Rinda which implements the Linda distributed computing paradigm in Ruby. According to Wikipedia: “Linda is a model of coordination and communication among several parallel processes operating upon objects stored in and retrieved from shared, virtual, associative memory.”
15
+
16
+ In other words, WatirGrid allows multiple parallel processes to *_provide_* remote Watir objects in the form of tuple spaces across a grid network. This grid network is *_controlled_* by a ring server.
17
+
18
+ ==== Key Terminology
19
+ The *controller* implements a repository of tuples (tuple space) that can be accessed concurrently. The controller hosts the *ring* *server* which advertises these tuples across a grid network. Typically you will host one controller on a central machine.
20
+
21
+ The *providers* make remote Watir objects available to the tuple space hosted by the *ring* *server*. Typically you will host one or many providers on your grid network, for example, each PC may become a single provider of a Watir tuple in the form of an Internet Explorer, Firefox or Safari browser object.
22
+
23
+ === Simple Example
6
24
 
7
25
  Pick a server to host the 'controller' for the ring server and execute the following:
8
- $ controller -l INFO
26
+ $ controller
9
27
 
10
28
  This should find your external facing IP and start the corresponding DRb and Ring Servers:
11
- DRb server started on : druby://192.168.1.105:11235
12
- Ring server started on: druby://192.168.1.105:12358
29
+ DRb server started on : druby://143.238.105.61:11235
30
+ Ring server started on: druby://143.238.105.61:12358
13
31
 
14
32
  On each client PC, host the 'provider' for the distributed (DRb) Watir objects
15
- $ provider -l INFO
33
+ $ provider
16
34
 
17
35
  This should find the recently started Ring Server and register a tuple for the Watir object:
18
- DRb server started on : druby://192.168.1.105:64864
19
- New tuple registered : druby://192.168.1.105:12358
36
+ DRb server started on : druby://143.238.105.61:11236
37
+ Ring server found on : druby://143.238.105.61:12358
38
+ New tuple registered : druby://143.238.105.61:12358
20
39
 
21
40
  You will now be able to execute commands across remote browsers on your grid network.
22
41
 
23
- Check the watirgid_spec.rb for some examples ...
24
-
25
42
  e.g.
26
- browsers = Watir::Grid.new(:ring_server_port => 12351)
27
- browsers.start(:quantity => 2, :read_all => true)
28
- browsers.size.should == 2
29
- browsers.each do |browser, browser_id|
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|
30
47
  browser.goto("http://www.google.com")
31
48
  browser.text_field(:name, 'q').set("watirgrid")
32
49
  browser.button(:name, "btnI").click
33
50
  end
34
51
 
35
- For more help see:
36
- $ controller -h
52
+ 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
+ $ controller --help
37
54
  Usage: controller [options]
38
55
  Specific options:
39
- -d, --drb-server-port PORT Specify DRb Server port to listen on
40
- -r, --ring-server-port PORT Specify Ring Server port to listen on
41
- -l, --log-level LEVEL Specify log level {DEBUG|INFO|ERROR}
42
- -h, --help Show this message
43
-
44
- $ ./provider -h
56
+ -H, --drb-server-host HOST Specify DRb Server interface to host on
57
+ -d, --drb-server-port PORT Specify DRb Server port to listen on
58
+ -h, --ring-server-host HOST Specify Ring Server interface to host on
59
+ -r, --ring-server-port PORT Specify Ring Server port to listen on
60
+ -a, --access-control-list ACLS Specify a comma separated Access Control List
61
+ -l, --log-level LEVEL Specify log level {DEBUG|INFO|ERROR}
62
+ --help Show this message
63
+
64
+ $ provider --help
45
65
  Usage: provider [options]
46
66
  Specific options:
47
- -r, --ring-server-port PORT Specify Ring Server port to broadcast on
48
- -b, --browser-type TYPE Specify browser type to register {ie|firefox|safari}
49
- -l, --log-level LEVEL Specify log level {DEBUG|INFO|ERROR}
50
- -h, --help Show this message
51
-
52
- I'll update the wiki soon'ish!
67
+ -H, --drb-server-host HOST Specify DRb Server interface to host on
68
+ -d, --drb-server-port PORT Specify DRb Server port to listen on
69
+ -h, --ring-server-host HOST Specify Ring Server host to connect to
70
+ -r, --ring-server-port PORT Specify Ring Server port to broadcast on
71
+ -b, --browser-type TYPE Specify browser type to register {ie|firefox|safari}
72
+ -a, --access-control-list ACLS Specify a comma separated Access Control List
73
+ -l, --log-level LEVEL Specify log level {DEBUG|INFO|ERROR}
74
+ --help Show this message
53
75
 
54
76
  == Copyright
55
77
 
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.1"
14
+ gem.version = "0.0.2"
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/TODO.rdoc ADDED
@@ -0,0 +1,16 @@
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
+
data/bin/controller CHANGED
@@ -8,10 +8,18 @@ OptionParser.new do |opts|
8
8
  opts.banner = "Usage: controller [options]"
9
9
  opts.separator ""
10
10
  opts.separator "Specific options:"
11
+ opts.on("-H HOST", "--drb-server-host", String,
12
+ "Specify DRb Server interface to host on") do |H|
13
+ options[:drb_server_host] = H || nil
14
+ end
11
15
  opts.on("-d PORT", "--drb-server-port", Integer,
12
16
  "Specify DRb Server port to listen on") do |d|
13
17
  options[:drb_server_port] = d
14
18
  end
19
+ opts.on("-h HOST", "--ring-server-host", String,
20
+ "Specify Ring Server interface to host on") do |h|
21
+ options[:ring_server_host] = h || nil
22
+ end
15
23
  opts.on("-r PORT", "--ring-server-port", Integer,
16
24
  "Specify Ring Server port to listen on") do |r|
17
25
  options[:ring_server_port] = r
@@ -40,9 +48,11 @@ OptionParser.new do |opts|
40
48
  end.parse!
41
49
 
42
50
  controller = Controller.new(
51
+ :drb_server_host => options[:drb_server_host],
43
52
  :drb_server_port => options[:drb_server_port] || 11235,
53
+ :ring_server_host => options[:ring_server_host],
44
54
  :ring_server_port => options[:ring_server_port] || 12358,
45
- :acls => options[:acls] || %w{ deny all allow 127.0.0.1 },
55
+ :acls => options[:acls] || %w{ allow all },
46
56
  :loglevel => options[:loglevel]
47
57
  )
48
58
  controller.start
data/bin/provider CHANGED
@@ -8,6 +8,18 @@ OptionParser.new do |opts|
8
8
  opts.banner = "Usage: provider [options]"
9
9
  opts.separator ""
10
10
  opts.separator "Specific options:"
11
+ opts.on("-H HOST", "--drb-server-host", String,
12
+ "Specify DRb Server interface to host on") do |H|
13
+ options[:drb_server_host] = H || nil
14
+ end
15
+ opts.on("-d PORT", "--drb-server-port", Integer,
16
+ "Specify DRb Server port to listen on") do |d|
17
+ options[:drb_server_port] = d
18
+ end
19
+ opts.on("-h HOST", "--ring-server-host", String,
20
+ "Specify Ring Server host to connect to") do |h|
21
+ options[:ring_server_host] = h || nil
22
+ end
11
23
  opts.on("-r PORT", "--ring-server-port", Integer,
12
24
  "Specify Ring Server port to broadcast on") do |r|
13
25
  options[:ring_server_port] = r
@@ -40,9 +52,12 @@ OptionParser.new do |opts|
40
52
  end.parse!
41
53
 
42
54
  provider = Provider.new(
55
+ :drb_server_host => options[:drb_server_host],
56
+ :drb_server_port => options[:drb_server_port] || 11236,
57
+ :ring_server_host => options[:ring_server_host],
43
58
  :ring_server_port => options[:ring_server_port] || 12358,
44
59
  :browser_type => options[:browser_type] || nil,
45
- :acls => options[:acls] || %w{ deny all allow 127.0.0.1 },
60
+ :acls => options[:acls] || %w{ allow all },
46
61
  :loglevel => options[:loglevel])
47
62
  provider.start
48
63
  DRb.thread.join
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require '../lib/watirgrid'
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
data/lib/controller.rb CHANGED
@@ -34,9 +34,10 @@ class Controller
34
34
 
35
35
  attr_accessor :drb_server_uri, :ring_server_uri
36
36
 
37
- def initialize(params = {})
38
- @host = params[:interface] || external_interface
37
+ def initialize(params = {})
38
+ @drb_server_host = params[:drb_server_host] || external_interface
39
39
  @drb_server_port = params[:drb_server_port] || 0
40
+ @ring_server_host = params[:ring_server_host] || external_interface
40
41
  @ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT
41
42
  @acls = params[:acls]
42
43
 
@@ -58,14 +59,16 @@ class Controller
58
59
  DRb.install_acl(ACL.new(@acls))
59
60
 
60
61
  # start the DRb Server
61
- drb_server = DRb.start_service("druby://#{@host}:#{@drb_server_port}", tuple_space)
62
+ drb_server = DRb.start_service(
63
+ "druby://#{@drb_server_host}:#{@drb_server_port}", tuple_space)
62
64
 
63
65
  # obtain DRb Server uri
64
66
  @drb_server_uri = drb_server.uri
65
67
  @log.info("DRb server started on : #{@drb_server_uri}")
66
68
 
67
69
  # start the Ring Server
68
- ring_server = Rinda::RingServer.new(tuple_space, @host, @ring_server_port)
70
+ ring_server = Rinda::RingServer.new(tuple_space,
71
+ @ring_server_host, @ring_server_port)
69
72
 
70
73
  # obtain Ring Server uri
71
74
  @ring_server_uri = ring_server.uri
data/lib/provider.rb CHANGED
@@ -52,9 +52,9 @@ module Watir
52
52
  end
53
53
 
54
54
  def find_supported_browser
55
- if Watir::Safari then return Watir::Safari end
56
55
  if Watir::IE then return Watir::IE end
57
56
  if FireWatir::Firefox then return FireWatir::Firefox end
57
+ if Watir::Safari then return Watir::Safari end
58
58
  end
59
59
 
60
60
  def new_browser
@@ -74,8 +74,9 @@ class Provider
74
74
  attr_accessor :drb_server_uri, :ring_server_uri
75
75
 
76
76
  def initialize(params = {})
77
- @host = params[:interface] || external_interface
77
+ @drb_server_host = params[:drb_server_host] || external_interface
78
78
  @drb_server_port = params[:drb_server_port] || 0
79
+ @ring_server_host = params[:ring_server_host] || external_interface
79
80
  @ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT
80
81
 
81
82
  @renewer = params[:renewer] || Rinda::SimpleRenewer.new
@@ -86,7 +87,6 @@ class Provider
86
87
  @log.level = params[:loglevel] || Logger::INFO
87
88
  @log.datetime_format = "%Y-%m-%d %H:%M:%S "
88
89
 
89
- @log.debug("DRB Server Port #{@drb_server_port}\nRing Server Port #{@ring_server_port}")
90
90
  end
91
91
 
92
92
  ##
@@ -97,11 +97,12 @@ class Provider
97
97
  architecture = Config::CONFIG['arch']
98
98
  hostname = ENV['SERVER_NAME'] || %x{hostname}.strip
99
99
 
100
- # Setup the security--remember to call before DRb.start_service()
100
+ # setup the security--remember to call before DRb.start_service()
101
101
  DRb.install_acl(ACL.new(@acls))
102
102
 
103
103
  # start the DRb Server
104
- drb_server = DRb.start_service("druby://#{@host}:#{@drb_server_port}")
104
+ drb_server = DRb.start_service(
105
+ "druby://#{@drb_server_host}:#{@drb_server_port}")
105
106
 
106
107
  # obtain DRb Server uri
107
108
  @drb_server_uri = drb_server.uri
@@ -119,15 +120,16 @@ class Provider
119
120
  ]
120
121
 
121
122
  # locate the Rinda Ring Server via a UDP broadcast
122
- ring_server = Rinda::RingFinger.new(@host, @ring_server_port)
123
+ @log.debug("Attempting to find ring server on : druby://#{@ring_server_host}:#{@ring_server_port}")
124
+ ring_server = Rinda::RingFinger.new(@ring_server_host, @ring_server_port)
123
125
  ring_server = ring_server.lookup_ring_any
124
- @log.info("Ring server found on : druby://#{@host}:#{@ring_server_port}")
126
+ @log.info("Ring server found on : druby://#{@ring_server_host}:#{@ring_server_port}")
125
127
 
126
128
  # advertise this service on the primary remote tuple space
127
129
  ring_server.write(@tuple, @renewer)
128
130
 
129
131
  # log DRb server uri
130
- @log.info("New tuple registered : druby://#{@host}:#{@ring_server_port}")
132
+ @log.info("New tuple registered : druby://#{@ring_server_host}:#{@ring_server_port}")
131
133
 
132
134
  # wait for explicit stop via ctrl-c
133
135
  DRb.thread.join if __FILE__ == $0
data/lib/watirgrid.rb CHANGED
@@ -13,13 +13,12 @@ module Watir
13
13
  attr_accessor :drb_server_uri, :ring_server, :browsers
14
14
 
15
15
  def initialize(params = {})
16
- @host = params[:interface] || external_interface
16
+ @drb_server_host = params[:drb_server_host] || external_interface
17
17
  @drb_server_port = params[:drb_server_port] || 0
18
+ @ring_server_host = params[:ring_server_host] || external_interface
18
19
  @ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT
19
20
  @renewer = params[:renewer] || Rinda::SimpleRenewer.new
20
21
 
21
- @quantity = params[:quantity]
22
-
23
22
  logfile = params[:logfile] || STDOUT
24
23
  @log = Logger.new(logfile, 'daily')
25
24
  @log.level = params[:loglevel] || Logger::ERROR
@@ -42,7 +41,9 @@ module Watir
42
41
  @browsers.each do |browser|
43
42
  threads << Thread.new do
44
43
  id += 1
45
- yield(browser, id)
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])
46
47
  end
47
48
  end
48
49
  threads.each {|thread| thread.join}
@@ -69,7 +70,8 @@ module Watir
69
70
  ##
70
71
  # Start the DRb Server
71
72
  def start_drb_server
72
- drb_server = DRb.start_service("druby://#{@host}:#{@drb_server_port}")
73
+ drb_server = DRb.start_service(
74
+ "druby://#{@drb_server_host}:#{@drb_server_port}")
73
75
  @drb_server_uri = drb_server.uri
74
76
  @log.info("DRb server started on : #{@drb_server_uri}")
75
77
  end
@@ -77,20 +79,25 @@ module Watir
77
79
  ##
78
80
  # Locate the Rinda Ring Server via a UDP broadcast
79
81
  def find_ring_server
80
- @ring_server = Rinda::RingFinger.new(@host, @ring_server_port)
82
+ @ring_server = Rinda::RingFinger.new(
83
+ @ring_server_host, @ring_server_port)
81
84
  @ring_server = @ring_server.lookup_ring_any
82
- @log.info("Ring server found on : druby://#{@host}:#{@ring_server_port}")
85
+ @log.info("Ring server found on : druby://#{@ring_server_host}:#{@ring_server_port}")
83
86
  end
84
87
 
85
88
  ##
86
89
  # Get all tuple spaces on ringserver
87
90
  def get_tuples(params = {})
88
- quantity = params[:quantity] || -1
91
+ if (params[:quantity].nil? or params[:quantity] == 0) then
92
+ quantity = -1
93
+ else
94
+ quantity = params[:quantity] - 1
95
+ end
89
96
  architecture = params[:architecture] || nil
90
97
  browser_type = params[:browser_type] || nil
91
98
 
92
99
  @browsers = []
93
- services = @ring_server.read_all([
100
+ @tuples = @ring_server.read_all([
94
101
  :name,
95
102
  nil, # watir provider
96
103
  nil, # browser front object
@@ -99,23 +106,26 @@ module Watir
99
106
  architecture,
100
107
  browser_type])
101
108
 
102
- @log.info("Found #{services.size} services.")
103
- if services.size > 0 then
104
- services[1..quantity].each do |service|
105
- hostname = service[4]
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]
106
115
  if params[:hostnames] then
107
116
  if params[:hostnames][hostname] then
108
- @browsers << service[2].new_browser
109
- @ring_server.take(service)if params[:take_all] == true
117
+ @browsers << tuple
118
+ @ring_server.take(tuple)if params[:take_all] == true
110
119
  end
111
120
  else
112
- @browsers << service[2].new_browser
113
- @ring_server.take(service)if params[:take_all] == true
121
+ @browsers << tuple
122
+ @ring_server.take(tuple)if params[:take_all] == true
114
123
  end
115
124
  end
116
125
  else
117
126
  @browsers
118
127
  end
128
+ @browsers
119
129
  end
120
130
  end
121
131
 
data/spec/grid_spec.rb CHANGED
@@ -2,11 +2,13 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe 'WatirGrid' do
4
4
  before(:all) do
5
- controller = Controller.new(:ring_server_port => 12351,
5
+ controller = Controller.new(
6
+ :ring_server_port => 12351,
6
7
  :loglevel => Logger::ERROR)
7
8
  controller.start
8
9
  1.upto(5) do
9
- provider = Provider.new(:ring_server_port => 12351,
10
+ provider = Provider.new(
11
+ :ring_server_port => 12351,
10
12
  :loglevel => Logger::ERROR, :browser_type => 'safari')
11
13
  provider.start
12
14
  end
@@ -15,17 +17,13 @@ describe 'WatirGrid' do
15
17
  it 'should return how many browsers are available in the tuplespace' do
16
18
  browsers = Watir::Grid.new(:ring_server_port => 12351)
17
19
  browsers.start(:read_all => true)
18
- browsers.size.should == 4
20
+ browsers.size.should == 5
19
21
  end
20
22
 
21
23
  it 'should read any 2 browsers in the tuplespace' do
22
24
  browsers = Watir::Grid.new(:ring_server_port => 12351)
23
25
  browsers.start(:quantity => 2, :read_all => true)
24
26
  browsers.size.should == 2
25
- browsers.each do |browser, browser_id|
26
- browser.goto(
27
- "http://localhost:4567/load/#{browser_id}/#{browser.object_id}")
28
- end
29
27
  end
30
28
 
31
29
  it 'should take any 1 browser in the tuplespace' do
@@ -37,7 +35,7 @@ describe 'WatirGrid' do
37
35
  it 'should take all browsers remaining in tuplespace' do
38
36
  browsers = Watir::Grid.new(:ring_server_port => 12351)
39
37
  browsers.start(:take_all => true)
40
- browsers.size.should == 3
38
+ browsers.size.should == 4
41
39
  end
42
40
 
43
41
  it 'should find no more browsers in the tuplespace' do
@@ -46,8 +44,8 @@ describe 'WatirGrid' do
46
44
  browsers.size.should == 0
47
45
  end
48
46
 
49
- it 'should register 3 new browsers in the tuplespace' do
50
- 1.upto(3) do
47
+ it 'should register 4 new browsers in the tuplespace' do
48
+ 1.upto(4) do
51
49
  provider = Provider.new(:ring_server_port => 12351,
52
50
  :loglevel => Logger::ERROR, :browser_type => 'safari')
53
51
  provider.start
@@ -90,10 +88,12 @@ describe 'WatirGrid' do
90
88
  end
91
89
 
92
90
  it 'should take any 1 browser based on specific hostname' do
91
+ hostname = `hostname`.strip
93
92
  browsers = Watir::Grid.new(:ring_server_port => 12351)
94
93
  browsers.start(:quantity => 1,
95
- :take_all => true, :hostnames => {
96
- "90kts.local" => "127.0.0.1"})
94
+ :take_all => true,
95
+ :hostnames => { hostname => "127.0.0.1"}
96
+ )
97
97
  browsers.size.should == 1
98
98
  end
99
99
 
@@ -105,6 +105,21 @@ describe 'WatirGrid' do
105
105
  browsers.size.should == 0
106
106
  end
107
107
 
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}")
119
+ end
120
+ browsers.size.should == 1
121
+ end
122
+
108
123
  it 'should find no more browsers in the tuplespace' do
109
124
  browsers = Watir::Grid.new(:ring_server_port => 12351)
110
125
  browsers.start(:read_all => true)
@@ -9,14 +9,17 @@ describe Controller do
9
9
  end
10
10
 
11
11
  it 'should start a DRb and Ring Server on a specified interface' do
12
- controller = Controller.new(:interface => '127.0.0.1')
12
+ controller = Controller.new(
13
+ :drb_server_host => '127.0.0.1',
14
+ :ring_server_host => '127.0.0.1')
13
15
  controller.start
14
16
  controller.drb_server_uri.should =~ /druby/
15
17
  controller.stop
16
18
  end
17
19
 
18
20
  it 'should start a DRb and Ring Server on specified ports' do
19
- controller = Controller.new(:drb_server_port => 11235,
21
+ controller = Controller.new(
22
+ :drb_server_port => 11235,
20
23
  :ring_server_port => 12358)
21
24
  controller.start
22
25
  controller.drb_server_uri.should =~ /druby/
@@ -26,12 +29,18 @@ end
26
29
 
27
30
  describe Provider do
28
31
  before(:all) do
29
- @controller = Controller.new(:ring_server_port => 12350)
32
+ @controller = Controller.new(
33
+ :drb_server_host => '127.0.0.1',
34
+ :ring_server_host => '127.0.0.1',
35
+ :ring_server_port => 12350)
30
36
  @controller.start
31
37
  end
32
38
 
33
39
  it 'should register a new provider on a specified port' do
34
- provider = Provider.new(:ring_server_port => 12350)
40
+ provider = Provider.new(
41
+ :drb_server_host => '127.0.0.1',
42
+ :ring_server_host => '127.0.0.1',
43
+ :ring_server_port => 12350)
35
44
  provider.start
36
45
  end
37
46
 
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Koopmans
@@ -35,13 +35,15 @@ extra_rdoc_files:
35
35
  files:
36
36
  - .document
37
37
  - .gitignore
38
+ - EXAMPLES.rdoc
39
+ - HISTORY.rdoc
38
40
  - LICENSE
39
- - NOTES.txt
40
41
  - README.rdoc
41
42
  - Rakefile
42
- - TODO.txt
43
+ - TODO.rdoc
43
44
  - bin/controller
44
45
  - bin/provider
46
+ - examples/simple.rb
45
47
  - lib/controller.rb
46
48
  - lib/provider.rb
47
49
  - lib/watirgrid.rb
@@ -84,3 +86,4 @@ test_files:
84
86
  - spec/spec_helper.rb
85
87
  - spec/stub.rb
86
88
  - spec/watirgrid_spec.rb
89
+ - examples/simple.rb
data/TODO.txt DELETED
@@ -1,16 +0,0 @@
1
- == Docs
2
- better instructions in general
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
- == Protocol
11
- Support for tcp or http?
12
-
13
- == Tests
14
- How many providers is suitable with druby
15
- Comparison in performance with proxied objects (DRbUndumped) vs. copied objects
16
-