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,89 @@
|
|
|
1
|
+
require ::File.expand_path("../util/configuration", File.dirname(__FILE__))
|
|
2
|
+
require ::File.expand_path("finder_diagnostics", File.dirname(__FILE__))
|
|
3
|
+
|
|
4
|
+
module Cornucopia
|
|
5
|
+
module Capybara
|
|
6
|
+
module FinderExtensions
|
|
7
|
+
def find(*args)
|
|
8
|
+
__cornucopia_finder_function(:find, *args)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def all(*args)
|
|
12
|
+
__cornucopia_finder_function(:all, *args)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def __cornucopia_finder_function(finder_function, *args)
|
|
16
|
+
retry_count = 0
|
|
17
|
+
result = nil
|
|
18
|
+
|
|
19
|
+
support_options = __cornucopia__extract_support_options(*args)
|
|
20
|
+
|
|
21
|
+
begin
|
|
22
|
+
retry_count += 1
|
|
23
|
+
result = send("__cornucopia_orig_#{finder_function}", *args)
|
|
24
|
+
rescue Selenium::WebDriver::Error::StaleElementReferenceError
|
|
25
|
+
retry if __cornucopia__retry_finder(retry_count, support_options)
|
|
26
|
+
|
|
27
|
+
result = __cornucopia__analyze_finder(finder_function, support_options, *args)
|
|
28
|
+
rescue Exception
|
|
29
|
+
result = __cornucopia__analyze_finder(finder_function, support_options, *args)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
result
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def __cornucopia__extract_support_options(*args)
|
|
38
|
+
support_options = {}
|
|
39
|
+
|
|
40
|
+
if args[-1].is_a?(Hash)
|
|
41
|
+
support_options[:__cornucopia_no_analysis] = args[-1].delete(:__cornucopia_no_analysis)
|
|
42
|
+
support_options[:__cornucopia_retry_with_found] = args[-1].delete(:__cornucopia_retry_with_found)
|
|
43
|
+
# support_options[:__cornucopia_alternate_retry] = args[-1].delete(:__cornucopia_alternate_retry)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
support_options
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def __cornucopia__analyze_finder(function_name, support_options, *args)
|
|
50
|
+
return_value = nil
|
|
51
|
+
error = $!
|
|
52
|
+
|
|
53
|
+
if !support_options[:__cornucopia_no_analysis] &&
|
|
54
|
+
(Cornucopia::Util::Configuration.analyze_find_exceptions ||
|
|
55
|
+
support_options[:__cornucopia_retry_with_found])
|
|
56
|
+
# || support_options[:__cornucopia_alternate_retry])
|
|
57
|
+
support_options.merge!({ __cornucopia_no_analysis: true })
|
|
58
|
+
|
|
59
|
+
find_action = Cornucopia::Capybara::FinderDiagnostics::FindAction.new(self,
|
|
60
|
+
{},
|
|
61
|
+
support_options,
|
|
62
|
+
function_name,
|
|
63
|
+
*args)
|
|
64
|
+
|
|
65
|
+
if find_action.perform_analysis(Cornucopia::Util::Configuration.retry_with_found ||
|
|
66
|
+
support_options[:__cornucopia_retry_with_found])
|
|
67
|
+
# Cornucopia::Util::Configuration.alternate_retry ||
|
|
68
|
+
# support_options[:__cornucopia_alternate_retry])
|
|
69
|
+
return_value = find_action.simple_run({ __cornucopia_no_analysis: true }) rescue nil
|
|
70
|
+
return_value ||= find_action.return_value
|
|
71
|
+
else
|
|
72
|
+
raise error
|
|
73
|
+
end
|
|
74
|
+
else
|
|
75
|
+
raise error
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
return_value
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def __cornucopia__retry_finder(retry_count, support_options)
|
|
82
|
+
retry_count <= Cornucopia::Util::Configuration.selenium_cache_retry_count &&
|
|
83
|
+
!support_options[:__cornucopia_no_analysis]
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
load ::File.expand_path("install_finder_extensions.rb", File.dirname(__FILE__))
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
$cornucopia_finder_extension_installed = false unless defined? $cornucopia_finder_extension_installed
|
|
2
|
+
|
|
3
|
+
if Object.const_defined?("Capybara") &&
|
|
4
|
+
Capybara.const_defined?("Node") &&
|
|
5
|
+
Capybara::Node.const_defined?("Document") &&
|
|
6
|
+
!$cornucopia_finder_extension_installed
|
|
7
|
+
module Capybara
|
|
8
|
+
module Node
|
|
9
|
+
class Document
|
|
10
|
+
alias_method :__cornucopia_orig_find, :find
|
|
11
|
+
alias_method :__cornucopia_orig_all, :all
|
|
12
|
+
|
|
13
|
+
include Cornucopia::Capybara::FinderExtensions
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
if Object.const_defined?("Capybara") &&
|
|
20
|
+
Capybara.const_defined?("Node") &&
|
|
21
|
+
Capybara::Node.const_defined?("Simple") &&
|
|
22
|
+
!$cornucopia_finder_extension_installed
|
|
23
|
+
module Capybara
|
|
24
|
+
module Node
|
|
25
|
+
class Simple
|
|
26
|
+
alias_method :__cornucopia_orig_find, :find
|
|
27
|
+
alias_method :__cornucopia_orig_all, :all
|
|
28
|
+
|
|
29
|
+
include Cornucopia::Capybara::FinderExtensions
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
if Object.const_defined?("Capybara") &&
|
|
36
|
+
Capybara.const_defined?("Node") &&
|
|
37
|
+
Capybara::Node.const_defined?("Element") &&
|
|
38
|
+
!$cornucopia_finder_extension_installed
|
|
39
|
+
module Capybara
|
|
40
|
+
module Node
|
|
41
|
+
class Element
|
|
42
|
+
alias_method :__cornucopia_orig_find, :find
|
|
43
|
+
alias_method :__cornucopia_orig_all, :all
|
|
44
|
+
|
|
45
|
+
include Cornucopia::Capybara::FinderExtensions
|
|
46
|
+
|
|
47
|
+
# select_value finds the option with the value #value then calls select_option on that item.
|
|
48
|
+
#
|
|
49
|
+
# select_value only works on select boxes.
|
|
50
|
+
def select_value(values)
|
|
51
|
+
raise "select_value is only valid for select items" unless self.tag_name == "select"
|
|
52
|
+
|
|
53
|
+
if values.is_a?(Array)
|
|
54
|
+
values.each do |value|
|
|
55
|
+
html_safe_value = "".html_safe + value.to_s
|
|
56
|
+
self.find("option[value=\"#{html_safe_value}\"]", visible: false).select_option
|
|
57
|
+
end
|
|
58
|
+
else
|
|
59
|
+
html_safe_value = "".html_safe + values.to_s
|
|
60
|
+
self.find("option[value=\"#{html_safe_value}\"]", visible: false).select_option
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# value_text returns the text for the selected items in the select box instead of the value(s)
|
|
65
|
+
#
|
|
66
|
+
# value_text only works on select boxes.
|
|
67
|
+
def value_text
|
|
68
|
+
raise "value_text is only valid for select items" unless self.tag_name == "select"
|
|
69
|
+
|
|
70
|
+
values = self.value
|
|
71
|
+
if values.is_a?(Array)
|
|
72
|
+
values.map do |value|
|
|
73
|
+
self.find("option[value=\"#{value}\"]", visible: false).text
|
|
74
|
+
end
|
|
75
|
+
else
|
|
76
|
+
self.find("option[value=\"#{values}\"]", visible: false).text
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
if Object.const_defined?("Capybara") &&
|
|
85
|
+
Capybara.const_defined?("Session") &&
|
|
86
|
+
!$cornucopia_finder_extension_installed
|
|
87
|
+
$cornucopia_finder_extension_installed = true
|
|
88
|
+
|
|
89
|
+
module Capybara
|
|
90
|
+
class Session
|
|
91
|
+
# alias_method :__cornucopia_orig_find, :find
|
|
92
|
+
# alias_method :__cornucopia_orig_all, :all
|
|
93
|
+
#
|
|
94
|
+
# include Cornucopia::Capybara::FinderExtensions
|
|
95
|
+
|
|
96
|
+
# This function uses Capybara's synchronize function to evaluate a block until
|
|
97
|
+
# it becomes true.
|
|
98
|
+
def synchronize_test(seconds=Capybara.default_wait_time, options = {}, &block)
|
|
99
|
+
document.synchronize(seconds, options) do
|
|
100
|
+
raise ::Capybara::ElementNotFound unless block.yield
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
$cornucopia_matcher_extension_installed = false unless defined? $cornucopia_matcher_extension_installed
|
|
2
|
+
|
|
3
|
+
if Object.const_defined?("Capybara") &&
|
|
4
|
+
Capybara.const_defined?("Node") &&
|
|
5
|
+
Capybara::Node.const_defined?("Document") &&
|
|
6
|
+
!$cornucopia_matcher_extension_installed
|
|
7
|
+
module Capybara
|
|
8
|
+
module Node
|
|
9
|
+
class Document
|
|
10
|
+
alias_method :__cornucopia_orig_assert_selector, :assert_selector
|
|
11
|
+
alias_method :__cornucopia_orig_assert_no_selector, :assert_no_selector
|
|
12
|
+
|
|
13
|
+
include Cornucopia::Capybara::MatcherExtensions
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
if Object.const_defined?("Capybara") &&
|
|
20
|
+
Capybara.const_defined?("Node") &&
|
|
21
|
+
Capybara::Node.const_defined?("Element") &&
|
|
22
|
+
!$cornucopia_matcher_extension_installed
|
|
23
|
+
module Capybara
|
|
24
|
+
module Node
|
|
25
|
+
class Element
|
|
26
|
+
alias_method :__cornucopia_orig_assert_selector, :assert_selector
|
|
27
|
+
alias_method :__cornucopia_orig_assert_no_selector, :assert_no_selector
|
|
28
|
+
|
|
29
|
+
include Cornucopia::Capybara::MatcherExtensions
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
if Object.const_defined?("Capybara") &&
|
|
36
|
+
Capybara.const_defined?("Session") &&
|
|
37
|
+
!$cornucopia_matcher_extension_installed
|
|
38
|
+
$cornucopia_matcher_extension_installed = true
|
|
39
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require ::File.expand_path("../util/configuration", File.dirname(__FILE__))
|
|
2
|
+
require ::File.expand_path("finder_diagnostics", File.dirname(__FILE__))
|
|
3
|
+
|
|
4
|
+
module Cornucopia
|
|
5
|
+
module Capybara
|
|
6
|
+
module MatcherExtensions
|
|
7
|
+
def assert_selector(*args)
|
|
8
|
+
__cornucopia_assert_selector_function(:assert_selector, *args)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def assert_no_selector(*args)
|
|
12
|
+
__cornucopia_assert_selector_function(:assert_no_selector, *args)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def __cornucopia_assert_selector_function(assert_selector_function, *args)
|
|
16
|
+
retry_count = 0
|
|
17
|
+
result = nil
|
|
18
|
+
|
|
19
|
+
support_options = __cornucopia__extract_selector_support_options(*args)
|
|
20
|
+
|
|
21
|
+
begin
|
|
22
|
+
retry_count += 1
|
|
23
|
+
result = send("__cornucopia_orig_#{assert_selector_function}", *args)
|
|
24
|
+
rescue Selenium::WebDriver::Error::StaleElementReferenceError
|
|
25
|
+
retry if __cornucopia__retry_selector(retry_count, support_options)
|
|
26
|
+
|
|
27
|
+
result = __cornucopia__analyze_selector(assert_selector_function, support_options, *args)
|
|
28
|
+
rescue Exception
|
|
29
|
+
result = __cornucopia__analyze_selector(assert_selector_function, support_options, *args)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
result
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def __cornucopia__extract_selector_support_options(*args)
|
|
38
|
+
support_options = {}
|
|
39
|
+
|
|
40
|
+
if args[-1].is_a?(Hash)
|
|
41
|
+
support_options[:__cornucopia_no_analysis] = args[-1].delete(:__cornucopia_no_analysis)
|
|
42
|
+
support_options[:__cornucopia_retry_with_found] = args[-1].delete(:__cornucopia_retry_with_found)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
support_options
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def __cornucopia__analyze_selector(function_name, support_options, *args)
|
|
49
|
+
return_value = nil
|
|
50
|
+
error = $!
|
|
51
|
+
|
|
52
|
+
if !support_options[:__cornucopia_no_analysis] &&
|
|
53
|
+
(Cornucopia::Util::Configuration.analyze_selector_exceptions ||
|
|
54
|
+
support_options[:__cornucopia_retry_with_found])
|
|
55
|
+
find_action = Cornucopia::Capybara::FinderDiagnostics::FindAction.new(self,
|
|
56
|
+
{},
|
|
57
|
+
support_options,
|
|
58
|
+
function_name,
|
|
59
|
+
*args)
|
|
60
|
+
|
|
61
|
+
if find_action.perform_analysis(Cornucopia::Util::Configuration.retry_match_with_found ||
|
|
62
|
+
support_options[:__cornucopia_retry_with_found])
|
|
63
|
+
return_value = find_action.simple_run rescue nil
|
|
64
|
+
return_value ||= find_action.return_value
|
|
65
|
+
else
|
|
66
|
+
raise error
|
|
67
|
+
end
|
|
68
|
+
else
|
|
69
|
+
raise error
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
return_value
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def __cornucopia__retry_selector(retry_count, support_options)
|
|
76
|
+
retry_count <= Cornucopia::Util::Configuration.selenium_cache_retry_count &&
|
|
77
|
+
!support_options[:__cornucopia_no_analysis]
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
load ::File.expand_path("install_matcher_extensions.rb", File.dirname(__FILE__))
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
require "digest"
|
|
2
|
+
require ::File.expand_path("../util/configuration", File.dirname(__FILE__))
|
|
3
|
+
require ::File.expand_path("../util/report_builder", File.dirname(__FILE__))
|
|
4
|
+
require ::File.expand_path("../util/report_table", File.dirname(__FILE__))
|
|
5
|
+
|
|
6
|
+
module Cornucopia
|
|
7
|
+
module Capybara
|
|
8
|
+
class PageDiagnostics
|
|
9
|
+
@@dumped_pages = []
|
|
10
|
+
|
|
11
|
+
Cornucopia::Util::ReportBuilder.on_close do
|
|
12
|
+
Cornucopia::Capybara::PageDiagnostics.clear_dumped_pages
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
attr_accessor :allow_other_windows
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
# This outputs the details about the current Capybara page to
|
|
19
|
+
# the current report.
|
|
20
|
+
def dump_details(options = {})
|
|
21
|
+
Cornucopia::Capybara::PageDiagnostics.new(options).dump_details
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def dump_details_in_table(report, report_table, options = {})
|
|
25
|
+
Cornucopia::Capybara::PageDiagnostics.new(options.merge(report: report, table: report_table)).dump_details
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def clear_dumped_pages
|
|
29
|
+
@@dumped_pages = []
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def initialize(options = {})
|
|
34
|
+
@options = options.clone
|
|
35
|
+
@report = @options.delete(:report)
|
|
36
|
+
@table = @options.delete(:table)
|
|
37
|
+
@unsupported_list ||= []
|
|
38
|
+
@allow_other_windows = true
|
|
39
|
+
|
|
40
|
+
@page_url = "use accessor"
|
|
41
|
+
@title = "use accessor"
|
|
42
|
+
@page_width = "use accessor"
|
|
43
|
+
@page_height = "use accessor"
|
|
44
|
+
@response_headers = "use accessor"
|
|
45
|
+
@status_code = "use accessor"
|
|
46
|
+
@html_source = "use accessor"
|
|
47
|
+
@html_frame = "use accessor"
|
|
48
|
+
@screen_shot = "use accessor"
|
|
49
|
+
@html_file = "use accessor"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def can_dump_details?
|
|
53
|
+
can_dump = false
|
|
54
|
+
|
|
55
|
+
if (Object.const_defined?("Capybara"))
|
|
56
|
+
my_page = ::Capybara.current_session
|
|
57
|
+
|
|
58
|
+
if (my_page && my_page.current_url.present? && my_page.current_url != "about:blank")
|
|
59
|
+
can_dump = !@@dumped_pages.include?(Digest::SHA2.hexdigest(my_page.html))
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
can_dump
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def dump_details
|
|
67
|
+
if can_dump_details?
|
|
68
|
+
if @report && @table
|
|
69
|
+
dump_details_in_table
|
|
70
|
+
else
|
|
71
|
+
@report = Cornucopia::Util::ReportBuilder.current_report
|
|
72
|
+
section_title = @options[:section_label] || "Page Dump:"
|
|
73
|
+
|
|
74
|
+
@report.within_section(section_title) do
|
|
75
|
+
@table = nil
|
|
76
|
+
dump_details_in_table
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def dump_details_in_table
|
|
83
|
+
if can_dump_details?
|
|
84
|
+
@session = ::Capybara.current_session
|
|
85
|
+
@driver = @session.driver
|
|
86
|
+
|
|
87
|
+
@current_window = execute_driver_function(:current_window_handle, nil)
|
|
88
|
+
@window_handles = execute_driver_function(:window_handles, [1]).clone
|
|
89
|
+
|
|
90
|
+
configured_report = Cornucopia::Util::Configuration.report_configuration(:capybara_page_diagnostics)
|
|
91
|
+
|
|
92
|
+
configured_report.add_report_objects(capybara: self)
|
|
93
|
+
configured_report.generate_report(@report, report_table: @table)
|
|
94
|
+
|
|
95
|
+
@@dumped_pages << Digest::SHA2.hexdigest(@session.html)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
class WindowIterator
|
|
100
|
+
def initialize(window_handles, current_window, diagnostics)
|
|
101
|
+
@window_handles = window_handles
|
|
102
|
+
@current_window = current_window
|
|
103
|
+
@diagnostics = diagnostics
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def each(&block)
|
|
107
|
+
begin
|
|
108
|
+
@diagnostics.allow_other_windows = false
|
|
109
|
+
|
|
110
|
+
if @window_handles.length > 1
|
|
111
|
+
@window_handles.each do |window_handle|
|
|
112
|
+
unless @current_window && @current_window == window_handle
|
|
113
|
+
switched = @diagnostics.execute_driver_function(:switch_to_window,
|
|
114
|
+
"could not switch windows",
|
|
115
|
+
window_handle)
|
|
116
|
+
if switched != "could not switch windows"
|
|
117
|
+
block.yield @diagnostics
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
ensure
|
|
123
|
+
@diagnostics.allow_other_windows = true
|
|
124
|
+
@diagnostics.execute_driver_function(:switch_to_window, "could not switch windows", @current_window)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def other_windows
|
|
130
|
+
if @allow_other_windows
|
|
131
|
+
Cornucopia::Capybara::PageDiagnostics::WindowIterator.new(@window_handles, @current_window, self)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def execute_driver_function(function_symbol, unsupported_value, *args)
|
|
136
|
+
value = unsupported_value
|
|
137
|
+
|
|
138
|
+
@unsupported_list << function_symbol unless @driver.respond_to?(function_symbol)
|
|
139
|
+
|
|
140
|
+
begin
|
|
141
|
+
unless @unsupported_list.include?(function_symbol)
|
|
142
|
+
value = @driver.send(function_symbol, *args)
|
|
143
|
+
end
|
|
144
|
+
rescue ::Capybara::NotSupportedByDriverError => error
|
|
145
|
+
@unsupported_list << function_symbol
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
value
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def page_url
|
|
152
|
+
execute_driver_function(:current_url, nil)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def title
|
|
156
|
+
execute_driver_function(:title, nil)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def page_width
|
|
160
|
+
if @current_window
|
|
161
|
+
value = execute_driver_function(:window_size, nil, @current_window)
|
|
162
|
+
value[0] if value
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def page_height
|
|
167
|
+
if @current_window
|
|
168
|
+
value = execute_driver_function(:window_size, nil, @current_window)
|
|
169
|
+
value[1] if value
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def response_headers
|
|
174
|
+
execute_driver_function(:response_headers, nil)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def status_code
|
|
178
|
+
execute_driver_function(:status_code, nil)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def html_source
|
|
182
|
+
value = execute_driver_function(:html, nil)
|
|
183
|
+
@report.page_text(value) if value
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def html_frame
|
|
187
|
+
value = execute_driver_function(:html, nil)
|
|
188
|
+
@report.page_frame(value) if value
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def screen_shot
|
|
192
|
+
dir_name = File.join(@report.report_folder_name, "temporary_folder")
|
|
193
|
+
|
|
194
|
+
begin
|
|
195
|
+
page_name = @options[:screen_shot_name] || "screen_shot"
|
|
196
|
+
page_name = page_name [Dir.pwd.length..-1] if page_name.start_with?(Dir.pwd)
|
|
197
|
+
page_name = page_name [1..-1] if page_name.start_with?("/")
|
|
198
|
+
page_name = page_name["features/".length..-1] if page_name.start_with?("features/")
|
|
199
|
+
page_name = page_name.gsub(/[^a-z0-9_]/i, "_")
|
|
200
|
+
page_name = page_name.gsub("__", "_")
|
|
201
|
+
|
|
202
|
+
page_name = File.join(dir_name, "#{page_name}.png")
|
|
203
|
+
|
|
204
|
+
FileUtils.mkdir_p dir_name
|
|
205
|
+
|
|
206
|
+
execute_driver_function(:save_screenshot, nil, page_name)
|
|
207
|
+
|
|
208
|
+
if File.exists?(page_name)
|
|
209
|
+
@report.image_link(page_name)
|
|
210
|
+
else
|
|
211
|
+
"Could not save screen_shot."
|
|
212
|
+
end
|
|
213
|
+
ensure
|
|
214
|
+
FileUtils.rm_rf dir_name
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def html_file
|
|
219
|
+
dir_name = @report.unique_folder_name("html_save_file")
|
|
220
|
+
FileUtils.mkdir_p File.join(@report.report_folder_name, dir_name)
|
|
221
|
+
::Capybara.current_session.
|
|
222
|
+
save_page(File.join(@report.report_folder_name, dir_name, "__cornucopia_save_page.html"))
|
|
223
|
+
"<a href=\"#{File.join(dir_name, "__cornucopia_save_page.html")}\" target=\"_blank\">Saved Page</a>".
|
|
224
|
+
html_safe
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|