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
- #all_cookies ⇒ Object
- #browser_info ⇒ Object
- #browser_logs ⇒ Object
- #can_dump_details? ⇒ Boolean
- #dump_details ⇒ Object
- #dump_details_in_table ⇒ Object
- #execute_browser_function(function_symbol, unsupported_value, *args) ⇒ 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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 35 def initialize( = {}) = .clone @report = .delete(:report) @table = .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" @browser_logs = "use accessor" @browser_info = "use accessor" = "use accessor" end |
Instance Attribute Details
#allow_other_windows ⇒ Object
Returns the value of attribute allow_other_windows.
17 18 19 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 17 def allow_other_windows @allow_other_windows end |
Class Method Details
.clear_dumped_pages ⇒ Object
30 31 32 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 30 def clear_dumped_pages @@dumped_pages = [] end |
.dump_details(options = {}) ⇒ Object
This outputs the details about the current Capybara page to the current report.
22 23 24 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 22 def dump_details( = {}) Cornucopia::::PageDiagnostics.new().dump_details end |
.dump_details_in_table(report, report_table, options = {}) ⇒ Object
26 27 28 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 26 def dump_details_in_table(report, report_table, = {}) Cornucopia::::PageDiagnostics.new(.merge(report: report, table: report_table)).dump_details end |
Instance Method Details
#all_cookies ⇒ Object
193 194 195 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 193 def execute_browser_function(:all_cookies, nil) end |
#browser_info ⇒ Object
189 190 191 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 189 def browser_info execute_browser_function(:logs, nil) end |
#browser_logs ⇒ Object
182 183 184 185 186 187 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 182 def browser_logs value = execute_browser_function(:logs, nil) types = value.available_types types.each_with_object({}) { |type, hash| hash[type] = value.get(type) } end |
#can_dump_details? ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 57 def can_dump_details? can_dump = false if Object.const_defined?("::Capybara") && ::.send(:session_pool).present? my_page = ::.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 rescue StandardError false end |
#dump_details ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 74 def dump_details if can_dump_details? if @report && @table dump_details_in_table else @report = Cornucopia::Util::ReportBuilder.current_report section_title = [: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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 90 def dump_details_in_table if can_dump_details? @session = ::.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_browser_function(function_symbol, unsupported_value, *args) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 159 def execute_browser_function(function_symbol, unsupported_value, *args) value = unsupported_value unless @driver.browser.respond_to?(function_symbol) || @driver.browser.manage.respond_to?(function_symbol) @unsupported_list << function_symbol unless @driver.browser.respond_to?(function_symbol) end begin unless @unsupported_list.include?(function_symbol) value = if @driver.browser.respond_to?(function_symbol) @driver.browser.send(function_symbol, *args) else @driver.browser.manage.send(function_symbol, *args) end end rescue ::::NotSupportedByDriverError @unsupported_list << function_symbol end value end |
#execute_driver_function(function_symbol, unsupported_value, *args) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 143 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 ::::NotSupportedByDriverError @unsupported_list << function_symbol end value end |
#html_file ⇒ Object
264 265 266 267 268 269 270 271 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 264 def html_file dir_name = @report.unique_folder_name("html_save_file") FileUtils.mkdir_p File.join(@report.report_test_folder_name, dir_name) ::.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
232 233 234 235 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 232 def html_frame value = execute_driver_function(:html, nil) @report.page_frame(value) if value end |
#html_source ⇒ Object
227 228 229 230 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 227 def html_source value = execute_driver_function(:html, nil) @report.page_text(value) if value end |
#other_windows ⇒ Object
137 138 139 140 141 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 137 def other_windows if @allow_other_windows Cornucopia::::PageDiagnostics::WindowIterator.new(@window_handles, @current_window, self) end end |
#page_height ⇒ Object
212 213 214 215 216 217 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 212 def page_height if @current_window value = execute_driver_function(:window_size, nil, @current_window) value[1] if value end end |
#page_url ⇒ Object
197 198 199 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 197 def page_url execute_driver_function(:current_url, nil) end |
#page_width ⇒ Object
205 206 207 208 209 210 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 205 def page_width if @current_window value = execute_driver_function(:window_size, nil, @current_window) value[0] if value end end |
#response_headers ⇒ Object
219 220 221 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 219 def response_headers execute_driver_function(:response_headers, nil) end |
#screen_shot ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 237 def screen_shot dir_name = File.join(@report.report_test_folder_name, "temporary_folder") begin page_name = [: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.exist?(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
223 224 225 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 223 def status_code execute_driver_function(:status_code, nil) end |
#title ⇒ Object
201 202 203 |
# File 'lib/cornucopia/capybara/page_diagnostics.rb', line 201 def title execute_driver_function(:title, nil) end |