rwebspec 1.4.0.2 → 1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +37 -0
- data/Rakefile +6 -9
- data/lib/rwebspec/assert.rb +95 -70
- data/lib/rwebspec/database_checker.rb +74 -0
- data/lib/rwebspec/driver.rb +878 -741
- data/lib/rwebspec/load_test_helper.rb +110 -0
- data/lib/rwebspec/matchers/contains_text.rb +2 -2
- data/lib/rwebspec/test_utils.rb +57 -16
- data/lib/rwebspec/{itest_plugin.rb → testwise_plugin.rb} +82 -78
- data/lib/rwebspec/web_browser.rb +67 -17
- data/lib/rwebspec/web_page.rb +6 -6
- data/lib/rwebspec.rb +6 -2
- data/lib/watir_extensions.rb +49 -43
- metadata +10 -28
data/CHANGELOG
CHANGED
@@ -1,5 +1,42 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
|
+
1.6
|
4
|
+
Include ScreenCapture
|
5
|
+
|
6
|
+
1.5.4
|
7
|
+
Add syntax click_link("Duplicate Link", :index => 2) # second link
|
8
|
+
|
9
|
+
1.5.3 (2010-01-06)
|
10
|
+
rename itest_plugin -> testwise_plugin
|
11
|
+
remove dependency on test-unit
|
12
|
+
|
13
|
+
1.5.2
|
14
|
+
add contains matcher to driver and page
|
15
|
+
in page, page_text renamed to page_specific_text
|
16
|
+
more unit tests
|
17
|
+
|
18
|
+
1.5.1
|
19
|
+
[Load Test helper
|
20
|
+
assert_text_present changed to check text view of web pages
|
21
|
+
detect ILOAD2 environment to determin to preivew load test or not
|
22
|
+
|
23
|
+
1.5
|
24
|
+
[New] Supports Watir 1.6.5
|
25
|
+
[Fixes] Array@sum conflicts with ActiveSupport
|
26
|
+
[New] New database_checker
|
27
|
+
[Other] load_table define class under ITEST::Module
|
28
|
+
|
29
|
+
1.4.2
|
30
|
+
[New] average, sum for array objects, such as [1,2,3,4].average
|
31
|
+
[New] support date format with today(:us), yesterday("%d/%m/%Y")
|
32
|
+
[TODO] click security alerts
|
33
|
+
|
34
|
+
1.4.1
|
35
|
+
[New] Added LoadTestHelper
|
36
|
+
[New] add expect_page to web_browser
|
37
|
+
[Fix] nil error in random_str (test_utils.rb)
|
38
|
+
[New] Add alias methods for select_list (alias)
|
39
|
+
|
3
40
|
1.4.0.2
|
4
41
|
Fixed: reuse browser does not work
|
5
42
|
Add gem dependency (Watir/Firewatir) depends on platforms
|
data/Rakefile
CHANGED
@@ -12,6 +12,9 @@ $:.unshift(File.dirname(__FILE__) + "/lib")
|
|
12
12
|
desc "Default task"
|
13
13
|
task :default => [ :clean, :spec, :rdoc, :chm, :gem]
|
14
14
|
|
15
|
+
desc "Continous build"
|
16
|
+
task :build => [:clean, :spec]
|
17
|
+
|
15
18
|
desc "Clean generated files"
|
16
19
|
task :clean do
|
17
20
|
rm_rf 'pkg'
|
@@ -69,7 +72,7 @@ end
|
|
69
72
|
spec = Gem::Specification.new do |s|
|
70
73
|
s.platform= Gem::Platform::RUBY
|
71
74
|
s.name = "rwebspec"
|
72
|
-
s.version = "1.
|
75
|
+
s.version = "1.6"
|
73
76
|
s.summary = "Executable functional specification for web applications in RSpec syntax and Watir"
|
74
77
|
# s.description = ""
|
75
78
|
|
@@ -89,14 +92,8 @@ spec = Gem::Specification.new do |s|
|
|
89
92
|
s.files = s.files + Dir.glob( "sample/**/*")
|
90
93
|
s.files = s.files + Dir.glob( "docs/**/*" )
|
91
94
|
s.add_dependency(%q<rspec>, ["= 1.1.12"])
|
92
|
-
|
93
|
-
|
94
|
-
else
|
95
|
-
s.add_dependency("firewatir", ">= 1.6.2")
|
96
|
-
end
|
97
|
-
|
98
|
-
s.add_dependency("commonwatir", ">= 1.6.2")
|
99
|
-
s.add_dependency("test-unit", ">= 2.0.2")
|
95
|
+
|
96
|
+
s.add_dependency("commonwatir", ">= 1.6.5")
|
100
97
|
end
|
101
98
|
|
102
99
|
Rake::GemPackageTask.new(spec) do |pkg|
|
data/lib/rwebspec/assert.rb
CHANGED
@@ -2,41 +2,53 @@ require 'test/unit/assertions'
|
|
2
2
|
|
3
3
|
module RWebSpec
|
4
4
|
module Assert
|
5
|
-
|
6
5
|
include Test::Unit::Assertions
|
7
|
-
|
6
|
+
|
8
7
|
def assert_not(condition, msg = "")
|
9
|
-
assert(!condition, msg)
|
8
|
+
perform_assertion { assert(!condition, msg) }
|
10
9
|
end
|
11
|
-
|
10
|
+
|
12
11
|
def assert_nil(actual, msg="")
|
13
|
-
assert(actual.nil?, msg)
|
12
|
+
perform_assertion { assert(actual.nil?, msg) }
|
14
13
|
end
|
15
14
|
|
16
15
|
def assert_not_nil(actual, msg="")
|
17
|
-
assert(!actual.nil?, msg)
|
16
|
+
perform_assertion { assert(!actual.nil?, msg) }
|
18
17
|
end
|
19
18
|
|
20
19
|
def fail(message)
|
21
|
-
assert(false, message)
|
20
|
+
perform_assertion { assert(false, message) }
|
22
21
|
end
|
23
22
|
|
24
23
|
# assertions
|
25
24
|
def assert_title_equals(title)
|
26
25
|
assert_equals(title, @web_browser.page_title)
|
27
26
|
end
|
27
|
+
|
28
28
|
alias assert_title assert_title_equals
|
29
29
|
|
30
30
|
# Assert text present in page source (html)
|
31
|
-
#
|
31
|
+
# assert_text_in_page_source("<b>iTest2</b> Cool") # <b>iTest2</b> Cool
|
32
|
+
def assert_text_in_page_source(text)
|
33
|
+
perform_assertion { assert((@web_browser.page_source.include? text), 'expected html: ' + text + ' not found') }
|
34
|
+
end
|
35
|
+
|
36
|
+
# Assert text not present in page source (html)
|
37
|
+
# assert_text_not_in_page_source("<b>iTest2</b> Cool") # <b>iTest2</b> Cool
|
38
|
+
def assert_text_not_in_page_source(text)
|
39
|
+
perform_assertion { assert(!(@web_browser.page_source.include? text), 'expected html: ' + text + ' found') }
|
40
|
+
end
|
41
|
+
|
42
|
+
# Assert text present in page source (html)
|
43
|
+
# assert_text_present("iTest2 Cool") # <b>iTest2</b> Cool
|
32
44
|
def assert_text_present(text)
|
33
|
-
assert((@web_browser.
|
45
|
+
perform_assertion { assert((@web_browser.text.include? text), 'expected text: ' + text + ' not found') }
|
34
46
|
end
|
35
47
|
|
36
48
|
# Assert text not present in page source (html)
|
37
|
-
# assert_text_not_present("<
|
49
|
+
# assert_text_not_present("iTest2 Cool") # <b>iTest2</b> Cool
|
38
50
|
def assert_text_not_present(text)
|
39
|
-
assert(!(@web_browser.
|
51
|
+
perform_assertion { assert(!(@web_browser.text.include? text), 'expected text: ' + text + ' found') }
|
40
52
|
end
|
41
53
|
|
42
54
|
|
@@ -58,7 +70,7 @@ module RWebSpec
|
|
58
70
|
|
59
71
|
def assert_link_not_present_with_exact(link_text)
|
60
72
|
@web_browser.links.each { |link|
|
61
|
-
assert(link_text != link.text, "unexpected link (exact): #{link_text} found")
|
73
|
+
perform_assertion { assert(link_text != link.text, "unexpected link (exact): #{link_text} found") }
|
62
74
|
}
|
63
75
|
end
|
64
76
|
|
@@ -76,7 +88,7 @@ module RWebSpec
|
|
76
88
|
|
77
89
|
def assert_link_not_present_with_text(link_text)
|
78
90
|
@web_browser.links.each { |link|
|
79
|
-
assert(!link.text.include?(link_text), "unexpected link containing: #{link_text} found")
|
91
|
+
perform_assertion { assert(!link.text.include?(link_text), "unexpected link containing: #{link_text} found") }
|
80
92
|
}
|
81
93
|
end
|
82
94
|
|
@@ -86,20 +98,22 @@ module RWebSpec
|
|
86
98
|
def assert_checkbox_not_selected(checkbox_name)
|
87
99
|
@web_browser.checkboxes.each { |checkbox|
|
88
100
|
if (checkbox.name == checkbox_name) then
|
89
|
-
assert(!checkbox.isSet?, "Checkbox #{checkbox_name} is checked unexpectly")
|
101
|
+
perform_assertion { assert(!checkbox.isSet?, "Checkbox #{checkbox_name} is checked unexpectly") }
|
90
102
|
end
|
91
103
|
}
|
92
104
|
end
|
93
|
-
|
105
|
+
|
106
|
+
alias assert_checkbox_not_checked assert_checkbox_not_selected
|
94
107
|
|
95
108
|
def assert_checkbox_selected(checkbox_name)
|
96
109
|
@web_browser.checkboxes.each { |checkbox|
|
97
110
|
if (checkbox.name == checkbox_name) then
|
98
|
-
assert(checkbox.isSet?, "Checkbox #{checkbox_name} not checked")
|
111
|
+
perform_assertion { assert(checkbox.isSet?, "Checkbox #{checkbox_name} not checked") }
|
99
112
|
end
|
100
113
|
}
|
101
114
|
end
|
102
|
-
|
115
|
+
|
116
|
+
alias assert_checkbox_checked assert_checkbox_selected
|
103
117
|
|
104
118
|
##
|
105
119
|
# select
|
@@ -107,20 +121,22 @@ module RWebSpec
|
|
107
121
|
@web_browser.select_lists.each { |select|
|
108
122
|
continue unless select.name == select_name
|
109
123
|
select.o.each do |option| # items in the list
|
110
|
-
assert(!(option.value == option_value), "unexpected select option: #{option_value} for #{select_name} found")
|
124
|
+
perform_assertion { assert(!(option.value == option_value), "unexpected select option: #{option_value} for #{select_name} found") }
|
111
125
|
end
|
112
126
|
}
|
113
127
|
end
|
128
|
+
|
114
129
|
alias assert_select_value_not_present assert_option_value_not_present
|
115
130
|
|
116
131
|
def assert_option_not_present(select_name, option_label)
|
117
132
|
@web_browser.select_lists.each { |select|
|
118
133
|
next unless select.name == select_name
|
119
134
|
select.o.each do |option| # items in the list
|
120
|
-
assert(!(option.text == option_label), "unexpected select option: #{option_label} for #{select_name} found")
|
135
|
+
perform_assertion { assert(!(option.text == option_label), "unexpected select option: #{option_label} for #{select_name} found") }
|
121
136
|
end
|
122
137
|
}
|
123
138
|
end
|
139
|
+
|
124
140
|
alias assert_select_label_not_present assert_option_not_present
|
125
141
|
|
126
142
|
def assert_option_value_present(select_name, option_value)
|
@@ -130,9 +146,11 @@ module RWebSpec
|
|
130
146
|
return if option.value == option_value
|
131
147
|
end
|
132
148
|
}
|
133
|
-
|
149
|
+
fail("can't find the combo box with value: #{option_value}")
|
134
150
|
end
|
151
|
+
|
135
152
|
alias assert_select_value_present assert_option_value_present
|
153
|
+
alias assert_menu_value_present assert_option_value_present
|
136
154
|
|
137
155
|
def assert_option_present(select_name, option_label)
|
138
156
|
@web_browser.select_lists.each { |select|
|
@@ -141,30 +159,36 @@ module RWebSpec
|
|
141
159
|
return if option.text == option_label
|
142
160
|
end
|
143
161
|
}
|
144
|
-
|
162
|
+
fail("can't find the combob box: #{select_name} with value: #{option_label}")
|
145
163
|
end
|
164
|
+
|
146
165
|
alias assert_select_label_present assert_option_present
|
166
|
+
alias assert_menu_label_present assert_option_present
|
147
167
|
|
148
168
|
def assert_option_equals(select_name, option_label)
|
149
169
|
@web_browser.select_lists.each { |select|
|
150
170
|
next unless select.name == select_name
|
151
171
|
select.o.each do |option| # items in the list
|
152
172
|
if (option.text == option_label) then
|
153
|
-
assert_equal(select.value, option.value, "Select #{select_name}'s value is not equal to expected option label: '#{option_label}'")
|
173
|
+
perform_assertion { assert_equal(select.value, option.value, "Select #{select_name}'s value is not equal to expected option label: '#{option_label}'") }
|
154
174
|
end
|
155
175
|
end
|
156
176
|
}
|
157
177
|
end
|
178
|
+
|
158
179
|
alias assert_select_label assert_option_equals
|
180
|
+
alias assert_menu_label assert_option_equals
|
159
181
|
|
160
182
|
def assert_option_value_equals(select_name, option_value)
|
161
183
|
@web_browser.select_lists.each { |select|
|
162
184
|
next unless select.name == select_name
|
163
|
-
assert_equal(select.value, option_value, "Select #{select_name}'s value is not equal to expected: '#{option_value}'")
|
185
|
+
perform_assertion { assert_equal(select.value, option_value, "Select #{select_name}'s value is not equal to expected: '#{option_value}'") }
|
164
186
|
}
|
165
187
|
end
|
188
|
+
|
166
189
|
alias assert_select_value assert_option_value_equals
|
167
|
-
|
190
|
+
alias assert_menu_value assert_option_value_equals
|
191
|
+
|
168
192
|
##
|
169
193
|
# radio
|
170
194
|
|
@@ -172,11 +196,11 @@ module RWebSpec
|
|
172
196
|
def assert_radio_option_not_present(radio_group, radio_option)
|
173
197
|
@web_browser.radios.each { |radio|
|
174
198
|
if (radio.name == radio_group) then
|
175
|
-
assert(!(radio_option == radio.value), "unexpected radio option: " + radio_option + " found")
|
199
|
+
perform_assertion { assert(!(radio_option == radio.value), "unexpected radio option: " + radio_option + " found") }
|
176
200
|
end
|
177
201
|
}
|
178
202
|
end
|
179
|
-
|
203
|
+
|
180
204
|
def assert_radio_option_present(radio_group, radio_option)
|
181
205
|
@web_browser.radios.each { |radio|
|
182
206
|
return if (radio.name == radio_group) and (radio_option == radio.value)
|
@@ -187,34 +211,36 @@ module RWebSpec
|
|
187
211
|
def assert_radio_option_selected(radio_group, radio_option)
|
188
212
|
@web_browser.radios.each { |radio|
|
189
213
|
if (radio.name == radio_group and radio_option == radio.value) then
|
190
|
-
assert(radio.isSet?, "Radio button #{radio_group}-[#{radio_option}] not checked")
|
214
|
+
perform_assertion { assert(radio.isSet?, "Radio button #{radio_group}-[#{radio_option}] not checked") }
|
191
215
|
end
|
192
216
|
}
|
193
217
|
end
|
194
|
-
|
195
|
-
|
196
|
-
|
218
|
+
|
219
|
+
alias assert_radio_button_checked assert_radio_option_selected
|
220
|
+
alias assert_radio_option_checked assert_radio_option_selected
|
221
|
+
|
197
222
|
def assert_radio_option_not_selected(radio_group, radio_option)
|
198
223
|
@web_browser.radios.each { |radio|
|
199
224
|
if (radio.name == radio_group and radio_option == radio.value) then
|
200
|
-
assert(!radio.isSet?, "Radio button #{radio_group}-[#{radio_option}] checked unexpected")
|
225
|
+
perform_assertion { assert(!radio.isSet?, "Radio button #{radio_group}-[#{radio_option}] checked unexpected") }
|
201
226
|
end
|
202
227
|
}
|
203
228
|
end
|
229
|
+
|
204
230
|
alias assert_radio_button_not_checked assert_radio_option_not_selected
|
205
231
|
alias assert_radio_option_not_checked assert_radio_option_not_selected
|
206
|
-
|
232
|
+
|
207
233
|
##
|
208
234
|
# Button
|
209
235
|
def assert_button_not_present(button_id)
|
210
236
|
@web_browser.buttons.each { |button|
|
211
|
-
assert(button.id != button_id, "unexpected button id: #{button_id} found")
|
237
|
+
perform_assertion { assert(button.id != button_id, "unexpected button id: #{button_id} found") }
|
212
238
|
}
|
213
239
|
end
|
214
240
|
|
215
241
|
def assert_button_not_present_with_text(text)
|
216
242
|
@web_browser.buttons.each { |button|
|
217
|
-
assert(button.value != text, "unexpected button id: #{text} found")
|
243
|
+
perform_assertion { assert(button.value != text, "unexpected button id: #{text} found") }
|
218
244
|
}
|
219
245
|
end
|
220
246
|
|
@@ -222,44 +248,37 @@ module RWebSpec
|
|
222
248
|
@web_browser.buttons.each { |button|
|
223
249
|
return if button_id == button.id
|
224
250
|
}
|
225
|
-
|
251
|
+
fail("can't find the button with id: #{button_id}")
|
226
252
|
end
|
227
253
|
|
228
254
|
def assert_button_present_with_text(button_text)
|
229
255
|
@web_browser.buttons.each { |button|
|
230
256
|
return if button_text == button.value
|
231
257
|
}
|
232
|
-
|
258
|
+
fail("can't find the button with text: #{button_text}")
|
233
259
|
end
|
234
260
|
|
235
261
|
|
236
262
|
def assert_equals(expected, actual, msg=nil)
|
237
|
-
assert(expected == actual, (msg.nil?) ? "Expected: #{expected} diff from actual: #{actual}" : msg)
|
263
|
+
perform_assertion { assert(expected == actual, (msg.nil?) ? "Expected: #{expected} diff from actual: #{actual}" : msg) }
|
238
264
|
end
|
239
265
|
|
240
266
|
|
241
|
-
|
242
267
|
# Check a HTML element exists or not
|
243
268
|
# Example:
|
244
269
|
# assert_exists("label", "receipt_date")
|
245
270
|
# assert_exists(:span, :receipt_date)
|
246
|
-
def assert_exists(tag, element_id)
|
247
|
-
|
248
|
-
assert eval("#{tag}(:id, '#{element_id.to_s}').exists?")
|
249
|
-
rescue => e
|
250
|
-
raise "Element '#{tag}' with id: '#{element_id}' not found, #{e}"
|
251
|
-
end
|
271
|
+
def assert_exists(tag, element_id)
|
272
|
+
perform_assertion { assert(eval("#{tag}(:id, '#{element_id.to_s}').exists?"), "Element '#{tag}' with id: '#{element_id}' not found") }
|
252
273
|
end
|
274
|
+
|
253
275
|
alias assert_exists? assert_exists
|
254
276
|
alias assert_element_exists assert_exists
|
255
277
|
|
256
|
-
def assert_not_exists(tag, element_id)
|
257
|
-
|
258
|
-
assert_not eval("#{tag}(:id, '#{element_id.to_s}').exists?")
|
259
|
-
raise "Unexpected element'#{tag}' + with id: '#{element_id}' found"
|
260
|
-
rescue => e
|
261
|
-
end
|
278
|
+
def assert_not_exists(tag, element_id)
|
279
|
+
perform_assertion { assert_not(eval("#{tag}(:id, '#{element_id.to_s}').exists?"), "Unexpected element'#{tag}' + with id: '#{element_id}' found")}
|
262
280
|
end
|
281
|
+
|
263
282
|
alias assert_not_exists? assert_not_exists
|
264
283
|
alias assert_element_not_exists? assert_not_exists
|
265
284
|
|
@@ -268,23 +287,16 @@ module RWebSpec
|
|
268
287
|
# assert_visible(:div, "public_notice")
|
269
288
|
# assert_visible(:span, "public_span")
|
270
289
|
def assert_visible(tag, element_id)
|
271
|
-
|
272
|
-
assert(eval("#{tag}(:id, '#{element_id.to_s}').visible?"))
|
273
|
-
rescue => e
|
274
|
-
raise "Element '#{tag}' with id: '#{element_id}' not visible, #{e}"
|
275
|
-
end
|
290
|
+
perform_assertion { assert(eval("#{tag}(:id, '#{element_id.to_s}').visible?"), "Element '#{tag}' with id: '#{element_id}' not visible") }
|
276
291
|
end
|
277
292
|
|
278
293
|
# Assert tag with element id is hidden?, example
|
279
294
|
# assert_hidden(:div, "secret")
|
280
295
|
# assert_hidden(:span, "secret_span")
|
281
296
|
def assert_hidden(tag, element_id)
|
282
|
-
|
283
|
-
assert(!eval("#{tag}(:id, '#{element_id.to_s}').visible?"))
|
284
|
-
rescue => e
|
285
|
-
raise "Element '#{tag}' with id: '#{element_id}' is visible, #{e}"
|
286
|
-
end
|
297
|
+
perform_assertion { assert(!eval("#{tag}(:id, '#{element_id.to_s}').visible?"), "Element '#{tag}' with id: '#{element_id}' is visible") }
|
287
298
|
end
|
299
|
+
|
288
300
|
alias assert_not_visible assert_hidden
|
289
301
|
|
290
302
|
|
@@ -312,13 +324,15 @@ module RWebSpec
|
|
312
324
|
# assert_text_present_in_table("t1", ">A<") # => true
|
313
325
|
# assert_text_present_in_table("t1", ">A<", :just_plain_text => true) # => false
|
314
326
|
def assert_text_present_in_table(table_id, text, options = { :just_plain_text => false })
|
315
|
-
assert(table_source(table_id, options).include?(text),
|
327
|
+
perform_assertion { assert(table_source(table_id, options).include?(text), "the text #{text} not found in table #{table_id}") }
|
316
328
|
end
|
329
|
+
|
317
330
|
alias assert_text_in_table assert_text_present_in_table
|
318
331
|
|
319
332
|
def assert_text_not_present_in_table(table_id, text, options = { :just_plain_text => false })
|
320
|
-
assert_not(table_source(table_id, options).include?(text),
|
333
|
+
perform_assertion { assert_not(table_source(table_id, options).include?(text), "the text #{text} not found in table #{table_id}") }
|
321
334
|
end
|
335
|
+
|
322
336
|
alias assert_text_not_in_table assert_text_not_present_in_table
|
323
337
|
|
324
338
|
# Assert a text field (with given name) has the value
|
@@ -328,17 +342,17 @@ module RWebSpec
|
|
328
342
|
# assert_text_field_value("text1", "text already there") => true
|
329
343
|
#
|
330
344
|
def assert_text_field_value(textfield_name, text)
|
331
|
-
assert_equal(text, text_field(:name, textfield_name).value)
|
345
|
+
perform_assertion { assert_equal(text, text_field(:name, textfield_name).value) }
|
332
346
|
end
|
333
347
|
|
334
|
-
|
348
|
+
|
335
349
|
#-- Not tested
|
336
350
|
# -----
|
337
|
-
|
351
|
+
|
338
352
|
def assert_text_in_element(element_id, text)
|
339
353
|
elem = element_by_id(element_id)
|
340
354
|
assert_not_nil(elem.innerText, "element #{element_id} has no text")
|
341
|
-
assert(elem.innerText.include?(text), "the text #{text} not found in element #{element_id}")
|
355
|
+
perform_assertion { assert(elem.innerText.include?(text), "the text #{text} not found in element #{element_id}") }
|
342
356
|
end
|
343
357
|
|
344
358
|
# Use
|
@@ -348,14 +362,25 @@ module RWebSpec
|
|
348
362
|
# def assert_position_in_list(list_element_id)
|
349
363
|
# raise "not implemented"
|
350
364
|
# end
|
351
|
-
|
365
|
+
|
352
366
|
private
|
353
367
|
def table_source(table_id, options)
|
354
|
-
|
355
|
-
elem_table_text = elem_table.text
|
368
|
+
elem_table = table(:id, table_id.to_s)
|
369
|
+
elem_table_text = elem_table.text
|
356
370
|
elem_table_html = is_firefox? ? elem_table.innerHTML : elem_table.html
|
357
371
|
table_source = options[:just_plain_text] ? elem_table_text : elem_table_html
|
358
372
|
end
|
359
|
-
|
373
|
+
|
374
|
+
|
375
|
+
def perform_assertion(&block)
|
376
|
+
begin
|
377
|
+
yield
|
378
|
+
rescue StandardError => e
|
379
|
+
# puts "[DEBUG] Assertion error: #{e}"
|
380
|
+
take_screenshot
|
381
|
+
raise e
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
360
385
|
end
|
361
386
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'active_record' # change rwebspec/database
|
2
|
+
|
3
|
+
module RWebSpec
|
4
|
+
module DatabaseChecker
|
5
|
+
|
6
|
+
# Example
|
7
|
+
# connect_to_database mysql_db(:host => "localhost", :database => "lavabuild_local", :user => "root", :password => ""), true
|
8
|
+
def mysql_db(settings)
|
9
|
+
options = {:adapter => "mysql"}
|
10
|
+
options.merge!(settings)
|
11
|
+
end
|
12
|
+
|
13
|
+
# connect_to_database sqlite3_db(:database => File.join(File.dirname(__FILE__), "testdata", "sample.sqlite3")), true
|
14
|
+
def sqlite3_db(settings)
|
15
|
+
options = {:adapter => "sqlite3"}
|
16
|
+
options.merge!(settings)
|
17
|
+
end
|
18
|
+
|
19
|
+
def sqlserver_db(settings)
|
20
|
+
options = {:adapter => "sqlserver"}
|
21
|
+
options[:username] ||= settings[:user]
|
22
|
+
options.merge!(settings)
|
23
|
+
end
|
24
|
+
|
25
|
+
def sqlserver_db_dbi(options)
|
26
|
+
options[:user] ||= options[:username]
|
27
|
+
options[:username] ||= options[:user]
|
28
|
+
conn_str = "DBI:ADO:Provider=SQLOLEDB;Data Source=#{options[:host]};Initial Catalog=#{options[:database]};User ID=\"#{options[:user]}\";password=\"#{options[:password]}\" "
|
29
|
+
dbh = DBI.connect(conn_str)
|
30
|
+
end
|
31
|
+
|
32
|
+
def clear_database_connection
|
33
|
+
begin
|
34
|
+
ActiveRecord::Base.remove_connection
|
35
|
+
rescue => e
|
36
|
+
puts "failed o clear database connection: #{e}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Connect to databse, example
|
41
|
+
# mysql_db(:host => "localhost", :database => "lavabuild_local", :user => "root", :password => "")
|
42
|
+
def connect_to_database(db_settings, force = false)
|
43
|
+
# only setup database connection once
|
44
|
+
if force
|
45
|
+
ActiveRecord::Base.establish_connection(db_settings)
|
46
|
+
else
|
47
|
+
begin
|
48
|
+
ActiveRecord::Base.connection
|
49
|
+
rescue => e
|
50
|
+
require 'pp'
|
51
|
+
pp db_settings
|
52
|
+
puts "failed to connect: #{e}"
|
53
|
+
ActiveRecord::Base.establish_connection(db_settings)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_table(table_name)
|
59
|
+
begin
|
60
|
+
ActiveRecord::Base.connection
|
61
|
+
rescue =>e
|
62
|
+
raise "No database connection setup yet, use connect_to_database() method"
|
63
|
+
end
|
64
|
+
class_name = table_name.classify
|
65
|
+
# define the class, so can use ActiveRecord in
|
66
|
+
# such as
|
67
|
+
# Perosn.count.should == 2
|
68
|
+
def_class = "class ::#{class_name} < ActiveRecord::Base; end"
|
69
|
+
eval def_class
|
70
|
+
return def_class
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|