watirgrid 0.0.7 → 0.0.8.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/.gitignore +22 -22
- data/EXAMPLES.rdoc +131 -131
- data/HISTORY.rdoc +18 -18
- data/LICENSE +20 -20
- data/README.rdoc +82 -82
- data/Rakefile +44 -45
- data/bin/controller +59 -59
- data/bin/provider +63 -63
- data/examples/find_by_uuid.rb +28 -28
- data/examples/google.rb +18 -18
- data/examples/info.rb +13 -13
- data/examples/restart_firefox.rb +13 -13
- data/examples/simple.rb +18 -18
- data/lib/controller.rb +104 -104
- data/lib/provider.rb +228 -242
- data/lib/watirgrid.rb +167 -167
- data/spec/grid_spec.rb +148 -148
- data/spec/spec.opts +1 -1
- data/spec/spec_helper.rb +9 -9
- data/spec/stub.rb +48 -48
- data/spec/tuples_spec.rb +46 -46
- data/spec/utilities_spec.rb +50 -50
- data/spec/watir_spec.rb +59 -0
- data/spec/watirgrid_spec.rb +51 -51
- data/spec/webdriver_spec.rb +59 -0
- data/watirgrid.gemspec +32 -13
- metadata +36 -21
data/lib/provider.rb
CHANGED
@@ -1,242 +1,228 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# provider.rb
|
3
|
-
# Rinda Ring Provider
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
require 'rinda/ring'
|
7
|
-
require 'rinda/tuplespace'
|
8
|
-
require 'logger'
|
9
|
-
require 'drb/acl'
|
10
|
-
require 'uuid'
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
when /
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
@
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
private
|
230
|
-
|
231
|
-
##
|
232
|
-
# Get the external facing interface for this server
|
233
|
-
def external_interface
|
234
|
-
begin
|
235
|
-
UDPSocket.open {|s| s.connect('ping.watirgrid.com', 1); s.addr.last }
|
236
|
-
rescue
|
237
|
-
'127.0.0.1'
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
end
|
242
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# provider.rb
|
3
|
+
# Rinda Ring Provider
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'rinda/ring'
|
7
|
+
require 'rinda/tuplespace'
|
8
|
+
require 'logger'
|
9
|
+
require 'drb/acl'
|
10
|
+
require 'uuid'
|
11
|
+
|
12
|
+
module Watir
|
13
|
+
|
14
|
+
##
|
15
|
+
# Extend Watir with a Provider class
|
16
|
+
# to determine which browser type is supported by the
|
17
|
+
# remote DRb process. This returns the DRb front object.
|
18
|
+
class Provider
|
19
|
+
|
20
|
+
include DRbUndumped # all objects will be proxied, not copied
|
21
|
+
|
22
|
+
attr_reader :browser
|
23
|
+
|
24
|
+
def initialize(browser = nil)
|
25
|
+
browser = (browser || 'tmp').downcase.to_sym
|
26
|
+
case browser
|
27
|
+
when :safari
|
28
|
+
require 'safariwatir'
|
29
|
+
@browser = Watir::Safari
|
30
|
+
when :firefox
|
31
|
+
require 'firewatir'
|
32
|
+
@browser = FireWatir::Firefox
|
33
|
+
when :ie
|
34
|
+
require 'watir'
|
35
|
+
@browser = Watir::IE
|
36
|
+
when :webdriver
|
37
|
+
require 'watir-webdriver'
|
38
|
+
@browser = Watir::Browser
|
39
|
+
else
|
40
|
+
@browser = find_supported_browser
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
#~ def find_supported_browser
|
45
|
+
#~ if Watir::IE then return Watir::IE end
|
46
|
+
#~ if FireWatir::Firefox then return FireWatir::Firefox end
|
47
|
+
#~ if Watir::Safari then return Watir::Safari end
|
48
|
+
#~ end
|
49
|
+
|
50
|
+
def new_browser(webdriver_browser_type = nil)
|
51
|
+
@browser.new(webdriver_browser_type)
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Get a list of running browsers (optionally specified by browser)
|
56
|
+
# 'iexplore','firefox','firefox-bin','chrome','safari','opera'
|
57
|
+
def get_running_browsers(browser=nil)
|
58
|
+
browsers = browser || \
|
59
|
+
['iexplore','firefox','firefox-bin','chrome','safari','opera']
|
60
|
+
case Config::CONFIG['arch']
|
61
|
+
when /mswin/
|
62
|
+
%x[tasklist].split(/\s+/).collect { |x| x[/\w+/]} \
|
63
|
+
& browsers.collect { |x| x.downcase }
|
64
|
+
when /linux|darwin/
|
65
|
+
%x[ps -A | grep -v ruby].split(/\/|\s+/).collect { |x| x.downcase} \
|
66
|
+
& browsers
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_running_processes
|
71
|
+
%x[ps -A | grep -v ruby].split(/\/|\s+/).collect.uniq
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Kill any browser running
|
76
|
+
def kill_all_browsers
|
77
|
+
case Config::CONFIG['arch']
|
78
|
+
when /mswin/
|
79
|
+
browsers = ['iexplore.exe', 'firefox.exe', 'chrome.exe']
|
80
|
+
browsers.each { |browser| %x[taskkill /F /IM #{browser}] }
|
81
|
+
when /linux/
|
82
|
+
browsers = ['firefox', 'chrome', 'opera']
|
83
|
+
browsers.each { |browser| %x[killall -r #{browser}] }
|
84
|
+
when /darwin/
|
85
|
+
browsers = ['firefox-bin', 'Chrome', 'Safari']
|
86
|
+
browsers.each { |browser| %x[killall -m #{browser}] }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Kill all browsers specified by browser name
|
92
|
+
# Windows: 'iexplore.exe', 'firefox.exe', 'chrome.exe'
|
93
|
+
# Linux: 'firefox', 'chrome', 'opera'
|
94
|
+
# OSX: 'firefox-bin', 'Chrome', 'Safari'
|
95
|
+
def kill_browser(browser)
|
96
|
+
case Config::CONFIG['arch']
|
97
|
+
when /mswin/
|
98
|
+
%x[taskkill /F /IM #{browser}]
|
99
|
+
when /linux/
|
100
|
+
%x[killall -r #{browser}]
|
101
|
+
when /darwin/
|
102
|
+
%x[killall -m #{browser}]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Start firefox (with an optional bin path) using the -jssh extension
|
108
|
+
def start_firefox_jssh(path=nil)
|
109
|
+
case Config::CONFIG['arch']
|
110
|
+
when /mswin/
|
111
|
+
bin = path || "C:/Program Files/Mozilla Firefox/firefox.exe"
|
112
|
+
when /linux/
|
113
|
+
bin = path || "/usr/bin/firefox"
|
114
|
+
when /darwin/
|
115
|
+
bin = path || "/Applications/Firefox.app/Contents/MacOS/firefox-bin"
|
116
|
+
end
|
117
|
+
# fork off and die!
|
118
|
+
Thread.new {system(bin, "about:blank", "-jssh")}
|
119
|
+
end
|
120
|
+
|
121
|
+
##
|
122
|
+
# Get the logged-in user
|
123
|
+
def get_logged_in_user
|
124
|
+
%x[whoami].chomp
|
125
|
+
end
|
126
|
+
|
127
|
+
##
|
128
|
+
# Grep for a process (Linux/OSX-with-port only)
|
129
|
+
def process_grep(pattern)
|
130
|
+
%x[pgrep -l #{pattern}].split(/\n/)
|
131
|
+
end
|
132
|
+
|
133
|
+
def renew_provider
|
134
|
+
self.class.superclass
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
class Provider
|
142
|
+
|
143
|
+
attr_accessor :drb_server_uri, :ring_server_uri
|
144
|
+
|
145
|
+
def initialize(params = {})
|
146
|
+
@drb_server_host = params[:drb_server_host] || external_interface
|
147
|
+
@drb_server_port = params[:drb_server_port] || 0
|
148
|
+
@ring_server_host = params[:ring_server_host] || external_interface
|
149
|
+
@ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT
|
150
|
+
|
151
|
+
@renewer = params[:renewer] || Rinda::SimpleRenewer.new
|
152
|
+
@browser_type = params[:browser_type] || nil
|
153
|
+
|
154
|
+
logfile = params[:logfile] || STDOUT
|
155
|
+
@log = Logger.new(logfile, 'daily')
|
156
|
+
@log.level = params[:loglevel] || Logger::INFO
|
157
|
+
@log.datetime_format = "%Y-%m-%d %H:%M:%S "
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
##
|
162
|
+
# Start providing watir objects on the ring server
|
163
|
+
def start
|
164
|
+
# create a DRb 'front' object
|
165
|
+
watir_provider = Watir::Provider.new(@browser_type)
|
166
|
+
architecture = Config::CONFIG['arch']
|
167
|
+
hostname = ENV['SERVER_NAME'] || %x{hostname}.strip
|
168
|
+
|
169
|
+
# setup the security--remember to call before DRb.start_service()
|
170
|
+
DRb.install_acl(ACL.new(@acls))
|
171
|
+
|
172
|
+
# start the DRb Server
|
173
|
+
drb_server = DRb.start_service(
|
174
|
+
"druby://#{@drb_server_host}:#{@drb_server_port}")
|
175
|
+
|
176
|
+
# obtain DRb Server uri
|
177
|
+
@drb_server_uri = drb_server.uri
|
178
|
+
@log.info("DRb server started on : #{@drb_server_uri}")
|
179
|
+
|
180
|
+
# create a service tuple
|
181
|
+
@tuple = [
|
182
|
+
:WatirGrid,
|
183
|
+
:WatirProvider,
|
184
|
+
watir_provider,
|
185
|
+
'A watir provider',
|
186
|
+
hostname,
|
187
|
+
architecture,
|
188
|
+
@browser_type,
|
189
|
+
UUID.new.generate
|
190
|
+
]
|
191
|
+
|
192
|
+
# locate the Rinda Ring Server via a UDP broadcast
|
193
|
+
@log.debug("Attempting to find ring server on : druby://#{@ring_server_host}:#{@ring_server_port}")
|
194
|
+
ring_server = Rinda::RingFinger.new(@ring_server_host, @ring_server_port)
|
195
|
+
ring_server = ring_server.lookup_ring_any
|
196
|
+
@log.info("Ring server found on : druby://#{@ring_server_host}:#{@ring_server_port}")
|
197
|
+
|
198
|
+
# advertise this service on the primary remote tuple space
|
199
|
+
ring_server.write(@tuple, @renewer)
|
200
|
+
|
201
|
+
# log DRb server uri
|
202
|
+
@log.info("New tuple registered : druby://#{@ring_server_host}:#{@ring_server_port}")
|
203
|
+
|
204
|
+
# wait for explicit stop via ctrl-c
|
205
|
+
DRb.thread.join if __FILE__ == $0
|
206
|
+
end
|
207
|
+
|
208
|
+
##
|
209
|
+
# Stop the provider by shutting down the DRb service
|
210
|
+
def stop
|
211
|
+
DRb.stop_service
|
212
|
+
@log.info("DRb server stopped on : #{@drb_server_uri}")
|
213
|
+
end
|
214
|
+
|
215
|
+
private
|
216
|
+
|
217
|
+
##
|
218
|
+
# Get the external facing interface for this server
|
219
|
+
def external_interface
|
220
|
+
begin
|
221
|
+
UDPSocket.open {|s| s.connect('ping.watirgrid.com', 1); s.addr.last }
|
222
|
+
rescue
|
223
|
+
'127.0.0.1'
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|