cornucopia 0.1.12
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.
- checksums.yaml +7 -0
- data/.gitignore +51 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +16 -0
- data/LICENSE.TXT +22 -0
- data/README.md +341 -0
- data/Rakefile +18 -0
- data/cornucopia.gemspec +39 -0
- data/lib/cornucopia.rb +18 -0
- data/lib/cornucopia/capybara/finder_diagnostics.rb +536 -0
- data/lib/cornucopia/capybara/finder_extensions.rb +89 -0
- data/lib/cornucopia/capybara/install_finder_extensions.rb +105 -0
- data/lib/cornucopia/capybara/install_matcher_extensions.rb +39 -0
- data/lib/cornucopia/capybara/matcher_extensions.rb +83 -0
- data/lib/cornucopia/capybara/page_diagnostics.rb +228 -0
- data/lib/cornucopia/cucumber_hooks.rb +38 -0
- data/lib/cornucopia/factory_girl/dynamic_association.rb +14 -0
- data/lib/cornucopia/rspec_hooks.rb +37 -0
- data/lib/cornucopia/site_prism/element_extensions.rb +273 -0
- data/lib/cornucopia/site_prism/install_element_extensions.rb +23 -0
- data/lib/cornucopia/site_prism/page_application.rb +126 -0
- data/lib/cornucopia/source_files/collapse.gif +0 -0
- data/lib/cornucopia/source_files/cornucopia.css +162 -0
- data/lib/cornucopia/source_files/expand.gif +0 -0
- data/lib/cornucopia/source_files/index_base.html +10 -0
- data/lib/cornucopia/source_files/index_contents.html +2 -0
- data/lib/cornucopia/source_files/more_info.js +87 -0
- data/lib/cornucopia/source_files/report_base.html +10 -0
- data/lib/cornucopia/source_files/report_contents.html +3 -0
- data/lib/cornucopia/spinach_hooks.rb +51 -0
- data/lib/cornucopia/util/configuration.rb +493 -0
- data/lib/cornucopia/util/configured_report.rb +520 -0
- data/lib/cornucopia/util/file_asset.rb +46 -0
- data/lib/cornucopia/util/generic_settings.rb +37 -0
- data/lib/cornucopia/util/log_capture.rb +97 -0
- data/lib/cornucopia/util/pretty_formatter.rb +580 -0
- data/lib/cornucopia/util/report_builder.rb +474 -0
- data/lib/cornucopia/util/report_formatters.rb +11 -0
- data/lib/cornucopia/util/report_table.rb +195 -0
- data/lib/cornucopia/version.rb +3 -0
- data/lib/tasks/cornucopia_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +27 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cucumber.yml +8 -0
- data/spec/dummy/config/database.yml +37 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/db/schema.rb +16 -0
- data/spec/dummy/features/support/env.rb +66 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/cucumber.rake +65 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/cucumber +10 -0
- data/spec/fixtures/sample_page.html +150 -0
- data/spec/lib/capybara/finder_diagnostics_spec.rb +517 -0
- data/spec/lib/capybara/finder_extensions_spec.rb +328 -0
- data/spec/lib/capybara/page_diagnostics_spec.rb +277 -0
- data/spec/lib/site_prism/element_extensions_spec.rb +290 -0
- data/spec/lib/site_prism/page_application_spec.rb +81 -0
- data/spec/lib/util/configuration_spec.rb +254 -0
- data/spec/lib/util/configured_report_spec.rb +1058 -0
- data/spec/lib/util/file_asset_spec.rb +86 -0
- data/spec/lib/util/generic_settings_spec.rb +48 -0
- data/spec/lib/util/log_capture_spec.rb +151 -0
- data/spec/lib/util/pretty_formatter_spec.rb +694 -0
- data/spec/lib/util/report_builder_spec.rb +983 -0
- data/spec/lib/util/report_formatters_spec.rb +13 -0
- data/spec/lib/util/report_table_exception_spec.rb +21 -0
- data/spec/lib/util/report_table_spec.rb +319 -0
- data/spec/pages/cornucopia_report_app.rb +10 -0
- data/spec/pages/google/email_page.rb +22 -0
- data/spec/pages/google/login_page.rb +25 -0
- data/spec/rails_helper.rb +43 -0
- data/spec/sample_report.rb +45 -0
- data/spec/spec_helper.rb +81 -0
- metadata +410 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require ::File.expand_path("../../../lib/cornucopia/capybara/finder_extensions", File.dirname(__FILE__))
|
|
3
|
+
|
|
4
|
+
describe Cornucopia::Capybara::FinderExtensions, type: :feature do
|
|
5
|
+
# Make sure that all tests start clean and get cleaned up afterwards...
|
|
6
|
+
around(:example) do |example|
|
|
7
|
+
expect(File.directory?(Rails.root.join("cornucopia_report/"))).to be_falsey
|
|
8
|
+
|
|
9
|
+
begin
|
|
10
|
+
@file_name_1 = generate_report_file("report_1")
|
|
11
|
+
|
|
12
|
+
example.run
|
|
13
|
+
ensure
|
|
14
|
+
if (Cornucopia::Util::ReportBuilder.class_variable_get("@@current_report"))
|
|
15
|
+
Cornucopia::Util::ReportBuilder.current_report.close
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
::Capybara.current_session.driver.window_handles.each do |handle|
|
|
19
|
+
if handle != ::Capybara.current_session.driver.current_window_handle
|
|
20
|
+
::Capybara.current_session.driver.close_window(handle)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
FileUtils.rm_rf Rails.root.join("cornucopia_report/")
|
|
25
|
+
FileUtils.rm_rf Rails.root.join("sample_report/")
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
before(:context) do
|
|
30
|
+
@file_name_1 = generate_report_file("report_1")
|
|
31
|
+
::Capybara.app = Rack::File.new File.absolute_path(File.join(File.dirname(@file_name_1), "../.."))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "#__cornucopia_finder_function" do
|
|
35
|
+
it "should retry if a Selenium cache error is thrown" do
|
|
36
|
+
index_page = CornucopiaReportApp.index_page
|
|
37
|
+
|
|
38
|
+
index_page.load base_folder: "sample_report"
|
|
39
|
+
|
|
40
|
+
index_page.contents do |contents_frame|
|
|
41
|
+
found_elements = contents_frame.all("a", __cornucopia_no_analysis: true)
|
|
42
|
+
|
|
43
|
+
num_retries = rand(1..(Cornucopia::Util::Configuration.selenium_cache_retry_count - 1))
|
|
44
|
+
time_count = num_retries
|
|
45
|
+
num_calls = 0
|
|
46
|
+
|
|
47
|
+
allow(contents_frame.page.document).
|
|
48
|
+
to receive(:__cornucopia_orig_all) do |*args|
|
|
49
|
+
num_calls += 1
|
|
50
|
+
|
|
51
|
+
if time_count > 0
|
|
52
|
+
time_count -= 1
|
|
53
|
+
raise Selenium::WebDriver::Error::StaleElementReferenceError.new
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
expect(args).to be == ["a"]
|
|
57
|
+
found_elements
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
second_found = contents_frame.all("a")
|
|
61
|
+
|
|
62
|
+
allow(contents_frame.page.document).
|
|
63
|
+
to receive(:__cornucopia_orig_all).
|
|
64
|
+
and_call_original
|
|
65
|
+
|
|
66
|
+
# I realize that this is almost like testing that the stub worked, which we don't need to test.
|
|
67
|
+
# However, we are really testing that the results returned by the stub are passed back all the way
|
|
68
|
+
# Which we do need to test.
|
|
69
|
+
expect(second_found).to be == found_elements
|
|
70
|
+
expect(time_count).to be == 0
|
|
71
|
+
expect(num_calls).to be == num_retries + 1
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "should call __cornucopia__analyze_finder if it cannot resolve the stale reference" do
|
|
76
|
+
index_page = CornucopiaReportApp.index_page
|
|
77
|
+
|
|
78
|
+
index_page.load base_folder: "sample_report"
|
|
79
|
+
|
|
80
|
+
index_page.contents do |contents_frame|
|
|
81
|
+
found_elements = contents_frame.all("a", __cornucopia_no_analysis: true)
|
|
82
|
+
|
|
83
|
+
# Because we are over riding the original call, we just stub this out
|
|
84
|
+
# because it cannot work properly.
|
|
85
|
+
expect(contents_frame.page.document).
|
|
86
|
+
to receive(:__cornucopia__analyze_finder).
|
|
87
|
+
and_return(found_elements)
|
|
88
|
+
|
|
89
|
+
allow(contents_frame.page.document).
|
|
90
|
+
to receive(:__cornucopia_orig_all) do |*args|
|
|
91
|
+
raise Selenium::WebDriver::Error::StaleElementReferenceError.new
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
second_found = contents_frame.all("a")
|
|
95
|
+
|
|
96
|
+
allow(contents_frame.page.document).
|
|
97
|
+
to receive(:__cornucopia_orig_all).
|
|
98
|
+
and_call_original
|
|
99
|
+
|
|
100
|
+
# I realize that this is almost like testing that the stub worked, which we don't need to test.
|
|
101
|
+
# However, we are really testing that the results returned by the stub are passed back all the way
|
|
102
|
+
# Which we do need to test.
|
|
103
|
+
expect(second_found).to be == found_elements
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "should call __cornucopia__analyze_finder if an exception is thrown" do
|
|
108
|
+
index_page = CornucopiaReportApp.index_page
|
|
109
|
+
|
|
110
|
+
index_page.load base_folder: "sample_report"
|
|
111
|
+
|
|
112
|
+
index_page.contents do |contents_frame|
|
|
113
|
+
found_elements = contents_frame.find(".report-block", __cornucopia_no_analysis: true)
|
|
114
|
+
|
|
115
|
+
# Because we are over riding the original call, we just stub this out
|
|
116
|
+
# because it cannot work properly.
|
|
117
|
+
expect(contents_frame.page.document).
|
|
118
|
+
to receive(:__cornucopia__analyze_finder).
|
|
119
|
+
and_return(found_elements)
|
|
120
|
+
|
|
121
|
+
allow(contents_frame.page.document).
|
|
122
|
+
to receive(:__cornucopia_orig_find) do |*args|
|
|
123
|
+
raise "This is an error"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
second_found = contents_frame.find(".report-block")
|
|
127
|
+
|
|
128
|
+
allow(contents_frame.page.document).
|
|
129
|
+
to receive(:__cornucopia_orig_find).
|
|
130
|
+
and_call_original
|
|
131
|
+
|
|
132
|
+
# I realize that this is almost like testing that the stub worked, which we don't need to test.
|
|
133
|
+
# However, we are really testing that the results returned by the stub are passed back all the way
|
|
134
|
+
# Which we do need to test.
|
|
135
|
+
expect(second_found).to be == found_elements
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
describe "#synchronize_test" do
|
|
141
|
+
it "synchronizes a random test condition" do
|
|
142
|
+
index_page = CornucopiaReportApp.index_page
|
|
143
|
+
|
|
144
|
+
index_page.load base_folder: "sample_report"
|
|
145
|
+
|
|
146
|
+
expect do
|
|
147
|
+
::Capybara.current_session.synchronize_test do
|
|
148
|
+
sleep(::Capybara.default_wait_time - 0.5)
|
|
149
|
+
true
|
|
150
|
+
end
|
|
151
|
+
end.not_to raise_exception
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it "will time out on a random test condition" do
|
|
155
|
+
index_page = CornucopiaReportApp.index_page
|
|
156
|
+
|
|
157
|
+
index_page.load base_folder: "sample_report"
|
|
158
|
+
|
|
159
|
+
expect do
|
|
160
|
+
::Capybara.current_session.synchronize_test do
|
|
161
|
+
sleep(0.05)
|
|
162
|
+
false
|
|
163
|
+
end
|
|
164
|
+
end.to raise_error(::Capybara::ElementNotFound)
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def get_object(object_type)
|
|
169
|
+
case (object_type)
|
|
170
|
+
when :page
|
|
171
|
+
::Capybara.page
|
|
172
|
+
|
|
173
|
+
when :document
|
|
174
|
+
::Capybara.page.document
|
|
175
|
+
|
|
176
|
+
when :body
|
|
177
|
+
::Capybara.page.document.find("html")
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
[:page, :document, :body].each do |object_type|
|
|
182
|
+
describe "#__cornucopia__analyze_finder for #{object_type}" do
|
|
183
|
+
it "does nothing if this is called from the analysis function" do
|
|
184
|
+
index_page = CornucopiaReportApp.index_page
|
|
185
|
+
|
|
186
|
+
index_page.load base_folder: "sample_report"
|
|
187
|
+
|
|
188
|
+
Cornucopia::Util::Configuration.analyze_find_exceptions = true
|
|
189
|
+
|
|
190
|
+
expect(Cornucopia::Capybara::FinderDiagnostics::FindAction).not_to receive(:new)
|
|
191
|
+
|
|
192
|
+
expect { get_object(object_type).find "boody", __cornucopia_no_analysis: true }.
|
|
193
|
+
to raise_error(::Capybara::ElementNotFound)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "does nothing if configuration is turned off" do
|
|
197
|
+
begin
|
|
198
|
+
index_page = CornucopiaReportApp.index_page
|
|
199
|
+
|
|
200
|
+
index_page.load base_folder: "sample_report"
|
|
201
|
+
|
|
202
|
+
Cornucopia::Util::Configuration.analyze_find_exceptions = false
|
|
203
|
+
|
|
204
|
+
expect(Cornucopia::Capybara::FinderDiagnostics::FindAction).not_to receive(:new)
|
|
205
|
+
|
|
206
|
+
expect { get_object(object_type).find "boody" }.to raise_error(::Capybara::ElementNotFound)
|
|
207
|
+
ensure
|
|
208
|
+
Cornucopia::Util::Configuration.analyze_find_exceptions = true
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it "calls perform analysis with values from the configuration and returns the results" do
|
|
213
|
+
begin
|
|
214
|
+
index_page = CornucopiaReportApp.index_page
|
|
215
|
+
|
|
216
|
+
index_page.load base_folder: "sample_report"
|
|
217
|
+
|
|
218
|
+
Cornucopia::Util::Configuration.analyze_find_exceptions = true
|
|
219
|
+
|
|
220
|
+
the_obj = get_object(object_type)
|
|
221
|
+
stubbed_finder = Cornucopia::Capybara::FinderDiagnostics::FindAction.new(the_obj, {}, {}, "boody")
|
|
222
|
+
found_body = the_obj.find("body")
|
|
223
|
+
|
|
224
|
+
expect(Cornucopia::Capybara::FinderDiagnostics::FindAction).to receive(:new).and_return(stubbed_finder)
|
|
225
|
+
|
|
226
|
+
retry_found = [true, false].sample
|
|
227
|
+
# retry_alt = [true, false].sample
|
|
228
|
+
|
|
229
|
+
Cornucopia::Util::Configuration.retry_with_found = retry_found
|
|
230
|
+
# Cornucopia::Util::Configuration.alternate_retry = retry_alt
|
|
231
|
+
|
|
232
|
+
retry_found = retry_found || nil
|
|
233
|
+
# retry_alt = retry_alt || nil
|
|
234
|
+
|
|
235
|
+
expect(stubbed_finder).to receive(:perform_analysis).with(retry_found).and_return true
|
|
236
|
+
expect(stubbed_finder).to receive(:return_value).and_return found_body
|
|
237
|
+
|
|
238
|
+
expect(the_obj.find("boody")).to be == found_body
|
|
239
|
+
ensure
|
|
240
|
+
Cornucopia::Util::Configuration.retry_with_found = false
|
|
241
|
+
# Cornucopia::Util::Configuration.alternate_retry = false
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it "re-raises the last error if the analysis doesn't find anything" do
|
|
246
|
+
begin
|
|
247
|
+
index_page = CornucopiaReportApp.index_page
|
|
248
|
+
|
|
249
|
+
index_page.load base_folder: "sample_report"
|
|
250
|
+
|
|
251
|
+
Cornucopia::Util::Configuration.analyze_find_exceptions = true
|
|
252
|
+
|
|
253
|
+
the_obj = get_object(object_type)
|
|
254
|
+
stubbed_finder = Cornucopia::Capybara::FinderDiagnostics::FindAction.new(the_obj, {}, {}, "boody")
|
|
255
|
+
found_body = the_obj.find("body")
|
|
256
|
+
|
|
257
|
+
expect(Cornucopia::Capybara::FinderDiagnostics::FindAction).to receive(:new).and_return(stubbed_finder)
|
|
258
|
+
|
|
259
|
+
retry_found = [true, false].sample
|
|
260
|
+
# retry_alt = [true, false].sample
|
|
261
|
+
|
|
262
|
+
Cornucopia::Util::Configuration.retry_with_found = retry_found
|
|
263
|
+
# Cornucopia::Util::Configuration.alternate_retry = retry_alt
|
|
264
|
+
|
|
265
|
+
retry_found = retry_found || nil
|
|
266
|
+
# retry_alt = retry_alt || nil
|
|
267
|
+
|
|
268
|
+
expect(stubbed_finder).to receive(:perform_analysis).with(retry_found).and_return false
|
|
269
|
+
|
|
270
|
+
expect { (the_obj.find("boody")) }.to raise_error(::Capybara::ElementNotFound)
|
|
271
|
+
ensure
|
|
272
|
+
Cornucopia::Util::Configuration.retry_with_found = false
|
|
273
|
+
# Cornucopia::Util::Configuration.alternate_retry = false
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
describe "#select_value" do
|
|
280
|
+
# Make sure that all tests start clean and get cleaned up afterwards...
|
|
281
|
+
around(:example) do |example|
|
|
282
|
+
expect(File.directory?(Rails.root.join("cornucopia_report/"))).to be_falsey
|
|
283
|
+
|
|
284
|
+
begin
|
|
285
|
+
@file_name_1 = generate_report_file("report_1")
|
|
286
|
+
|
|
287
|
+
example.run
|
|
288
|
+
ensure
|
|
289
|
+
if (Cornucopia::Util::ReportBuilder.class_variable_get("@@current_report"))
|
|
290
|
+
Cornucopia::Util::ReportBuilder.current_report.close
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
::Capybara.current_session.driver.window_handles.each do |handle|
|
|
294
|
+
if handle != ::Capybara.current_session.driver.current_window_handle
|
|
295
|
+
::Capybara.current_session.driver.close_window(handle)
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
FileUtils.rm_rf Rails.root.join("cornucopia_report/")
|
|
300
|
+
FileUtils.rm_rf Rails.root.join("sample_report/")
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
let(:base_folder) { File.absolute_path(File.join(File.dirname(@file_name_1), "../..")) }
|
|
305
|
+
|
|
306
|
+
it "selects based on the value" do
|
|
307
|
+
Cornucopia::Util::FileAsset.new("../../../spec/fixtures/sample_page.html").
|
|
308
|
+
create_file(File.join(base_folder, "sample_report/sample_file.html"))
|
|
309
|
+
|
|
310
|
+
::Capybara.current_session.visit("/sample_report/sample_file.html")
|
|
311
|
+
sel_value = rand(0..19)
|
|
312
|
+
::Capybara.page.find("\#select-box").select_value(sel_value)
|
|
313
|
+
expect(::Capybara.page.find("\#select-box").value).to eq sel_value.to_s
|
|
314
|
+
expect(::Capybara.page.find("\#select-box").value_text).to eq (sel_value + 100).to_s
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
it "multi-selects based on the value" do
|
|
318
|
+
Cornucopia::Util::FileAsset.new("../../../spec/fixtures/sample_page.html").
|
|
319
|
+
create_file(File.join(base_folder, "sample_report/sample_file.html"))
|
|
320
|
+
|
|
321
|
+
::Capybara.current_session.visit("/sample_report/sample_file.html")
|
|
322
|
+
sel_value = (0..19).to_a.sample(3).sort
|
|
323
|
+
::Capybara.page.find("\#multi-select-box").select_value(sel_value)
|
|
324
|
+
expect(::Capybara.page.find("\#multi-select-box").value).to eq sel_value.map(&:to_s)
|
|
325
|
+
expect(::Capybara.page.find("\#multi-select-box").value_text).to eq sel_value.map { |value| (value + 200).to_s }
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
end
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require 'rack/file'
|
|
3
|
+
require ::File.expand_path("../../../lib/cornucopia/util/report_builder", File.dirname(__FILE__))
|
|
4
|
+
require ::File.expand_path("../../../lib/cornucopia/capybara/page_diagnostics", File.dirname(__FILE__))
|
|
5
|
+
require ::File.expand_path("../../../lib/cornucopia/capybara/finder_extensions", File.dirname(__FILE__))
|
|
6
|
+
require ::File.expand_path("../../../lib/cornucopia/capybara/matcher_extensions", File.dirname(__FILE__))
|
|
7
|
+
|
|
8
|
+
describe Cornucopia::Capybara::PageDiagnostics, type: :feature do
|
|
9
|
+
# Make sure that all tests start clean and get cleaned up afterwards...
|
|
10
|
+
around(:example) do |example|
|
|
11
|
+
expect(File.directory?(Rails.root.join("cornucopia_report/"))).to be_falsey
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
example.run
|
|
15
|
+
ensure
|
|
16
|
+
if (Cornucopia::Util::ReportBuilder.class_variable_get("@@current_report"))
|
|
17
|
+
Cornucopia::Util::ReportBuilder.current_report.close
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
::Capybara.current_session.driver.window_handles.each do |handle|
|
|
21
|
+
if handle != ::Capybara.current_session.driver.current_window_handle
|
|
22
|
+
::Capybara.current_session.driver.close_window(handle)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
FileUtils.rm_rf Rails.root.join("cornucopia_report/")
|
|
27
|
+
FileUtils.rm_rf Rails.root.join("sample_report/")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe "#dump_page_details" do
|
|
32
|
+
before(:context) do
|
|
33
|
+
file_name_1 = generate_report_file("report_1")
|
|
34
|
+
|
|
35
|
+
::Capybara.app = Rack::File.new File.absolute_path(File.join(File.dirname(file_name_1), ".."))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "does nothing if Capybara isn't open" do
|
|
39
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
40
|
+
|
|
41
|
+
Cornucopia::Capybara::PageDiagnostics.dump_details(report: report)
|
|
42
|
+
|
|
43
|
+
report.close
|
|
44
|
+
|
|
45
|
+
report_text = File.read(report.report_contents_page_name)
|
|
46
|
+
expect(report_text).to match /No Errors to report/
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "can open a page" do
|
|
50
|
+
file_name_1 = generate_report_file("report_1")
|
|
51
|
+
::Capybara.current_session.visit("/report_1/#{File.basename(file_name_1)}")
|
|
52
|
+
::Capybara.page.has_text?(@last_val)
|
|
53
|
+
|
|
54
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
55
|
+
|
|
56
|
+
Cornucopia::Capybara::PageDiagnostics.dump_details(report: report)
|
|
57
|
+
|
|
58
|
+
report.close
|
|
59
|
+
|
|
60
|
+
report_text = File.read(report.report_contents_page_name)
|
|
61
|
+
expect(report_text).not_to match /No Errors to report/
|
|
62
|
+
expect(report_text).to match /\>Page Dump:\</
|
|
63
|
+
expect(report_text).to match /\>\npage_url\n\</
|
|
64
|
+
expect(report_text).to match /\>\ntitle\n\</
|
|
65
|
+
expect(report_text).to match /\>\nscreen_shot\n\</
|
|
66
|
+
expect(report_text).to match /\<img/
|
|
67
|
+
expect(report_text).to match /\>More Details...\</
|
|
68
|
+
expect(report_text).to match /\>\nhtml_frame\n\</
|
|
69
|
+
expect(report_text).to match /\<iframe/
|
|
70
|
+
expect(report_text).to match /\>\nhtml_source\n\</
|
|
71
|
+
expect(report_text).to match /\<textarea/
|
|
72
|
+
expect(report_text).to match /\>\npage_height\n\</
|
|
73
|
+
expect(report_text).to match /\>\npage_width\n\</
|
|
74
|
+
expect(report_text).to match /\>\nhtml_file\n\</
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "can report on multiple pages" do
|
|
78
|
+
file_name_1 = generate_report_file("report_1")
|
|
79
|
+
|
|
80
|
+
::Capybara.current_session.visit("/report_1/#{File.basename(file_name_1)}")
|
|
81
|
+
::Capybara.page.has_text?(@last_val)
|
|
82
|
+
|
|
83
|
+
file_name_2 = generate_report_file("report_2")
|
|
84
|
+
new_handle = ::Capybara.window_opened_by { ::Capybara.current_session.driver.open_new_window }
|
|
85
|
+
::Capybara.current_session.switch_to_window(new_handle)
|
|
86
|
+
::Capybara.current_session.visit("/report_2/#{File.basename(file_name_2)}")
|
|
87
|
+
::Capybara.page.has_text?(@last_val)
|
|
88
|
+
|
|
89
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
90
|
+
|
|
91
|
+
Cornucopia::Capybara::PageDiagnostics.dump_details(report: report)
|
|
92
|
+
|
|
93
|
+
report.close
|
|
94
|
+
|
|
95
|
+
report_text = File.read(report.report_contents_page_name)
|
|
96
|
+
expect(report_text).not_to match /No Errors to report/
|
|
97
|
+
expect(report_text).not_to match /\>\noptions\n\</
|
|
98
|
+
expect(report_text).not_to match /\>\nreport\n\</
|
|
99
|
+
expect(report_text).not_to match /\>\ntable\n\</
|
|
100
|
+
expect(report_text).not_to match /\>\nunsupported_list\n\</
|
|
101
|
+
expect(report_text).not_to match /\>\nallow_other_windows\n\</
|
|
102
|
+
expect(report_text).not_to match /\>\niterating\n\</
|
|
103
|
+
expect(report_text).not_to match /\>\nsession\n\</
|
|
104
|
+
expect(report_text).not_to match /\>\ndriver\n\</
|
|
105
|
+
expect(report_text).not_to match /\>\nwindow_handles\n\</
|
|
106
|
+
expect(report_text).not_to match /\>\ncurrent_window\n\</
|
|
107
|
+
expect(report_text.scan(/\>Page Dump:\</).length).to be == 1
|
|
108
|
+
expect(report_text.scan(/\>\npage_url\n\</).length).to be == 2
|
|
109
|
+
expect(report_text.scan(/\>\ntitle\n\</).length).to be == 2
|
|
110
|
+
expect(report_text.scan(/\>\nscreen_shot\n\</).length).to be == 2
|
|
111
|
+
expect(report_text.scan(/\"cornucopia-section-image\"/).length).to be == 2
|
|
112
|
+
expect(report_text.scan(/\>More Details...\</).length).to be == 1
|
|
113
|
+
expect(report_text.scan(/\>\nhtml_frame\n\</).length).to be == 2
|
|
114
|
+
expect(report_text.scan(/\<iframe/).length).to be == 2
|
|
115
|
+
expect(report_text.scan(/\>\nhtml_source\n\</).length).to be == 2
|
|
116
|
+
expect(report_text.scan(/\<textarea/).length).to be == 2
|
|
117
|
+
expect(report_text.scan(/\>\npage_height\n\</).length).to be == 2
|
|
118
|
+
expect(report_text.scan(/\>\npage_width\n\</).length).to be == 2
|
|
119
|
+
expect(report_text.scan(/\>\nhtml_file\n\</).length).to be == 2
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "only report on a page once" do
|
|
123
|
+
file_name_1 = generate_report_file("report_1")
|
|
124
|
+
::Capybara.current_session.visit("/report_1/#{File.basename(file_name_1)}")
|
|
125
|
+
::Capybara.page.has_text?(@last_val)
|
|
126
|
+
|
|
127
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
128
|
+
|
|
129
|
+
Cornucopia::Capybara::PageDiagnostics.dump_details(report: report)
|
|
130
|
+
Cornucopia::Capybara::PageDiagnostics.dump_details(report: report)
|
|
131
|
+
|
|
132
|
+
report.close
|
|
133
|
+
|
|
134
|
+
report_text = File.read(report.report_contents_page_name)
|
|
135
|
+
expect(report_text).not_to match /No Errors to report/
|
|
136
|
+
expect(report_text).not_to match /\>\noptions\n\</
|
|
137
|
+
expect(report_text).not_to match /\>\nreport\n\</
|
|
138
|
+
expect(report_text).not_to match /\>\ntable\n\</
|
|
139
|
+
expect(report_text).not_to match /\>\nunsupported_list\n\</
|
|
140
|
+
expect(report_text).not_to match /\>\nallow_other_windows\n\</
|
|
141
|
+
expect(report_text).not_to match /\>\niterating\n\</
|
|
142
|
+
expect(report_text).not_to match /\>\nsession\n\</
|
|
143
|
+
expect(report_text).not_to match /\>\ndriver\n\</
|
|
144
|
+
expect(report_text).not_to match /\>\nwindow_handles\n\</
|
|
145
|
+
expect(report_text).not_to match /\>\ncurrent_window\n\</
|
|
146
|
+
expect(report_text.scan(/\>Page Dump:\</).length).to be == 1
|
|
147
|
+
expect(report_text.scan(/\>\npage_url\n\</).length).to be == 1
|
|
148
|
+
expect(report_text.scan(/\>\ntitle\n\</).length).to be == 1
|
|
149
|
+
expect(report_text.scan(/\>\nscreen_shot\n\</).length).to be == 1
|
|
150
|
+
expect(report_text.scan(/\"cornucopia-section-image\"/).length).to be == 1
|
|
151
|
+
expect(report_text.scan(/\>More Details...\</).length).to be == 1
|
|
152
|
+
expect(report_text.scan(/\>\nhtml_frame\n\</).length).to be == 1
|
|
153
|
+
expect(report_text.scan(/\<iframe/).length).to be == 1
|
|
154
|
+
expect(report_text.scan(/\>\nhtml_source\n\</).length).to be == 1
|
|
155
|
+
expect(report_text.scan(/\<textarea/).length).to be == 1
|
|
156
|
+
expect(report_text.scan(/\>\npage_height\n\</).length).to be == 1
|
|
157
|
+
expect(report_text.scan(/\>\npage_width\n\</).length).to be == 1
|
|
158
|
+
expect(report_text.scan(/\>\nhtml_file\n\</).length).to be == 1
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it "will report on page twice in it is in a new report." do
|
|
162
|
+
file_name_1 = generate_report_file("report_1")
|
|
163
|
+
::Capybara.current_session.visit("/report_1/#{File.basename(file_name_1)}")
|
|
164
|
+
::Capybara.page.has_text?(@last_val)
|
|
165
|
+
|
|
166
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
167
|
+
Cornucopia::Capybara::PageDiagnostics.dump_details(report: report)
|
|
168
|
+
report.close
|
|
169
|
+
|
|
170
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
171
|
+
Cornucopia::Capybara::PageDiagnostics.dump_details(report: report)
|
|
172
|
+
report.close
|
|
173
|
+
|
|
174
|
+
report_text = File.read(report.report_contents_page_name)
|
|
175
|
+
expect(report_text).not_to match /No Errors to report/
|
|
176
|
+
expect(report_text).not_to match /\>\noptions\n\</
|
|
177
|
+
expect(report_text).not_to match /\>\nreport\n\</
|
|
178
|
+
expect(report_text).not_to match /\>\ntable\n\</
|
|
179
|
+
expect(report_text).not_to match /\>\nunsupported_list\n\</
|
|
180
|
+
expect(report_text).not_to match /\>\nallow_other_windows\n\</
|
|
181
|
+
expect(report_text).not_to match /\>\niterating\n\</
|
|
182
|
+
expect(report_text).not_to match /\>\nsession\n\</
|
|
183
|
+
expect(report_text).not_to match /\>\ndriver\n\</
|
|
184
|
+
expect(report_text).not_to match /\>\nwindow_handles\n\</
|
|
185
|
+
expect(report_text).not_to match /\>\ncurrent_window\n\</
|
|
186
|
+
expect(report_text.scan(/\>Page Dump:\</).length).to be == 1
|
|
187
|
+
expect(report_text.scan(/\>\npage_url\n\</).length).to be == 1
|
|
188
|
+
expect(report_text.scan(/\>\ntitle\n\</).length).to be == 1
|
|
189
|
+
expect(report_text.scan(/\>\nscreen_shot\n\</).length).to be == 1
|
|
190
|
+
expect(report_text.scan(/\"cornucopia-section-image\"/).length).to be == 1
|
|
191
|
+
expect(report_text.scan(/\>More Details...\</).length).to be == 1
|
|
192
|
+
expect(report_text.scan(/\>\nhtml_frame\n\</).length).to be == 1
|
|
193
|
+
expect(report_text.scan(/\<iframe/).length).to be == 1
|
|
194
|
+
expect(report_text.scan(/\>\nhtml_source\n\</).length).to be == 1
|
|
195
|
+
expect(report_text.scan(/\<textarea/).length).to be == 1
|
|
196
|
+
expect(report_text.scan(/\>\npage_height\n\</).length).to be == 1
|
|
197
|
+
expect(report_text.scan(/\>\npage_width\n\</).length).to be == 1
|
|
198
|
+
expect(report_text.scan(/\>\nhtml_file\n\</).length).to be == 1
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it "can take a section title" do
|
|
202
|
+
file_name_1 = generate_report_file("report_1")
|
|
203
|
+
::Capybara.current_session.visit("/report_1/#{File.basename(file_name_1)}")
|
|
204
|
+
::Capybara.page.has_text?(@last_val)
|
|
205
|
+
|
|
206
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
207
|
+
|
|
208
|
+
Cornucopia::Capybara::PageDiagnostics.dump_details(report: report, section_label: "Super cool report dump:")
|
|
209
|
+
|
|
210
|
+
report.close
|
|
211
|
+
|
|
212
|
+
report_text = File.read(report.report_contents_page_name)
|
|
213
|
+
expect(report_text).not_to match /No Errors to report/
|
|
214
|
+
expect(report_text.scan(/\>Super cool report dump:\</).length).to be == 1
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it "can deal with it if the image cannot be exported" do
|
|
218
|
+
file_name_1 = generate_report_file("report_1")
|
|
219
|
+
::Capybara.current_session.visit("/report_1/#{File.basename(file_name_1)}")
|
|
220
|
+
::Capybara.page.has_text?(@last_val)
|
|
221
|
+
|
|
222
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
223
|
+
|
|
224
|
+
allow_any_instance_of(Cornucopia::Capybara::PageDiagnostics).
|
|
225
|
+
to receive(:execute_driver_function).and_call_original
|
|
226
|
+
|
|
227
|
+
allow_any_instance_of(Cornucopia::Capybara::PageDiagnostics).
|
|
228
|
+
to receive(:execute_driver_function).
|
|
229
|
+
with(:save_screenshot, nil, File.join(report.report_folder_name, "temporary_folder", "screen_shot.png")).
|
|
230
|
+
and_return nil
|
|
231
|
+
|
|
232
|
+
Cornucopia::Capybara::PageDiagnostics.dump_details(report: report, section_label: "Super cool report dump:")
|
|
233
|
+
|
|
234
|
+
report.close
|
|
235
|
+
|
|
236
|
+
report_text = File.read(report.report_contents_page_name)
|
|
237
|
+
expect(report_text).not_to match /No Errors to report/
|
|
238
|
+
expect(report_text.scan(/\>Super cool report dump:\</).length).to be == 1
|
|
239
|
+
expect(report_text).to match /Could not save screen_shot./
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
it "puts the details in an existing report table" do
|
|
243
|
+
file_name_1 = generate_report_file("report_1")
|
|
244
|
+
::Capybara.current_session.visit("/report_1/#{File.basename(file_name_1)}")
|
|
245
|
+
::Capybara.page.has_text?(@last_val)
|
|
246
|
+
|
|
247
|
+
report = Cornucopia::Util::ReportBuilder.current_report
|
|
248
|
+
|
|
249
|
+
report.within_section("an existing section") do |section|
|
|
250
|
+
section.within_table do |table|
|
|
251
|
+
table.write_stats "something", "a value"
|
|
252
|
+
Cornucopia::Capybara::PageDiagnostics.dump_details_in_table(report, table)
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
report.close
|
|
257
|
+
|
|
258
|
+
report_text = File.read(report.report_contents_page_name)
|
|
259
|
+
expect(report_text).not_to match /No Errors to report/
|
|
260
|
+
expect(report_text).to match /\>an existing section\</
|
|
261
|
+
expect(report_text).to match /\>\nsomething\n\</
|
|
262
|
+
expect(report_text).to match /\>a value\</
|
|
263
|
+
expect(report_text).to match /\>\npage_url\n\</
|
|
264
|
+
expect(report_text).to match /\>\ntitle\n\</
|
|
265
|
+
expect(report_text).to match /\>\nscreen_shot\n\</
|
|
266
|
+
expect(report_text).to match /\<img/
|
|
267
|
+
expect(report_text).not_to match /\>More Details...\</
|
|
268
|
+
expect(report_text).to match /\>\nhtml_frame\n\</
|
|
269
|
+
expect(report_text).to match /\<iframe/
|
|
270
|
+
expect(report_text).to match /\>\nhtml_source\n\</
|
|
271
|
+
expect(report_text).to match /\<textarea/
|
|
272
|
+
expect(report_text).to match /\>\npage_height\n\</
|
|
273
|
+
expect(report_text).to match /\>\npage_width\n\</
|
|
274
|
+
expect(report_text).to match /\>\nhtml_file\n\</
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
end
|