polonium 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/CHANGES +1 -0
  2. data/Rakefile +1 -1
  3. data/lib/polonium/adapters/rspec.rb +21 -0
  4. data/lib/polonium/{extensions/testrunnermediator.rb → adapters/test_unit.rb} +1 -1
  5. data/lib/polonium/configuration.rb +35 -33
  6. data/lib/polonium/dsl/selenium_dsl.rb +6 -3
  7. data/lib/polonium/dsl/test_unit_dsl.rb +4 -1
  8. data/lib/polonium/element.rb +13 -12
  9. data/lib/polonium/page.rb +14 -4
  10. data/lib/polonium/test_case.rb +3 -37
  11. data/lib/polonium/values_match.rb +9 -0
  12. data/lib/polonium.rb +6 -1
  13. data/spec/main_spec_suite.rb +11 -0
  14. data/spec/polonium/{selenium_configuration_spec.rb → configuration_spec.rb} +0 -0
  15. data/spec/polonium/{selenium_driver_spec.rb → driver_spec.rb} +0 -0
  16. data/spec/polonium/element_spec.rb +601 -0
  17. data/spec/polonium/{selenium_page_spec.rb → page_spec.rb} +95 -60
  18. data/spec/polonium/{selenium_server_runner_spec.rb → server_runner_spec.rb} +0 -0
  19. data/spec/polonium/test_case_class_method_spec.rb +14 -0
  20. data/spec/polonium/{selenium_test_case_spec.rb → test_case_spec.rb} +16 -7
  21. data/spec/polonium/{selenium_test_case_spec_helper.rb → test_case_spec_helper.rb} +1 -1
  22. data/spec/polonium/values_match_spec.rb +30 -0
  23. data/spec/rspec/options_spec.rb +30 -0
  24. data/spec/rspec/rspec_spec_helper.rb +1 -0
  25. data/spec/rspec_spec_suite.rb +11 -0
  26. data/spec/spec_helper.rb +2 -2
  27. data/spec/spec_suite.rb +17 -4
  28. data/spec/test_unit/test_unit_spec_helper.rb +1 -0
  29. data/spec/{polonium/extensions → test_unit}/testrunnermediator_spec.rb +1 -1
  30. data/spec/test_unit_spec_suite.rb +11 -0
  31. metadata +21 -12
  32. data/spec/polonium/selenium_element_spec.rb +0 -551
  33. data/spec/polonium/selenium_test_case_class_method_spec.rb +0 -41
@@ -0,0 +1,601 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ module Polonium
4
+ describe Element do
5
+ it_should_behave_like "Selenium"
6
+ include TestCaseSpecHelper
7
+ attr_reader :driver, :element, :element_locator
8
+
9
+ before do
10
+ @driver = ::Polonium::Driver.new('http://test.host', 4000, "*firefox", 'http://test.host')
11
+ @element_locator ||= "id=foobar"
12
+ @element = Element.new(driver, element_locator)
13
+ end
14
+
15
+ describe "#initialize" do
16
+ it "sets the locator" do
17
+ element.locator.should == element_locator
18
+ end
19
+
20
+ it "sets the selenium object" do
21
+ element.driver.should == driver
22
+ end
23
+ end
24
+
25
+ describe "#assert_element_present" do
26
+ it "passes when element is present" do
27
+ ticks = [false, false, false, true]
28
+ mock(driver).do_command("isElementPresent", [element_locator]).times(4) do
29
+ result ticks.shift
30
+ end
31
+ element.assert_element_present
32
+ end
33
+
34
+ it "fails when element is not present" do
35
+ stub(driver).is_element_present(element_locator) {false}
36
+ proc do
37
+ element.assert_element_present
38
+ end.should raise_error("Expected element 'id=foobar' to be present, but it was not (after 5 sec)")
39
+ end
40
+ end
41
+
42
+ describe "#is_present?" do
43
+ it "returns true when element is present" do
44
+ mock(driver).is_element_present(element_locator) {true}
45
+ element.is_present?.should be_true
46
+ end
47
+
48
+ it "returns false when element is not present" do
49
+ mock(driver).is_element_present(element_locator) {false}
50
+ element.is_present?.should be_false
51
+ end
52
+ end
53
+
54
+ describe "#contains?" do
55
+ describe "when passed a String" do
56
+ it "returns true when inner html does contain passed in text" do
57
+ mock(driver).get_inner_html(element_locator) {"hello world"}
58
+ element.contains?("hello").should be_true
59
+ end
60
+
61
+ it "returns false when inner html does not contain passed in text" do
62
+ mock(driver).get_inner_html(element_locator) {"hello world"}
63
+ element.contains?("goodbye").should be_false
64
+ end
65
+ end
66
+
67
+ describe "when passed a Regexp" do
68
+ it "returns true when inner html does match passed in Regexp" do
69
+ mock(driver).get_inner_html(element_locator) {"hello world"}
70
+ element.contains?(/hello/).should be_true
71
+ end
72
+
73
+ it "returns false when inner html does not match passed in Regexp" do
74
+ mock(driver).get_inner_html(element_locator) {"hello world"}
75
+ element.contains?(/goodbye/).should be_false
76
+ end
77
+ end
78
+
79
+ end
80
+
81
+ describe "#assert_element_not_present" do
82
+ it "passes when element is not present" do
83
+ ticks = [true, true, true, false]
84
+ mock(driver).is_element_present(element_locator) do
85
+ ticks.shift
86
+ end.times(4)
87
+ element.assert_element_not_present
88
+ end
89
+
90
+ it "fails when element is present" do
91
+ stub(driver).is_element_present(element_locator) {true}
92
+ proc do
93
+ element.assert_element_not_present
94
+ end.should raise_error("Expected element 'id=foobar' to be absent, but it was not (after 5 sec)")
95
+ end
96
+ end
97
+
98
+ describe "#is_not_present?" do
99
+ it "returns true when element is not present" do
100
+ mock(driver).is_element_present(element_locator) {false}
101
+ element.is_not_present?.should be_true
102
+ end
103
+
104
+ it "returns false when element is present" do
105
+ mock(driver).is_element_present(element_locator) {true}
106
+ element.is_not_present?.should be_false
107
+ end
108
+ end
109
+
110
+ describe "#assert_value" do
111
+ it "passes when element is present and value is expected value" do
112
+ element_ticks = [false, false, false, true]
113
+ mock(driver).is_element_present(element_locator) do
114
+ element_ticks.shift
115
+ end.times(4)
116
+ value_ticks = [nil, nil, nil, "joe"]
117
+ mock(driver).get_value(element_locator) do
118
+ value_ticks.shift
119
+ end.times(4)
120
+ element.assert_value("joe")
121
+ end
122
+
123
+ it "fails when element is present and not expected value" do
124
+ mock(driver).is_element_present(element_locator) {true}
125
+ stub(driver).get_value(element_locator) {"jane"}
126
+ proc do
127
+ element.assert_value("joe")
128
+ end.should raise_error(Test::Unit::AssertionFailedError)
129
+ end
130
+
131
+ it "fails when element is not present" do
132
+ stub(driver).is_element_present(element_locator) {false}
133
+ proc do
134
+ element.assert_value("joe")
135
+ end.should raise_error(Test::Unit::AssertionFailedError)
136
+ end
137
+ end
138
+
139
+ describe "#has_value?" do
140
+ it "returns true when value is expected value" do
141
+ mock(driver).get_value(element_locator) {"joe"}
142
+ element.has_value?("joe").should be_true
143
+ end
144
+
145
+ it "returns false when value is not expected value" do
146
+ stub(driver).get_value(element_locator) {"jane"}
147
+ element.has_value?("joe").should be_false
148
+ end
149
+ end
150
+
151
+ describe "#assert_attribute" do
152
+ attr_reader :element_locator
153
+
154
+ before do
155
+ element_locator = "id=foobar"
156
+ end
157
+
158
+ it "passes when element is present and value is expected value" do
159
+ element_ticks = [false, false, false, true]
160
+ mock(driver).is_element_present(element_locator) do
161
+ element_ticks.shift
162
+ end.times(4)
163
+ label_ticks = ["jane", "jane", "jane", "joe"]
164
+ mock(driver).get_attribute("#{element_locator}@theattribute") do
165
+ label_ticks.shift
166
+ end.times(4)
167
+ mock.proxy(element).values_match?.with_any_args.times(4)
168
+
169
+ element.assert_attribute('theattribute', "joe")
170
+ end
171
+
172
+ it "fails when element is present and value is not expected" do
173
+ stub(driver).is_element_present(element_locator) {true}
174
+ stub(driver).get_attribute("#{element_locator}@theattribute") {"jane"}
175
+ mock.proxy(element).values_match?.with_any_args.times(4)
176
+ proc do
177
+ element.assert_attribute('theattribute', "joe")
178
+ end.should raise_error(Test::Unit::AssertionFailedError)
179
+ end
180
+
181
+ it "fails when element is not present" do
182
+ stub(driver).is_element_present(element_locator) {false}
183
+ proc do
184
+ element.assert_attribute('theattribute', "joe")
185
+ end.should raise_error(Test::Unit::AssertionFailedError)
186
+ end
187
+ end
188
+
189
+ describe "#assert_selected" do
190
+ before do
191
+ @element_locator = "id=foobar"
192
+ end
193
+
194
+ it "passes when element is present and value is expected value" do
195
+ element_ticks = [false, false, false, true]
196
+ mock(driver).is_element_present(element_locator) do
197
+ element_ticks.shift
198
+ end.times(4)
199
+ label_ticks = ["jane", "jane", "jane", "joe"]
200
+ mock(driver).get_selected_label(element_locator) do
201
+ label_ticks.shift
202
+ end.times(4)
203
+ mock.proxy(element).values_match?.with_any_args.times(4)
204
+
205
+ element.assert_selected("joe")
206
+ end
207
+
208
+ it "fails when element is present and value is not expected" do
209
+ stub(driver).is_element_present(element_locator) {true}
210
+ stub(driver).get_selected_label(element_locator) {"jane"}
211
+ mock.proxy(element).values_match?.with_any_args.times(4)
212
+
213
+ proc do
214
+ element.assert_selected("joe")
215
+ end.should raise_error(Test::Unit::AssertionFailedError)
216
+ end
217
+
218
+ it "fails when element is not present" do
219
+ stub(driver).is_element_present(element_locator) {false}
220
+ proc do
221
+ element.assert_selected("joe")
222
+ end.should raise_error(Test::Unit::AssertionFailedError)
223
+ end
224
+ end
225
+
226
+ describe "#assert_visible" do
227
+ before do
228
+ @element_locator = "id=foobar"
229
+ end
230
+
231
+ it "passes when element exists and is visible" do
232
+ element_ticks = [false, false, false, true]
233
+ mock(driver).is_element_present(element_locator) do
234
+ element_ticks.shift
235
+ end.times(4)
236
+ visible_ticks = [false, false, false, true]
237
+ mock(driver).is_visible(element_locator) do
238
+ visible_ticks.shift
239
+ end.times(4)
240
+ element.assert_visible
241
+ end
242
+
243
+ it "fails when element is present and is not visible" do
244
+ stub(driver).is_element_present(element_locator) {true}
245
+ stub(driver).is_visible(element_locator) {false}
246
+ proc do
247
+ element.assert_visible
248
+ end.should raise_error(Test::Unit::AssertionFailedError)
249
+ end
250
+
251
+ it "fails when element is not present" do
252
+ stub(driver).is_element_present(element_locator) {false}
253
+ proc do
254
+ element.assert_visible
255
+ end.should raise_error(Test::Unit::AssertionFailedError)
256
+ end
257
+ end
258
+
259
+ describe "#assert_not_visible" do
260
+ before do
261
+ @element_locator = "id=foobar"
262
+ end
263
+
264
+ it "passes when element exists and is not visible" do
265
+ element_ticks = [false, false, false, true]
266
+ mock(driver).is_element_present(element_locator) do
267
+ element_ticks.shift
268
+ end.times(4)
269
+ visible_ticks = [true, true, true, false]
270
+ mock(driver).is_visible(element_locator) do
271
+ visible_ticks.shift
272
+ end.times(4)
273
+ element.assert_not_visible
274
+ end
275
+
276
+ it "fails when element is present and is visible" do
277
+ stub(driver).is_element_present(element_locator) {true}
278
+ stub(driver).is_visible(element_locator) {true}
279
+ proc do
280
+ element.assert_not_visible
281
+ end.should raise_error(Test::Unit::AssertionFailedError)
282
+ end
283
+
284
+ it "fails when element is not present" do
285
+ stub(driver).is_element_present(element_locator) {false}
286
+ proc do
287
+ element.assert_visible
288
+ end.should raise_error(Test::Unit::AssertionFailedError)
289
+ end
290
+ end
291
+
292
+ describe "#assert_checked" do
293
+ before do
294
+ @element_locator = "id=foobar"
295
+ end
296
+
297
+ it "passes when element is present and value is expected value" do
298
+ element_ticks = [false, false, false, true]
299
+ mock(driver).is_element_present(element_locator) do
300
+ element_ticks.shift
301
+ end.times(4)
302
+ checked_ticks = [false, false, false, true]
303
+ mock(driver).is_checked(element_locator) do
304
+ checked_ticks.shift
305
+ end.times(4)
306
+ element.assert_checked
307
+ end
308
+
309
+ it "fails when element is present and value is not expected" do
310
+ stub(driver).is_element_present(element_locator) {true}
311
+ stub(driver).is_checked(element_locator) {false}
312
+ proc do
313
+ element.assert_checked
314
+ end.should raise_error(Test::Unit::AssertionFailedError)
315
+ end
316
+
317
+ it "fails when element is not present" do
318
+ stub(driver).is_element_present(element_locator) {false}
319
+ proc do
320
+ element.assert_checked
321
+ end.should raise_error(Test::Unit::AssertionFailedError)
322
+ end
323
+ end
324
+
325
+ describe "#assert_not_checked" do
326
+ before do
327
+ @element_locator = "id=foobar"
328
+ end
329
+
330
+ it "passes when element is present and value is expected value" do
331
+ element_ticks = [false, false, false, true]
332
+ mock(driver).is_element_present(element_locator) do
333
+ element_ticks.shift
334
+ end.times(4)
335
+ checked_ticks = [true, true, true, false]
336
+ mock(driver).is_checked(element_locator) do
337
+ checked_ticks.shift
338
+ end.times(4)
339
+ element.assert_not_checked
340
+ end
341
+
342
+ it "fails when element is present and value is not expected" do
343
+ stub(driver).is_element_present(element_locator) {true}
344
+ stub(driver).is_checked(element_locator) {true}
345
+ proc do
346
+ element.assert_not_checked
347
+ end.should raise_error(Test::Unit::AssertionFailedError)
348
+ end
349
+
350
+ it "fails when element is not present" do
351
+ stub(driver).is_element_present(element_locator) {false}
352
+ proc do
353
+ element.assert_not_checked
354
+ end.should raise_error(Test::Unit::AssertionFailedError)
355
+ end
356
+ end
357
+
358
+ describe "#assert_text" do
359
+ before do
360
+ @element_locator = "id=foobar"
361
+ end
362
+
363
+ it "passes when element is present and value is expected value" do
364
+ element_ticks = [false, false, false, true]
365
+ mock(driver).is_element_present(element_locator) do
366
+ element_ticks.shift
367
+ end.times(4)
368
+ checked_ticks = ["no match", "no match", "no match", "match"]
369
+ mock(driver).get_text(element_locator) do
370
+ checked_ticks.shift
371
+ end.times(4)
372
+ mock.proxy(element).values_match?.with_any_args.times(4)
373
+
374
+ element.assert_text("match")
375
+ end
376
+
377
+ it "fails when element is present and value is not expected" do
378
+ stub(driver).is_element_present(element_locator) {true}
379
+ stub(driver).get_text(element_locator) {"no match"}
380
+ mock.proxy(element).values_match?.with_any_args.times(4)
381
+
382
+ proc do
383
+ element.assert_text "match"
384
+ end.should raise_error(Test::Unit::AssertionFailedError)
385
+ end
386
+
387
+ it "fails when element is not present" do
388
+ stub(driver).is_element_present(element_locator) {false}
389
+ proc do
390
+ element.assert_text "match"
391
+ end.should raise_error(Test::Unit::AssertionFailedError)
392
+ end
393
+ end
394
+
395
+ describe "#assert_contains" do
396
+ before do
397
+ @element_locator = "id=foobar"
398
+ @evaled_js = "this.page().findElement(\"#{element_locator}\").innerHTML"
399
+ end
400
+
401
+ describe "when passed a String" do
402
+ it "passes when element is present and the element contains text" do
403
+ element_ticks = [false, false, false, true]
404
+ mock(driver).is_element_present(element_locator) do
405
+ element_ticks.shift
406
+ end.times(4)
407
+ inner_html_ticks = ["html", "html", "html", "html match html"]
408
+ mock(driver).get_eval(@evaled_js) do
409
+ inner_html_ticks.shift
410
+ end.times(4)
411
+ element.assert_contains("match")
412
+ end
413
+
414
+ it "fails when element is present and the element does not contain text" do
415
+ stub(driver).is_element_present(element_locator) {true}
416
+ stub(driver).get_eval(@evaled_js) {"html"}
417
+ proc do
418
+ element.assert_contains "this is not contained in the html"
419
+ end.should raise_error(Test::Unit::AssertionFailedError)
420
+ end
421
+ end
422
+
423
+ describe "when passed a Regexp" do
424
+ it "passes when element is present and the element contains text that matches the regexp" do
425
+ element_ticks = [false, false, false, true]
426
+ mock(driver).is_element_present(element_locator) do
427
+ element_ticks.shift
428
+ end.times(4)
429
+ inner_html_ticks = ["html", "html", "html", "html match html"]
430
+ mock(driver).get_eval(@evaled_js) do
431
+ inner_html_ticks.shift
432
+ end.times(4)
433
+ element.assert_contains(/match/)
434
+ end
435
+
436
+ it "fails when element is present and the element does not contain text that matches the regexp" do
437
+ stub(driver).is_element_present(element_locator) {true}
438
+ stub(driver).get_eval(@evaled_js) {"html"}
439
+ proc do
440
+ element.assert_contains /blahblah/
441
+ end.should raise_error(Test::Unit::AssertionFailedError)
442
+ end
443
+ end
444
+
445
+ it "fails when element is not present" do
446
+ stub(driver).is_element_present(element_locator) {false}
447
+ proc do
448
+ element.assert_contains "the element does not exist"
449
+ end.should raise_error(Test::Unit::AssertionFailedError)
450
+ end
451
+
452
+ it "calls assert_contains_in_order when passed an array" do
453
+ element_ticks = [false, false, false, true]
454
+ mock(driver).is_element_present(element_locator) {true}
455
+ mock(driver).get_text(element_locator) {"foo bar baz"}
456
+
457
+ mock.proxy(element).assert_contains_in_order("foo", "bar", "baz")
458
+ element.assert_contains(["foo", "bar", "baz"])
459
+ end
460
+ end
461
+
462
+ describe "#assert_does_not_contain" do
463
+ before do
464
+ @element_locator = "id=foobar"
465
+ @evaled_js = "this.page().findElement(\"#{element_locator}\").innerHTML"
466
+ end
467
+
468
+ describe "when passed a String" do
469
+ it "passes when element is present and the element does not contain text" do
470
+ element_ticks = [false, false, false, true]
471
+ mock(driver).is_element_present(element_locator) do
472
+ element_ticks.shift
473
+ end.times(4)
474
+ inner_html_ticks = ["html match html", "html match html", "html match html", "html"]
475
+ mock(driver).get_eval(@evaled_js) do
476
+ inner_html_ticks.shift
477
+ end.times(4)
478
+ element.assert_does_not_contain("match")
479
+ end
480
+
481
+ it "fails when element is present and the element contains text" do
482
+ stub(driver).is_element_present(element_locator) {true}
483
+ stub(driver).get_eval(@evaled_js) {"html match html"}
484
+ proc do
485
+ element.assert_does_not_contain "match"
486
+ end.should raise_error(Test::Unit::AssertionFailedError)
487
+ end
488
+ end
489
+
490
+ describe "when passed a Regexp" do
491
+ it "passes when element is present and the element does not contain text that matches the Regexp" do
492
+ element_ticks = [false, false, false, true]
493
+ mock(driver).is_element_present(element_locator) do
494
+ element_ticks.shift
495
+ end.times(4)
496
+ inner_html_ticks = ["html match html", "html match html", "html match html", "html"]
497
+ mock(driver).get_eval(@evaled_js) do
498
+ inner_html_ticks.shift
499
+ end.times(4)
500
+ element.assert_does_not_contain(/match/)
501
+ end
502
+
503
+ it "fails when element is present and the element contains text" do
504
+ stub(driver).is_element_present(element_locator) {true}
505
+ stub(driver).get_eval(@evaled_js) {"html match html"}
506
+ proc do
507
+ element.assert_does_not_contain /match/
508
+ end.should raise_error(Test::Unit::AssertionFailedError)
509
+ end
510
+ end
511
+
512
+ it "fails when element is not present" do
513
+ stub(driver).is_element_present(element_locator) {false}
514
+ proc do
515
+ element.assert_does_not_contain "match"
516
+ end.should raise_error(Test::Unit::AssertionFailedError)
517
+ end
518
+ end
519
+
520
+ describe "#assert_next_sibling" do
521
+ before do
522
+ @element_locator = "id=foobar"
523
+ @evaled_js = "this.page().findElement('#{@element_locator}').nextSibling.id"
524
+ end
525
+
526
+ it "passes when element is present and value is expected value" do
527
+ element_ticks = [false, false, false, true]
528
+ mock(driver).is_element_present(@element_locator) do
529
+ element_ticks.shift
530
+ end.times(4)
531
+ inner_html_ticks = ["", "", "", "next_element"]
532
+ mock(driver).get_eval(@evaled_js) do
533
+ inner_html_ticks.shift
534
+ end.times(4)
535
+ element.assert_next_sibling("next_element")
536
+ end
537
+
538
+ it "fails when element is present and value is not expected" do
539
+ stub(driver).is_element_present(@element_locator) {true}
540
+ stub(driver).get_eval(@evaled_js) {""}
541
+ proc do
542
+ element.assert_next_sibling "next_element"
543
+ end.should raise_error(Test::Unit::AssertionFailedError)
544
+ end
545
+
546
+ it "fails when element is not present" do
547
+ stub(driver).is_element_present(@element_locator) {false}
548
+ proc do
549
+ element.assert_next_sibling "match"
550
+ end.should raise_error(Test::Unit::AssertionFailedError)
551
+ end
552
+ end
553
+
554
+ describe "#assert_contains_in_order" do
555
+ before do
556
+ @element_locator = "id=foobar"
557
+ @evaled_js = "this.page().findElement('#{@element_locator}').nextSibling.id"
558
+ end
559
+
560
+ it "passes when element is present and passed in text and Regexp matches are in order" do
561
+ element_ticks = [false, false, false, true]
562
+ mock(driver).is_element_present(@element_locator) do
563
+ element_ticks.shift
564
+ end.times(4)
565
+ get_text_ticks = [
566
+ "no match",
567
+ "no match",
568
+ "no match",
569
+ "one\ntwo\nthree",
570
+ ]
571
+ mock(driver).get_text(@element_locator) do
572
+ get_text_ticks.shift
573
+ end.times(4)
574
+ element.assert_contains_in_order('one', /two/, 'three')
575
+ end
576
+
577
+ it "fails when element is present and value is not expected" do
578
+ stub(driver).is_element_present(@element_locator) {true}
579
+ stub(driver).get_text(@element_locator) {"no match"}
580
+ proc do
581
+ element.assert_contains_in_order 'one', 'two', 'three'
582
+ end.should raise_error(Test::Unit::AssertionFailedError)
583
+ end
584
+
585
+ it "fails when element is not present" do
586
+ stub(driver).is_element_present(@element_locator) {false}
587
+ proc do
588
+ element.assert_contains_in_order 'one', 'two', 'three'
589
+ end.should raise_error(Test::Unit::AssertionFailedError)
590
+ end
591
+ end
592
+
593
+ describe "#method_missing" do
594
+ it "delegates command to the driver" do
595
+ element.methods.should_not include('click')
596
+ mock(driver).click(@element_locator)
597
+ element.click
598
+ end
599
+ end
600
+ end
601
+ end