polonium 0.1.0

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