celerity 0.9.0 → 0.9.1
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/.document +5 -0
- data/.gitignore +9 -0
- data/.gitmodules +3 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/LICENSE +253 -596
- data/README.rdoc +8 -4
- data/Rakefile +5 -1
- data/benchmark/bm_2000_spans.rb +48 -0
- data/benchmark/bm_digg.rb +26 -0
- data/benchmark/bm_google_images.rb +36 -0
- data/benchmark/bm_input_locator.rb +69 -0
- data/benchmark/bm_text_input.rb +19 -0
- data/benchmark/loader.rb +14 -0
- data/celerity.gemspec +18 -114
- data/lib/celerity.rb +1 -3
- data/lib/celerity/htmlunit/commons-lang3-3.0.1.jar +0 -0
- data/lib/celerity/htmlunit/cssparser-0.9.6-20110829.205617-3.jar +0 -0
- data/lib/celerity/htmlunit/{htmlunit-2.9.jar → htmlunit-2.10-SNAPSHOT.jar} +0 -0
- data/lib/celerity/version.rb +1 -1
- data/spec/browser_authentication_spec.rb +16 -0
- data/spec/browser_spec.rb +428 -0
- data/spec/button_spec.rb +24 -0
- data/spec/clickable_element_spec.rb +39 -0
- data/spec/default_viewer_spec.rb +23 -0
- data/spec/element_spec.rb +77 -0
- data/spec/filefield_spec.rb +18 -0
- data/spec/htmlunit_spec.rb +63 -0
- data/spec/implementation.rb +7 -0
- data/spec/index_offset_spec.rb +24 -0
- data/spec/link_spec.rb +16 -0
- data/spec/listener_spec.rb +142 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/table_spec.rb +41 -0
- data/spec/watir_compatibility_spec.rb +32 -0
- data/tasks/snapshot.rake +1 -1
- data/website/benchmarks.html +237 -0
- data/website/css/color.css +153 -0
- data/website/css/hacks.css +3 -0
- data/website/css/layout.css +179 -0
- data/website/css/screen.css +5 -0
- data/website/css/textmate.css +226 -0
- data/website/css/typography.css +72 -0
- data/website/gfx/body_bg.gif +0 -0
- data/website/gfx/button_bg.jpg +0 -0
- data/website/gfx/header_bg.jpg +0 -0
- data/website/gfx/header_left.jpg +0 -0
- data/website/gfx/header_right.jpg +0 -0
- data/website/gfx/nav_bg.jpg +0 -0
- data/website/index.html +125 -0
- data/website/yard/index.html +1 -0
- metadata +69 -22
- data/VERSION.yml +0 -5
- data/lib/celerity/htmlunit/commons-lang-2.6.jar +0 -0
- data/lib/celerity/htmlunit/cssparser-0.9.5.jar +0 -0
- data/tasks/jeweler.rake +0 -28
@@ -0,0 +1,428 @@
|
|
1
|
+
require File.expand_path("../watirspec/spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe "Browser" do
|
4
|
+
describe "#new" do
|
5
|
+
it "raises TypeError if argument is not a Hash" do
|
6
|
+
lambda { Browser.new(:foo) }.should raise_error(TypeError)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "raises ArgumentError if given bad arguments for :render key" do
|
10
|
+
lambda { Browser.new(:render => :foo) }.should raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "raises ArgumentError if given bad arguments for :browser key" do
|
14
|
+
lambda { Browser.new(:browser => 'foo') }.should raise_error(ArgumentError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "raises ArgumentError if given an unknown option" do
|
18
|
+
lambda { Browser.new(:foo => 1) }.should raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should hold the init options" do
|
22
|
+
browser.options.should == WatirSpec.implementation.browser_args.first
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should use the specified proxy" do
|
26
|
+
# TODO: find a better way to test this with rack
|
27
|
+
require 'webrick/httpproxy'
|
28
|
+
|
29
|
+
received = false
|
30
|
+
blk = lambda { received = true }
|
31
|
+
port = WatirSpec::Server.find_free_port_above(2001)
|
32
|
+
|
33
|
+
s = WEBrick::HTTPProxyServer.new(:Port => port,
|
34
|
+
:ProxyContentHandler => blk)
|
35
|
+
Thread.new { s.start }
|
36
|
+
|
37
|
+
opts = WatirSpec.implementation.browser_args.first.merge(:proxy => "localhost:#{port}")
|
38
|
+
|
39
|
+
begin
|
40
|
+
b = Browser.new(opts)
|
41
|
+
b.goto(WatirSpec.host)
|
42
|
+
ensure
|
43
|
+
s.shutdown
|
44
|
+
b.close if b
|
45
|
+
end
|
46
|
+
|
47
|
+
received.should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should use the specified user agent" do
|
51
|
+
opts = WatirSpec.implementation.browser_args.first.merge(:user_agent => "Celerity")
|
52
|
+
|
53
|
+
b = Browser.new(opts)
|
54
|
+
|
55
|
+
begin
|
56
|
+
b.goto(WatirSpec.host + "/header_echo")
|
57
|
+
b.text.should include('"HTTP_USER_AGENT"=>"Celerity"')
|
58
|
+
ensure
|
59
|
+
b.close
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "does not try to find a viewer if created with :viewer => false" do
|
64
|
+
ViewerConnection.should_not_receive(:create)
|
65
|
+
|
66
|
+
Browser.new(:viewer => false).close
|
67
|
+
end
|
68
|
+
|
69
|
+
it "tries to find a viewer if created with :viewer => nil" do
|
70
|
+
ViewerConnection.should_receive(:create).with("127.0.0.1", 6429)
|
71
|
+
|
72
|
+
Browser.new(:viewer => nil).close
|
73
|
+
end
|
74
|
+
|
75
|
+
it "tries to find a viewer on the specified host/port with :viewer => String" do
|
76
|
+
ViewerConnection.should_receive(:create).with("localhost", 1234)
|
77
|
+
|
78
|
+
Browser.new(:viewer => "localhost:1234").close
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should use the specified cache limit" do
|
82
|
+
opts = WatirSpec.implementation.browser_args.first.merge(:cache_limit => 100)
|
83
|
+
b = Browser.new(opts)
|
84
|
+
|
85
|
+
begin
|
86
|
+
b.cache_limit.should == 100
|
87
|
+
ensure
|
88
|
+
b.close
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should use the Firefox 3 browser version when specified" do
|
93
|
+
Browser.new(:browser => :firefox).webclient.browser_version.nickname.should == "FF3"
|
94
|
+
Browser.new(:browser => :firefox3).webclient.browser_version.nickname.should == "FF3"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should use the Firefox 3.6 browser version when specified" do
|
98
|
+
Browser.new(:browser => :firefox_3_6).webclient.browser_version.nickname.should == "FF3.6"
|
99
|
+
Browser.new(:browser => :ff36).webclient.browser_version.nickname.should == "FF3.6"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should use the Internet Explorer 7 browser version when specified" do
|
103
|
+
Browser.new(:browser => :internet_explorer).webclient.browser_version.nickname.should == "IE7"
|
104
|
+
Browser.new(:browser => :internet_explorer7).webclient.browser_version.nickname.should == "IE7"
|
105
|
+
Browser.new(:browser => :internet_explorer_7).webclient.browser_version.nickname.should == "IE7"
|
106
|
+
Browser.new(:browser => :ie).webclient.browser_version.nickname.should == "IE7"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should use the Internet Explorer 8 browser version when specified" do
|
110
|
+
Browser.new(:browser => :internet_explorer_8).webclient.browser_version.nickname.should == "IE8"
|
111
|
+
Browser.new(:browser => :ie8).webclient.browser_version.nickname.should == "IE8"
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should turn off CSS" do
|
115
|
+
b = Browser.new(:css => false)
|
116
|
+
b.css.should be_false
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#html" do
|
122
|
+
%w(shift_jis iso-2022-jp euc-jp).each do |charset|
|
123
|
+
it "returns decoded #{charset.upcase} when :charset specified" do
|
124
|
+
opts = WatirSpec.implementation.browser_args.first.merge(:charset => charset.upcase)
|
125
|
+
browser = Browser.new(opts)
|
126
|
+
|
127
|
+
begin
|
128
|
+
browser.goto(WatirSpec.files + "/#{charset}_text.html")
|
129
|
+
# Browser#text is automagically transcoded into the right charset, but Browser#html isn't.
|
130
|
+
browser.html.should =~ /本日は晴天なり。/
|
131
|
+
ensure
|
132
|
+
browser.close
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
it "does not fail for huge pages" do
|
138
|
+
browser.goto WatirSpec.host + "/big"
|
139
|
+
browser.html.should include("hello</body>")
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "#text" do
|
144
|
+
it "does not fail for huge pages" do
|
145
|
+
browser.goto WatirSpec.host + "/big"
|
146
|
+
browser.text.should include("hello")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "#response_headers" do
|
151
|
+
it "returns the response headers (as a hash)" do
|
152
|
+
browser.goto(WatirSpec.host + "/non_control_elements.html")
|
153
|
+
browser.response_headers.should be_kind_of(Hash)
|
154
|
+
browser.response_headers['Date'].should be_kind_of(String)
|
155
|
+
browser.response_headers['Content-Type'].should be_kind_of(String)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "#content_type" do
|
160
|
+
it "returns the content type" do
|
161
|
+
browser.goto(WatirSpec.host + "/non_control_elements.html")
|
162
|
+
browser.content_type.should =~ /\w+\/\w+/
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "#io" do
|
167
|
+
it "returns the io object of the content" do
|
168
|
+
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
169
|
+
browser.io.should be_kind_of(IO)
|
170
|
+
browser.io.read.should == File.read("#{WatirSpec.html}/non_control_elements.html")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "#goto" do
|
175
|
+
it "raises UnexpectedPageException if the content type is not understood" do
|
176
|
+
lambda { browser.goto(WatirSpec.host + "/octet_stream") }.should raise_error(UnexpectedPageException)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "takes a 2nd argument of headers" do
|
180
|
+
browser.goto(WatirSpec.host + "/header_echo", {'Accept-Language'=>'fr','Accept'=>'application/json'})
|
181
|
+
browser.text.should include('"HTTP_ACCEPT"=>"application/json"')
|
182
|
+
browser.text.should include('"HTTP_ACCEPT_LANGUAGE"=>"fr"')
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "#cookies" do
|
187
|
+
it "returns set cookies as a Ruby hash" do
|
188
|
+
browser = WatirSpec.new_browser
|
189
|
+
begin
|
190
|
+
browser.cookies.should == {}
|
191
|
+
|
192
|
+
browser.goto(WatirSpec.host + "/set_cookie")
|
193
|
+
|
194
|
+
cookies = browser.cookies
|
195
|
+
cookies.size.should == 1
|
196
|
+
cookies[WatirSpec::Server.bind]['monster'].should == "/"
|
197
|
+
ensure
|
198
|
+
browser.close
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe "#clear_cookies" do
|
204
|
+
it "clears all cookies" do
|
205
|
+
b = WatirSpec.new_browser
|
206
|
+
|
207
|
+
begin
|
208
|
+
b.cookies.should be_empty
|
209
|
+
|
210
|
+
b.goto(WatirSpec.host + "/set_cookie")
|
211
|
+
b.cookies.size.should == 1
|
212
|
+
b.clear_cookies
|
213
|
+
b.cookies.should be_empty
|
214
|
+
ensure
|
215
|
+
b.close
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "add_cookie" do
|
221
|
+
it "adds a cookie with the given domain, name and value" do
|
222
|
+
begin
|
223
|
+
browser.add_cookie("example.com", "foo", "bar")
|
224
|
+
cookies = browser.cookies
|
225
|
+
cookies.should be_instance_of(Hash)
|
226
|
+
cookies.should have_key('example.com')
|
227
|
+
cookies['example.com']['foo'].should == 'bar'
|
228
|
+
ensure
|
229
|
+
browser.clear_cookies
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
it "adds a cookie with the specified options" do
|
234
|
+
begin
|
235
|
+
browser.add_cookie("example.com", "foo", "bar", :path => "/foobar", :expires => Time.now + 100000)
|
236
|
+
cookies = browser.cookies
|
237
|
+
cookies.should be_instance_of(Hash)
|
238
|
+
cookies['example.com']['foo'].should == 'bar'
|
239
|
+
ensure
|
240
|
+
browser.clear_cookies
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "remove_cookie" do
|
246
|
+
it "removes the cookie for the given domain and name" do
|
247
|
+
b = WatirSpec.new_browser
|
248
|
+
begin
|
249
|
+
b.goto(WatirSpec.host + "/set_cookie")
|
250
|
+
|
251
|
+
b.remove_cookie(WatirSpec::Server.bind, "monster")
|
252
|
+
b.cookies.should be_empty
|
253
|
+
ensure
|
254
|
+
b.close
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
it "raises an error if no such cookie exists" do
|
259
|
+
lambda { browser.remove_cookie("bogus.com", "bar") }.should raise_error(CookieNotFoundError)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe "#wait" do
|
264
|
+
it "should wait for javascript timers to finish" do
|
265
|
+
alerts = 0
|
266
|
+
browser.add_listener(:alert) { alerts += 1 }
|
267
|
+
browser.goto(WatirSpec.files + "/timeout.html")
|
268
|
+
browser.div(:id, 'alert').click
|
269
|
+
browser.wait.should be_true
|
270
|
+
alerts.should == 1
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should pass the correct args to webclient" do
|
274
|
+
browser.webclient.should_receive(:waitForBackgroundJavaScript).with(10000)
|
275
|
+
browser.wait
|
276
|
+
|
277
|
+
browser.webclient.should_receive(:waitForBackgroundJavaScript).with(3000)
|
278
|
+
browser.wait(3)
|
279
|
+
end
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
describe "#wait_while" do
|
284
|
+
it "waits until the specified condition becomes false" do
|
285
|
+
browser.goto(WatirSpec.files + "/timeout.html")
|
286
|
+
browser.div(:id, "change").click
|
287
|
+
browser.wait_while { browser.contains_text("Trigger change") }
|
288
|
+
browser.div(:id, "change").text.should == "all done"
|
289
|
+
end
|
290
|
+
|
291
|
+
it "returns the value returned from the block" do
|
292
|
+
browser.wait_while { false }.should == false
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
describe "#wait_until" do
|
297
|
+
it "waits until the condition becomes true" do
|
298
|
+
browser.goto(WatirSpec.files + "/timeout.html")
|
299
|
+
browser.div(:id, "change").click
|
300
|
+
browser.wait_until { browser.contains_text("all done") }
|
301
|
+
end
|
302
|
+
|
303
|
+
it "returns the value returned from the block" do
|
304
|
+
browser.wait_until { true }.should == true
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
describe "#element_by_xpath" do
|
309
|
+
it "returns usable elements even though they're not supported" do
|
310
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
311
|
+
|
312
|
+
el = browser.element_by_xpath("//link")
|
313
|
+
el.should be_instance_of(Celerity::Element)
|
314
|
+
el.should be_kind_of(Celerity::ClickableElement)
|
315
|
+
el.rel.should == "stylesheet"
|
316
|
+
end
|
317
|
+
|
318
|
+
it "includes the xpath in an exception message" do
|
319
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
320
|
+
|
321
|
+
the_xpath = "//div[contains(@class, 'this does not exist')]"
|
322
|
+
el = browser.element_by_xpath(the_xpath)
|
323
|
+
|
324
|
+
lambda { el.visible? }.should raise_error(
|
325
|
+
Celerity::Exception::UnknownObjectException, Regexp.new(Regexp.escape(the_xpath)))
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
describe "#focused_element" do
|
330
|
+
it "returns the element that currently has the focus" do
|
331
|
+
b = WatirSpec.new_browser
|
332
|
+
b.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
333
|
+
b.focused_element.id.should == "new_user_first_name"
|
334
|
+
|
335
|
+
b.close
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
describe "#status_code" do
|
340
|
+
it "returns the status code of the last request" do
|
341
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
342
|
+
browser.status_code.should == 200
|
343
|
+
|
344
|
+
browser.goto(WatirSpec.host + "/doesnt_exist")
|
345
|
+
browser.status_code.should == 404
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
describe "#status_code_exceptions" do
|
350
|
+
it "raises status code exceptions if set to true" do
|
351
|
+
browser.status_code_exceptions = true
|
352
|
+
lambda do
|
353
|
+
browser.goto(WatirSpec.host + "/doesnt_exist")
|
354
|
+
end.should raise_error(NavigationException)
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
describe "#javascript_exceptions" do
|
359
|
+
it "raises javascript exceptions if set to true" do
|
360
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
361
|
+
browser.javascript_exceptions = true
|
362
|
+
lambda do
|
363
|
+
browser.execute_script("no_such_function()")
|
364
|
+
end.should raise_error
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
describe "#add_listener" do
|
369
|
+
it "should click OK for confirm() calls" do
|
370
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
371
|
+
browser.add_listener(:confirm) { }
|
372
|
+
browser.execute_script("confirm()").should == true
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
describe "#remove_listener" do
|
377
|
+
it "should remove the given listener Proc" do
|
378
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
379
|
+
|
380
|
+
called = false
|
381
|
+
listener = lambda { called = true }
|
382
|
+
|
383
|
+
browser.add_listener(:alert, &listener)
|
384
|
+
browser.execute_script("alert('foo')")
|
385
|
+
called.should be_true
|
386
|
+
|
387
|
+
called = false
|
388
|
+
browser.remove_listener(:alert, listener)
|
389
|
+
browser.execute_script("alert('foo')")
|
390
|
+
called.should be_false
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
describe "#add_checker" do
|
395
|
+
|
396
|
+
# watir only supports a lambda instance as argument, celerity supports both
|
397
|
+
it "runs the given block on each page load" do
|
398
|
+
output = ''
|
399
|
+
|
400
|
+
browser.add_checker { |browser| output << browser.text }
|
401
|
+
browser.goto(WatirSpec.files + "/non_control_elements.html")
|
402
|
+
|
403
|
+
output.should include('Dubito, ergo cogito, ergo sum')
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
|
408
|
+
describe "#confirm" do
|
409
|
+
it "clicks 'OK' for a confirm() call" do
|
410
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
411
|
+
|
412
|
+
browser.confirm(true) do
|
413
|
+
browser.execute_script('confirm()').should be_true
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
it "clicks 'cancel' for a confirm() call" do
|
418
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
419
|
+
|
420
|
+
browser.confirm(false) do
|
421
|
+
browser.execute_script('confirm()').should be_false
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
|
427
|
+
|
428
|
+
end
|
data/spec/button_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path("../watirspec/spec_helper", __FILE__)
|
2
|
+
|
3
|
+
describe "Button" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#click_and_attach" do
|
10
|
+
it "returns a new browser instance with the popup page" do
|
11
|
+
b = browser.button(:name, 'new_popup_window').click_and_attach
|
12
|
+
b.should_not == browser
|
13
|
+
b.title.should == "Tables"
|
14
|
+
browser.title.should == "Forms with input elements"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns a new browser with same log_level as original" do
|
18
|
+
b = browser.button(:name, 'new_popup_window').click_and_attach
|
19
|
+
b.should_not == browser
|
20
|
+
b.log_level.should == browser.log_level
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|