seleniumrc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/CHANGES +2 -0
  2. data/README +0 -0
  3. data/Rakefile +68 -0
  4. data/lib/seleniumrc/app_server_checker.rb +43 -0
  5. data/lib/seleniumrc/dsl/selenium_dsl.rb +186 -0
  6. data/lib/seleniumrc/dsl/test_unit_dsl.rb +95 -0
  7. data/lib/seleniumrc/extensions/selenium_driver.rb +33 -0
  8. data/lib/seleniumrc/extensions/testrunnermediator.rb +19 -0
  9. data/lib/seleniumrc/mongrel_selenium_server_runner.rb +35 -0
  10. data/lib/seleniumrc/selenium_configuration.rb +78 -0
  11. data/lib/seleniumrc/selenium_context.rb +226 -0
  12. data/lib/seleniumrc/selenium_element.rb +195 -0
  13. data/lib/seleniumrc/selenium_helper.rb +5 -0
  14. data/lib/seleniumrc/selenium_page.rb +76 -0
  15. data/lib/seleniumrc/selenium_server_runner.rb +33 -0
  16. data/lib/seleniumrc/selenium_test_case.rb +95 -0
  17. data/lib/seleniumrc/tasks/selenium_test_task.rb +21 -0
  18. data/lib/seleniumrc/wait_for.rb +47 -0
  19. data/lib/seleniumrc/webrick_selenium_server_runner.rb +33 -0
  20. data/lib/seleniumrc.rb +28 -0
  21. data/spec/seleniumrc/app_server_checker_spec.rb +56 -0
  22. data/spec/seleniumrc/mongrel_selenium_server_runner_spec.rb +42 -0
  23. data/spec/seleniumrc/selenese_interpreter_spec.rb +25 -0
  24. data/spec/seleniumrc/selenium_configuration_spec.rb +21 -0
  25. data/spec/seleniumrc/selenium_context_spec.rb +362 -0
  26. data/spec/seleniumrc/selenium_element_spec.rb +530 -0
  27. data/spec/seleniumrc/selenium_page_spec.rb +226 -0
  28. data/spec/seleniumrc/selenium_server_runner_spec.rb +42 -0
  29. data/spec/seleniumrc/selenium_test_case_class_method_spec.rb +41 -0
  30. data/spec/seleniumrc/selenium_test_case_spec.rb +908 -0
  31. data/spec/seleniumrc/selenium_test_case_spec_helper.rb +23 -0
  32. data/spec/seleniumrc/webrick_selenium_server_runner_spec.rb +116 -0
  33. data/spec/spec_helper.rb +57 -0
  34. data/spec/spec_suite.rb +4 -0
  35. metadata +83 -0
@@ -0,0 +1,908 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ module Seleniumrc
4
+ describe SeleniumTestCase, :shared => true do
5
+ include SeleniumTestCaseSpec
6
+
7
+ before(:each) do
8
+ stub_selenium_configuration
9
+ @test_case = SeleniumTestCaseSpec::MySeleniumTestCase.new
10
+ @base_selenium = "Base Selenium"
11
+ @test_case.base_selenium = @base_selenium
12
+ stub(@base_selenium).get_eval(SeleniumPage::PAGE_LOADED_COMMAND) {"true"}
13
+ end
14
+
15
+ def sample_locator
16
+ "sample_locator"
17
+ end
18
+
19
+ def sample_text
20
+ "test text"
21
+ end
22
+
23
+ def stub_selenium_configuration
24
+ @context = SeleniumContext.new
25
+ @context.external_app_server_host = "test.com"
26
+ @context.external_app_server_port = 80
27
+
28
+ stub(SeleniumConfiguration.instance).returns(@context)
29
+ end
30
+ end
31
+
32
+ describe SeleniumTestCase, "#setup" do
33
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
34
+
35
+ it "should not allow transactional fixtures" do
36
+ stub(@test_case.class).use_transactional_fixtures.returns true
37
+
38
+ expected_message = "Cannot use transactional fixtures if ActiveRecord concurrency is turned on (which is required for Selenium tests to work)."
39
+ proc {@test_case.setup}.should raise_error(RuntimeError, expected_message)
40
+ end
41
+ end
42
+
43
+ describe SeleniumTestCase, "#wait_for" do
44
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
45
+
46
+ it "should pass when the block returns true within time limit" do
47
+ @test_case.wait_for(:timeout => 2) do
48
+ true
49
+ end
50
+ end
51
+
52
+ it "should raise a AssertionFailedError when block times out" do
53
+ proc do
54
+ @test_case.wait_for(:timeout => 2) {false}
55
+ end.should raise_error(Test::Unit::AssertionFailedError, "Timeout exceeded (after 2 sec)")
56
+ end
57
+ end
58
+
59
+ describe SeleniumTestCase, "#wait_for_element_to_contain" do
60
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
61
+
62
+ it "should pass when finding text within time limit" do
63
+ is_element_present_results = [false, true]
64
+
65
+ stub(base_selenium).is_element_present {is_element_present_results.shift}
66
+ stub(base_selenium).get_eval("this.page().findElement(\"#{sample_locator}\").innerHTML") do
67
+ sample_text
68
+ end
69
+
70
+ @test_case.wait_for_element_to_contain(sample_locator, sample_text)
71
+ end
72
+
73
+ it "should fail when element not found in time" do
74
+ is_element_present_results = [false, false, false, false]
75
+
76
+ stub(base_selenium).is_element_present {is_element_present_results.shift}
77
+
78
+ proc do
79
+ @test_case.wait_for_element_to_contain(sample_locator, "")
80
+ end.should raise_error(Test::Unit::AssertionFailedError, "Timeout exceeded (after 5 sec)")
81
+ end
82
+
83
+ it "should fail when text does not match in time" do
84
+ is_element_present_results = [false, true, true, true]
85
+
86
+ stub(base_selenium).is_element_present {is_element_present_results.shift}
87
+ stub(base_selenium).get_eval.
88
+ with("this.page().findElement(\"#{sample_locator}\").innerHTML").
89
+ returns(sample_text)
90
+
91
+ proc do
92
+ @test_case.wait_for_element_to_contain(sample_locator, "wrong text", nil, 1)
93
+ end.should raise_error(Test::Unit::AssertionFailedError, "Timeout exceeded (after 1 sec)")
94
+ end
95
+ end
96
+
97
+ describe SeleniumTestCase, "#default_timeout" do
98
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
99
+
100
+ it "default_timeout should be 20 seconds" do
101
+ @test_case.default_timeout.should == 20000
102
+ end
103
+ end
104
+
105
+ describe SeleniumTestCase, "#open_home_page" do
106
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
107
+
108
+ it "opens home page" do
109
+ mock(base_selenium).open("http://localhost:4000")
110
+ mock(base_selenium).wait_for_page_to_load(@test_case.default_timeout)
111
+ stub(base_selenium).send {""}
112
+
113
+ @test_case.open_home_page
114
+ end
115
+ end
116
+
117
+ describe SeleniumTestCase, "#open_and_wait" do
118
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
119
+
120
+ before do
121
+ mock.proxy(SeleniumPage).new(base_selenium) do |page|
122
+ mock.proxy(page).open_and_wait("/users/list")
123
+ page
124
+ end
125
+ end
126
+
127
+ it "opens the url and waits for the page to load" do
128
+ mock(base_selenium) do |o|
129
+ o.open("/users/list")
130
+ o.wait_for_page_to_load(@test_case.default_timeout)
131
+ o.get_title {"Users in the project"}
132
+ end
133
+ @test_case.open_and_wait("/users/list")
134
+ end
135
+ end
136
+
137
+ describe SeleniumTestCase, "#assert_title" do
138
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
139
+
140
+ before do
141
+ mock.proxy(SeleniumPage).new(base_selenium) do |page|
142
+ mock.proxy(page).has_title("my page", {})
143
+ page
144
+ end
145
+ end
146
+
147
+ it "passes when title is expected" do
148
+ mock(base_selenium).get_title {"my page"}
149
+ @test_case.assert_title("my page")
150
+ end
151
+
152
+ it "fails when title is not expected" do
153
+ stub(base_selenium).get_title {"no page"}
154
+ proc do
155
+ @test_case.assert_title("my page")
156
+ end.should raise_error(Test::Unit::AssertionFailedError)
157
+ end
158
+ end
159
+
160
+ describe SeleniumTestCase, "#assert_text_present" do
161
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
162
+
163
+ before do
164
+ mock.proxy(SeleniumPage).new(base_selenium) do |page|
165
+ mock.proxy(page).is_text_present("my page", {})
166
+ page
167
+ end
168
+ end
169
+
170
+ it "passes when text is in page" do
171
+ ticks = [false, false, false, true]
172
+ mock(base_selenium).is_text_present("my page") do
173
+ ticks.shift
174
+ end.times(4)
175
+ @test_case.assert_text_present("my page")
176
+ end
177
+
178
+ it "fails when text is not in page" do
179
+ stub(base_selenium).is_text_present("my page") {false}
180
+ proc do
181
+ @test_case.assert_text_present("my page")
182
+ end.should raise_error(Test::Unit::AssertionFailedError)
183
+ end
184
+ end
185
+
186
+ describe SeleniumTestCase, "#assert_text_not_present" do
187
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
188
+
189
+ before do
190
+ mock.proxy(SeleniumPage).new(base_selenium) do |page|
191
+ mock.proxy(page).is_text_not_present("my page", {})
192
+ page
193
+ end
194
+ end
195
+
196
+ it "passes when text is not in page" do
197
+ ticks = [true, true, true, false]
198
+ mock(base_selenium).is_text_present("my page") do
199
+ ticks.shift
200
+ end.times(4)
201
+ @test_case.assert_text_not_present("my page")
202
+ end
203
+
204
+ it "fails when text is in page" do
205
+ stub(base_selenium).is_text_present("my page") {true}
206
+ proc do
207
+ @test_case.assert_text_not_present("my page")
208
+ end.should raise_error(Test::Unit::AssertionFailedError)
209
+ end
210
+ end
211
+
212
+ describe SeleniumTestCase, "#assert_location_ends_in" do
213
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
214
+
215
+ before do
216
+ @ends_with = "foobar.com?arg1=2"
217
+ mock.proxy(SeleniumPage).new(base_selenium) do |page|
218
+ mock.proxy(page).url_ends_with(@ends_with, {})
219
+ page
220
+ end
221
+ end
222
+
223
+ it "passes when the url ends with the passed in value" do
224
+ ticks = [
225
+ "http://no.com",
226
+ "http://no.com",
227
+ "http://no.com",
228
+ "http://foobar.com?arg1=2"
229
+ ]
230
+ mock(base_selenium).get_location do
231
+ ticks.shift
232
+ end.times(4)
233
+ @test_case.assert_location_ends_in(@ends_with)
234
+ end
235
+
236
+ it "fails when the url does not end with the passed in value" do
237
+ stub(base_selenium).get_location {"http://no.com"}
238
+ proc do
239
+ @test_case.assert_location_ends_in(@ends_with)
240
+ end.should raise_error(Test::Unit::AssertionFailedError)
241
+ end
242
+ end
243
+
244
+ describe SeleniumTestCase, "#assert_element_present" do
245
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
246
+
247
+ before do
248
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
249
+ mock.proxy(element).is_present({})
250
+ element
251
+ end
252
+ end
253
+
254
+ it "passes when element is present" do
255
+ ticks = [false, false, false, true]
256
+ mock(base_selenium) do |o|
257
+ o.is_element_present(sample_locator) do
258
+ ticks.shift
259
+ end.times(4)
260
+ end
261
+ @test_case.assert_element_present(sample_locator)
262
+ end
263
+
264
+ it "fails when element is not present" do
265
+ stub(base_selenium) do |o|
266
+ o.is_element_present(sample_locator) {false}
267
+ end
268
+ proc do
269
+ @test_case.assert_element_present(sample_locator)
270
+ end.should raise_error(Test::Unit::AssertionFailedError)
271
+ end
272
+ end
273
+
274
+ describe SeleniumTestCase, "#assert_element_not_present" do
275
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
276
+
277
+ before do
278
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
279
+ mock.proxy(element).is_not_present({})
280
+ element
281
+ end
282
+ end
283
+
284
+ it "passes when element is not present" do
285
+ ticks = [true, true, true, false]
286
+ mock(base_selenium) do |o|
287
+ o.is_element_present(sample_locator) do
288
+ ticks.shift
289
+ end.times(4)
290
+ end
291
+ @test_case.assert_element_not_present(sample_locator)
292
+ end
293
+
294
+ it "fails when element is present" do
295
+ stub(base_selenium) do |o|
296
+ o.is_element_present(sample_locator) {true}
297
+ end
298
+ proc do
299
+ @test_case.assert_element_not_present(sample_locator)
300
+ end.should raise_error(Test::Unit::AssertionFailedError)
301
+ end
302
+ end
303
+
304
+ describe SeleniumTestCase, "#assert_value" do
305
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
306
+
307
+ before do
308
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
309
+ mock.proxy(element).has_value("passed in value")
310
+ element
311
+ end
312
+ end
313
+
314
+ it "passes when value is expected" do
315
+ mock(base_selenium) do |o|
316
+ o.is_element_present(sample_locator) {true}
317
+ o.get_value(sample_locator) {"passed in value"}
318
+ end
319
+ @test_case.assert_value(sample_locator, "passed in value")
320
+ end
321
+
322
+ it "fails when value is not expected" do
323
+ stub(base_selenium) do |o|
324
+ o.is_element_present(sample_locator) {true}
325
+ o.get_value(sample_locator) {"another value"}
326
+ end
327
+ proc do
328
+ @test_case.assert_value(sample_locator, "passed in value")
329
+ end.should raise_error(Test::Unit::AssertionFailedError)
330
+ end
331
+ end
332
+
333
+ describe SeleniumTestCase, "#assert_element_contains" do
334
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
335
+
336
+ before do
337
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
338
+ mock.proxy(element).contains_text("passed in value", {})
339
+ element
340
+ end
341
+ @evaled_js = "this.page().findElement(\"#{sample_locator}\").innerHTML"
342
+ end
343
+
344
+ it "passes when text is in the element's inner_html" do
345
+ mock(base_selenium) do |o|
346
+ o.is_element_present(sample_locator) {true}
347
+ o.get_eval(@evaled_js) do
348
+ "html passed in value html"
349
+ end
350
+ end
351
+ @test_case.assert_element_contains(sample_locator, "passed in value")
352
+ end
353
+
354
+ it "fails when text is not in the element's inner_html" do
355
+ stub(base_selenium) do |o|
356
+ o.is_element_present(sample_locator) {true}
357
+ o.get_eval(@evaled_js) {"another value"}
358
+ end
359
+ proc do
360
+ @test_case.assert_element_contains(sample_locator, "passed in value")
361
+ end.should raise_error(Test::Unit::AssertionFailedError)
362
+ end
363
+ end
364
+
365
+ describe SeleniumTestCase, "#element_does_not_contain_text" do
366
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
367
+
368
+ it "returns true when element is not on the page" do
369
+ locator = "id=element_id"
370
+ expected_text = "foobar"
371
+ mock(base_selenium).is_element_present.with(locator).returns(false)
372
+
373
+ @test_case.element_does_not_contain_text(locator, expected_text).should == true
374
+ end
375
+
376
+ it "returns true when element is on page and inner_html does not contain text" do
377
+ locator = "id=element_id"
378
+ inner_html = "Some text that does not contain the expected_text"
379
+ expected_text = "foobar"
380
+ mock(base_selenium).is_element_present.with(locator).returns(true)
381
+ mock(@test_case).get_inner_html.with(locator).returns(inner_html)
382
+
383
+ @test_case.element_does_not_contain_text(locator, expected_text).should == true
384
+ end
385
+
386
+ it "returns false when element is on page and inner_html does contain text" do
387
+ locator = "id=element_id"
388
+ inner_html = "foobar foobar foobar"
389
+ expected_text = "foobar"
390
+ mock(base_selenium).is_element_present.with(locator).returns(true)
391
+ mock(@test_case).get_inner_html.with(locator).returns(inner_html)
392
+
393
+ @test_case.element_does_not_contain_text(locator, expected_text).should == false
394
+ end
395
+ end
396
+
397
+ describe SeleniumTestCase, "#assert_element_does_not_contain_text" do
398
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
399
+
400
+ before do
401
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
402
+ mock.proxy(element).does_not_contain_text("passed in value", {})
403
+ element
404
+ end
405
+ @evaled_js = "this.page().findElement(\"#{sample_locator}\").innerHTML"
406
+ end
407
+
408
+ it "passes when text is not in the element's inner_html" do
409
+ mock(base_selenium) do |o|
410
+ o.is_element_present(sample_locator) {true}
411
+ o.get_eval(@evaled_js) do
412
+ "another value"
413
+ end
414
+ end
415
+ @test_case.assert_element_does_not_contain_text(sample_locator, "passed in value")
416
+ end
417
+
418
+ it "fails when text is in the element's inner_html" do
419
+ stub(base_selenium) do |o|
420
+ o.is_element_present(sample_locator) {true}
421
+ o.get_eval(@evaled_js) {"html passed in value html"}
422
+ end
423
+ proc do
424
+ @test_case.assert_element_does_not_contain_text(sample_locator, "passed in value")
425
+ end.should raise_error(Test::Unit::AssertionFailedError)
426
+ end
427
+ end
428
+
429
+ describe SeleniumTestCase, "#element_does_not_contain_text" do
430
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
431
+
432
+ it "checks if text is in order" do
433
+ locator = "id=foo"
434
+ stub(@base_selenium).get_text(locator).returns("one\ntwo\nthree\n")
435
+
436
+ @test_case.is_text_in_order locator, "one", "two", "three"
437
+ end
438
+ end
439
+
440
+ describe SeleniumTestCase, "#assert_attribute" do
441
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
442
+
443
+ before do
444
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
445
+ mock.proxy(element).has_attribute("passed in value")
446
+ element
447
+ end
448
+ end
449
+
450
+ it "passes when attribute is expected" do
451
+ mock(base_selenium) do |o|
452
+ o.is_element_present(sample_locator) {true}
453
+ o.get_attribute(sample_locator) {"passed in value"}
454
+ end
455
+ @test_case.assert_attribute(sample_locator, "passed in value")
456
+ end
457
+
458
+ it "fails when attribute is not expected" do
459
+ stub(base_selenium) do |o|
460
+ o.is_element_present(sample_locator) {true}
461
+ o.get_attribute(sample_locator) {"another value"}
462
+ end
463
+ proc do
464
+ @test_case.assert_attribute(sample_locator, "passed in value")
465
+ end.should raise_error(Test::Unit::AssertionFailedError)
466
+ end
467
+ end
468
+
469
+ describe SeleniumTestCase, "#assert_selected" do
470
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
471
+
472
+ before do
473
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
474
+ mock.proxy(element).has_selected("passed_in_element")
475
+ element
476
+ end
477
+ end
478
+
479
+ it "passes when selected is expected" do
480
+ mock(base_selenium) do |o|
481
+ o.is_element_present(sample_locator) {true}
482
+ o.get_selected_label(sample_locator) {"passed_in_element"}
483
+ end
484
+ @test_case.assert_selected(sample_locator, "passed_in_element")
485
+ end
486
+
487
+ it "fails when selected is not expected" do
488
+ stub(base_selenium) do |o|
489
+ o.is_element_present(sample_locator) {true}
490
+ o.get_selected_label(sample_locator) {"another_element"}
491
+ end
492
+ proc do
493
+ @test_case.assert_selected(sample_locator, "passed_in_element")
494
+ end.should raise_error(Test::Unit::AssertionFailedError)
495
+ end
496
+ end
497
+
498
+ describe SeleniumTestCase, "#assert_checked" do
499
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
500
+
501
+ before do
502
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
503
+ mock.proxy(element).is_checked
504
+ element
505
+ end
506
+ end
507
+
508
+ it "passes when checked" do
509
+ mock(base_selenium) do |o|
510
+ o.is_element_present(sample_locator) {true}
511
+ o.is_checked(sample_locator) {true}
512
+ end
513
+ @test_case.assert_checked(sample_locator)
514
+ end
515
+
516
+ it "fails when not checked" do
517
+ stub(base_selenium) do |o|
518
+ o.is_element_present(sample_locator) {true}
519
+ o.is_checked(sample_locator) {false}
520
+ end
521
+ proc do
522
+ @test_case.assert_checked(sample_locator)
523
+ end.should raise_error(Test::Unit::AssertionFailedError)
524
+ end
525
+ end
526
+
527
+ describe SeleniumTestCase, "#assert_not_checked" do
528
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
529
+
530
+ before do
531
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
532
+ mock.proxy(element).is_not_checked
533
+ element
534
+ end
535
+ end
536
+
537
+ it "passes when not checked" do
538
+ mock(base_selenium) do |o|
539
+ o.is_element_present(sample_locator) {true}
540
+ o.is_checked(sample_locator) {false}
541
+ end
542
+ @test_case.assert_not_checked(sample_locator)
543
+ end
544
+
545
+ it "fails when checked" do
546
+ stub(base_selenium) do |o|
547
+ o.is_element_present(sample_locator) {true}
548
+ o.is_checked(sample_locator) {true}
549
+ end
550
+ proc do
551
+ @test_case.assert_not_checked(sample_locator)
552
+ end.should raise_error(Test::Unit::AssertionFailedError)
553
+ end
554
+ end
555
+
556
+ describe SeleniumTestCase, "#assert_text" do
557
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
558
+
559
+ before do
560
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
561
+ mock.proxy(element).has_text("expected text", {})
562
+ element
563
+ end
564
+ end
565
+
566
+ it "passes when text is expected" do
567
+ mock(base_selenium) do |o|
568
+ o.is_element_present(sample_locator) {true}
569
+ o.get_text(sample_locator) {"expected text"}
570
+ end
571
+ @test_case.assert_text(sample_locator, "expected text")
572
+ end
573
+
574
+ it "fails when text is not expected" do
575
+ stub(base_selenium) do |o|
576
+ o.is_element_present(sample_locator) {true}
577
+ o.get_text(sample_locator) {"unexpected text"}
578
+ end
579
+ proc do
580
+ @test_case.assert_text(sample_locator, "expected text")
581
+ end.should raise_error(Test::Unit::AssertionFailedError)
582
+ end
583
+ end
584
+
585
+ describe SeleniumTestCase, "#assert_visible" do
586
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
587
+
588
+ before do
589
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
590
+ mock.proxy(element).is_visible({})
591
+ element
592
+ end
593
+ end
594
+
595
+ it "passes when element is visible" do
596
+ mock(base_selenium).is_element_present(sample_locator) {true}
597
+ mock(base_selenium).is_visible(sample_locator) {true}
598
+
599
+ @test_case.assert_visible(sample_locator)
600
+ end
601
+
602
+ it "fails when element is not visible" do
603
+ mock(base_selenium).is_element_present(sample_locator) {true}
604
+ stub(base_selenium).is_visible.returns {false}
605
+
606
+ proc {
607
+ @test_case.assert_visible(sample_locator)
608
+ }.should raise_error(Test::Unit::AssertionFailedError)
609
+ end
610
+ end
611
+
612
+ describe SeleniumTestCase, "#assert_not_visible" do
613
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
614
+
615
+ before do
616
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
617
+ mock.proxy(element).is_not_visible({})
618
+ element
619
+ end
620
+ end
621
+
622
+ it "passes when element is present and is not visible" do
623
+ mock(base_selenium).is_element_present(sample_locator) {true}
624
+ mock(base_selenium).is_visible(sample_locator) {false}
625
+
626
+ @test_case.assert_not_visible(sample_locator)
627
+ end
628
+
629
+ it "fails when element is visible" do
630
+ mock(base_selenium).is_element_present(sample_locator) {true}
631
+ stub(base_selenium).is_visible(sample_locator) {true}
632
+
633
+ proc {
634
+ @test_case.assert_not_visible(sample_locator)
635
+ }.should raise_error(Test::Unit::AssertionFailedError)
636
+ end
637
+ end
638
+
639
+ describe SeleniumTestCase, "#assert_next_sibling" do
640
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
641
+
642
+ before do
643
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator) do |element|
644
+ mock.proxy(element).has_next_sibling("next_sibling", {})
645
+ element
646
+ end
647
+ @evaled_js = "this.page().findElement('#{sample_locator}').nextSibling.id"
648
+ end
649
+
650
+ it "passes when passed next sibling id" do
651
+ mock(base_selenium) do |o|
652
+ o.is_element_present(sample_locator) {true}
653
+ o.get_eval(@evaled_js) {"next_sibling"}
654
+ end
655
+ @test_case.assert_next_sibling(sample_locator, "next_sibling")
656
+ end
657
+
658
+ it "fails when not passed next sibling id" do
659
+ stub(base_selenium) do |o|
660
+ o.is_element_present(sample_locator) {true}
661
+ o.get_eval(@evaled_js) {"wrong_sibling"}
662
+ end
663
+ proc do
664
+ @test_case.assert_next_sibling(sample_locator, "next_sibling")
665
+ end.should raise_error(Test::Unit::AssertionFailedError)
666
+ end
667
+ end
668
+
669
+ describe SeleniumTestCase, "#assert_text_in_order" do
670
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
671
+
672
+ before do
673
+ mock.proxy(SeleniumElement).new(base_selenium, sample_locator)
674
+ @evaled_js = "this.page().findElement('#{sample_locator}').nextSibling.id"
675
+ end
676
+
677
+ it "passes when text is in order" do
678
+ mock(base_selenium) do |o|
679
+ o.is_element_present(sample_locator) {true}
680
+ o.get_text(sample_locator) {"one\ntwo\nthree\n"}
681
+ end
682
+ @test_case.assert_text_in_order sample_locator, "one", "two", "three"
683
+ end
684
+
685
+ it "fails when element is present and text is not in order" do
686
+ stub(base_selenium) do |o|
687
+ o.is_element_present(sample_locator) {true}
688
+ o.get_text(sample_locator) {"<html>one\ntext not in order\n</html>"}
689
+ end
690
+ proc do
691
+ @test_case.assert_text_in_order sample_locator, "one", "two", "three"
692
+ end.should raise_error(Test::Unit::AssertionFailedError)
693
+ end
694
+ end
695
+
696
+ describe SeleniumTestCase, "#type" do
697
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
698
+
699
+ it "types when element is present and types" do
700
+ is_element_present_results = [false, true]
701
+ mock(base_selenium).is_element_present.with("id=foobar").twice.returns {is_element_present_results.shift}
702
+ mock(base_selenium).type.with("id=foobar", "The Text")
703
+
704
+ @test_case.type "id=foobar", "The Text"
705
+ end
706
+
707
+ it "fails when element is not present" do
708
+ is_element_present_results = [false, false, false, false]
709
+ mock(base_selenium).is_element_present.with("id=foobar").times(4).
710
+ returns {is_element_present_results.shift}
711
+ dont_allow(base_selenium).type
712
+
713
+ proc {
714
+ @test_case.type "id=foobar", "The Text"
715
+ }.should raise_error(Test::Unit::AssertionFailedError)
716
+ end
717
+ end
718
+
719
+ describe SeleniumTestCase, "#click" do
720
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
721
+
722
+ it "click when element is present and types" do
723
+ is_element_present_results = [false, true]
724
+ mock(base_selenium).is_element_present.with("id=foobar").twice.returns {is_element_present_results.shift}
725
+ mock(base_selenium).click.with("id=foobar")
726
+
727
+ @test_case.click "id=foobar"
728
+ end
729
+
730
+ it "fails when element is not present" do
731
+ is_element_present_results = [false, false, false, false]
732
+ mock(base_selenium).is_element_present.with("id=foobar").times(4).
733
+ returns {is_element_present_results.shift}
734
+ dont_allow(base_selenium).click
735
+
736
+ proc {
737
+ @test_case.click "id=foobar"
738
+ }.should raise_error(Test::Unit::AssertionFailedError)
739
+ end
740
+ end
741
+
742
+ describe SeleniumTestCase, "#select" do
743
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
744
+
745
+ it "types when element is present and types" do
746
+ is_element_present_results = [false, true]
747
+ mock(base_selenium).is_element_present.with("id=foobar").twice.returns {is_element_present_results.shift}
748
+ mock(base_selenium).select.with("id=foobar", "value=3")
749
+
750
+ @test_case.select "id=foobar", "value=3"
751
+ end
752
+
753
+ it "fails when element is not present" do
754
+ is_element_present_results = [false, false, false, false]
755
+ mock(base_selenium).is_element_present.with("id=foobar").times(4).
756
+ returns {is_element_present_results.shift}
757
+ dont_allow(base_selenium).select
758
+
759
+ proc {
760
+ @test_case.select "id=foobar", "value=3"
761
+ }.should raise_error(Test::Unit::AssertionFailedError)
762
+ end
763
+ end
764
+
765
+ describe SeleniumTestCase, "#wait_for_and_click" do
766
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
767
+
768
+ it "click when element is present and types" do
769
+ is_element_present_results = [false, true]
770
+ mock(base_selenium).is_element_present.with("id=foobar").twice.returns {is_element_present_results.shift}
771
+ mock(base_selenium).click.with("id=foobar")
772
+
773
+ @test_case.wait_for_and_click "id=foobar"
774
+ end
775
+
776
+ it "fails when element is not present" do
777
+ is_element_present_results = [false, false, false, false]
778
+ mock(base_selenium).is_element_present.with("id=foobar").times(4).
779
+ returns {is_element_present_results.shift}
780
+ dont_allow(base_selenium).click
781
+
782
+ proc {
783
+ @test_case.wait_for_and_click "id=foobar"
784
+ }.should raise_error(Test::Unit::AssertionFailedError)
785
+ end
786
+ end
787
+
788
+ describe SeleniumTestCase, "#page" do
789
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
790
+
791
+ it "returns page" do
792
+ @test_case.page.should == SeleniumPage.new(base_selenium)
793
+ end
794
+ end
795
+
796
+ describe "SeleniumTestCase in test browser mode and test fails" do
797
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
798
+
799
+ it "should stop interpreter when configuration says to stop test" do
800
+ @test_case.configuration = "Seleniumrc::SeleniumConfiguration"
801
+ mock(@test_case.configuration).test_browser_mode?.returns(true)
802
+
803
+ stub(@test_case).passed?.returns(false)
804
+ mock(@test_case.configuration).stop_selenese_interpreter?.with(false).returns(true)
805
+
806
+ mock(base_selenium).stop.once
807
+ @test_case.base_selenium = base_selenium
808
+
809
+ @test_case.teardown
810
+ end
811
+
812
+ it "should not stop interpreter when configuration says not to stop test" do
813
+ @test_case.configuration = "Seleniumrc::SeleniumConfiguration"
814
+ mock(@test_case.configuration).test_browser_mode?.returns(true)
815
+
816
+ stub(@test_case).passed?.returns(false)
817
+ mock(@test_case.configuration).stop_selenese_interpreter?.with(false).returns(false)
818
+
819
+ @test_case.base_selenium = base_selenium
820
+
821
+ @test_case.teardown
822
+ end
823
+ end
824
+
825
+ describe "SeleniumTestCase in test browser mode and test pass" do
826
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
827
+
828
+ it "should stop interpreter when configuration says to stop test" do
829
+ @test_case.configuration = "Seleniumrc::SeleniumConfiguration"
830
+ mock(@test_case.configuration).test_browser_mode?.returns(true)
831
+
832
+ stub(@test_case).passed?.returns(true)
833
+ mock(@test_case.configuration).stop_selenese_interpreter?.with(true).returns(true)
834
+
835
+ mock(base_selenium).stop.once
836
+ @test_case.base_selenium = base_selenium
837
+
838
+ @test_case.teardown
839
+ end
840
+
841
+ it "should not stop interpreter when configuration says not to stop test" do
842
+ @test_case.configuration = "Seleniumrc::SeleniumConfiguration"
843
+ mock(@test_case.configuration).test_browser_mode?.returns(true)
844
+
845
+ stub(@test_case).passed?.returns(true)
846
+ mock(@test_case.configuration).stop_selenese_interpreter?.with(true).returns(false)
847
+
848
+ @test_case.base_selenium = base_selenium
849
+
850
+ @test_case.teardown
851
+ end
852
+ end
853
+
854
+ describe "SeleniumTestCase not in suite browser mode" do
855
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
856
+
857
+ it "should not stop interpreter when tests fail" do
858
+ @test_case.configuration = "Seleniumrc::SeleniumConfiguration"
859
+ mock(@test_case.configuration).test_browser_mode?.returns(false)
860
+
861
+ def @test_case.passed?; false; end
862
+
863
+ @test_case.base_selenium = base_selenium
864
+
865
+ @test_case.teardown
866
+ end
867
+
868
+ it "should stop interpreter when tests pass" do
869
+ @test_case.configuration = "Seleniumrc::SeleniumConfiguration"
870
+ mock(@test_case.configuration).test_browser_mode?.returns(false)
871
+
872
+ stub(@test_case).passed?.returns(true)
873
+
874
+ @test_case.base_selenium = base_selenium
875
+
876
+ @test_case.teardown
877
+ end
878
+ end
879
+
880
+ describe "SeleniumTestCase in test browser mode and test pass" do
881
+ it_should_behave_like "Seleniumrc::SeleniumTestCase"
882
+
883
+ it "should stop interpreter when configuration says to stop test" do
884
+ @test_case.configuration = "Seleniumrc::SeleniumConfiguration"
885
+ mock(@test_case.configuration).test_browser_mode?.returns(true)
886
+
887
+ stub(@test_case).passed?.returns(true)
888
+ mock(@test_case.configuration).stop_selenese_interpreter?.with(true).returns(true)
889
+
890
+ mock(base_selenium).stop.once
891
+ @test_case.base_selenium = base_selenium
892
+
893
+ @test_case.teardown
894
+ end
895
+
896
+ it "should not stop interpreter when configuration says not to stop test" do
897
+ @test_case.configuration = "Seleniumrc::SeleniumConfiguration"
898
+ mock(@test_case.configuration).test_browser_mode?.returns(true)
899
+
900
+ stub(@test_case).passed?.returns(true)
901
+ mock(@test_case.configuration).stop_selenese_interpreter?.with(true).returns(false)
902
+
903
+ @test_case.base_selenium = base_selenium
904
+
905
+ @test_case.teardown
906
+ end
907
+ end
908
+ end