Class: Cornucopia::Capybara::PageDiagnostics
- Inherits:
-
Object
- Object
- Cornucopia::Capybara::PageDiagnostics
- Defined in:
- lib/cornucopia/capybara/page_diagnostics.rb
Defined Under Namespace
Classes: WindowIterator
Constant Summary collapse
- @@dumped_pages =
[]
Instance Attribute Summary collapse
-
#allow_other_windows ⇒ Object
Returns the value of attribute allow_other_windows.
Class Method Summary collapse
- .clear_dumped_pages ⇒ Object
-
.dump_details(options = {}) ⇒ Object
This outputs the details about the current Capybara page to the current report.
- .dump_details_in_table(report, report_table, options = {}) ⇒ Object
Instance Method Summary collapse
- #can_dump_details? ⇒ Boolean
- #dump_details ⇒ Object
- #dump_details_in_table ⇒ Object
- #execute_driver_function(function_symbol, unsupported_value, *args) ⇒ Object
- #html_file ⇒ Object
- #html_frame ⇒ Object
- #html_source ⇒ Object
-
#initialize(options = {}) ⇒ PageDiagnostics
constructor
A new instance of PageDiagnostics.
- #other_windows ⇒ Object
- #page_height ⇒ Object
- #page_url ⇒ Object
- #page_width ⇒ Object
- #response_headers ⇒ Object
- #screen_shot ⇒ Object
- #status_code ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ PageDiagnostics
Returns a new instance of PageDiagnostics.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 33 def initialize( = {}) @options = .clone @report = @options.delete(:report) @table = @options.delete(:table) @unsupported_list ||= [] @allow_other_windows = true @page_url = "use accessor" @title = "use accessor" @page_width = "use accessor" @page_height = "use accessor" @response_headers = "use accessor" @status_code = "use accessor" @html_source = "use accessor" @html_frame = "use accessor" @screen_shot = "use accessor" @html_file = "use accessor" end |
Instance Attribute Details
#allow_other_windows ⇒ Object
Returns the value of attribute allow_other_windows.
15 16 17 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 15 def allow_other_windows @allow_other_windows end |
Class Method Details
.clear_dumped_pages ⇒ Object
28 29 30 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 28 def clear_dumped_pages @@dumped_pages = [] end |
.dump_details(options = {}) ⇒ Object
This outputs the details about the current Capybara page to the current report.
20 21 22 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 20 def dump_details( = {}) Cornucopia::Capybara::PageDiagnostics.new().dump_details end |
.dump_details_in_table(report, report_table, options = {}) ⇒ Object
24 25 26 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 24 def dump_details_in_table(report, report_table, = {}) Cornucopia::Capybara::PageDiagnostics.new(.merge(report: report, table: report_table)).dump_details end |
Instance Method Details
#can_dump_details? ⇒ Boolean
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 52 def can_dump_details? can_dump = false if (Object.const_defined?("Capybara")) my_page = ::Capybara.current_session if (my_page && my_page.current_url.present? && my_page.current_url != "about:blank") can_dump = !@@dumped_pages.include?(Digest::SHA2.hexdigest(my_page.html)) end end can_dump end |
#dump_details ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 66 def dump_details if can_dump_details? if @report && @table dump_details_in_table else @report = Cornucopia::Util::ReportBuilder.current_report section_title = @options[:section_label] || "Page Dump:" @report.within_section(section_title) do @table = nil dump_details_in_table end end end end |
#dump_details_in_table ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 82 def dump_details_in_table if can_dump_details? @session = ::Capybara.current_session @driver = @session.driver @current_window = execute_driver_function(:current_window_handle, nil) @window_handles = execute_driver_function(:window_handles, [1]).clone configured_report = Cornucopia::Util::Configuration.report_configuration(:capybara_page_diagnostics) configured_report.add_report_objects(capybara: self) configured_report.generate_report(@report, report_table: @table) @@dumped_pages << Digest::SHA2.hexdigest(@session.html) end end |
#execute_driver_function(function_symbol, unsupported_value, *args) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 135 def execute_driver_function(function_symbol, unsupported_value, *args) value = unsupported_value @unsupported_list << function_symbol unless @driver.respond_to?(function_symbol) begin unless @unsupported_list.include?(function_symbol) value = @driver.send(function_symbol, *args) end rescue ::Capybara::NotSupportedByDriverError => error @unsupported_list << function_symbol end value end |
#html_file ⇒ Object
218 219 220 221 222 223 224 225 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 218 def html_file dir_name = @report.unique_folder_name("html_save_file") FileUtils.mkdir_p File.join(@report.report_test_folder_name, dir_name) ::Capybara.current_session. save_page(File.join(@report.report_test_folder_name, dir_name, "__cornucopia_save_page.html")) "<a href=\"#{File.join(dir_name, "__cornucopia_save_page.html")}\" target=\"_blank\">Saved Page</a>". html_safe end |
#html_frame ⇒ Object
186 187 188 189 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 186 def html_frame value = execute_driver_function(:html, nil) @report.page_frame(value) if value end |
#html_source ⇒ Object
181 182 183 184 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 181 def html_source value = execute_driver_function(:html, nil) @report.page_text(value) if value end |
#other_windows ⇒ Object
129 130 131 132 133 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 129 def other_windows if @allow_other_windows Cornucopia::Capybara::PageDiagnostics::WindowIterator.new(@window_handles, @current_window, self) end end |
#page_height ⇒ Object
166 167 168 169 170 171 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 166 def page_height if @current_window value = execute_driver_function(:window_size, nil, @current_window) value[1] if value end end |
#page_url ⇒ Object
151 152 153 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 151 def page_url execute_driver_function(:current_url, nil) end |
#page_width ⇒ Object
159 160 161 162 163 164 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 159 def page_width if @current_window value = execute_driver_function(:window_size, nil, @current_window) value[0] if value end end |
#response_headers ⇒ Object
173 174 175 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 173 def response_headers execute_driver_function(:response_headers, nil) end |
#screen_shot ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 191 def screen_shot dir_name = File.join(@report.report_test_folder_name, "temporary_folder") begin page_name = @options[:screen_shot_name] || "screen_shot" page_name = page_name [Dir.pwd.length..-1] if page_name.start_with?(Dir.pwd) page_name = page_name [1..-1] if page_name.start_with?("/") page_name = page_name["features/".length..-1] if page_name.start_with?("features/") page_name = page_name.gsub(/[^a-z0-9_]/i, "_") page_name = page_name.gsub("__", "_") page_name = File.join(dir_name, "#{page_name}.png") FileUtils.mkdir_p dir_name execute_driver_function(:save_screenshot, nil, page_name) if File.exists?(page_name) @report.image_link(page_name) else "Could not save screen_shot." end ensure FileUtils.rm_rf dir_name end end |
#status_code ⇒ Object
177 178 179 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 177 def status_code execute_driver_function(:status_code, nil) end |
#title ⇒ Object
155 156 157 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 155 def title execute_driver_function(:title, nil) end |