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