Module: QAT::Web::Browser::HTMLDump

Extended by:
HTMLDump
Includes:
Logger
Included in:
HTMLDump
Defined in:
lib/qat/web/browser/html_dump.rb

Overview

Module to handle browser HTML dumps.

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#html_dump_pathString

Default HTML dump path. Can be set with #html_dump_path=.

Returns:

  • (String)

    HTML dump path

Since:

  • 1.0.0



33
34
35
# File 'lib/qat/web/browser/html_dump.rb', line 33

def html_dump_path
  @html_dump_path || ::File.join('public', "browser_#{Time.new.strftime("%H%M%S%L")}.html")
end

#html_dump_path=(path) ⇒ Object

Set new default HTML dump path.

Parameters:

  • path (String)

    HTML dump path

Since:

  • 1.0.0



40
41
42
# File 'lib/qat/web/browser/html_dump.rb', line 40

def html_dump_path=(path)
  @html_dump_path = path
end

#take_html_dump(page = Capybara.current_session, path = html_dump_path) ⇒ String/NilClass

Function to take a browser HTML dump. Will handle the usage of driver that don’t support HTML dumps.

Parameters:

  • page (Capybara::Session) (defaults to: Capybara.current_session)

    Browser to take HTML dump from

  • path (String) (defaults to: html_dump_path)

    File path to save HTML dump file

Returns:

  • (String/NilClass)

    File path to where the HTML dump file was saved or nil if the browser doesn’t support HTML dumps

Since:

  • 1.0.0



19
20
21
22
23
24
25
26
27
28
# File 'lib/qat/web/browser/html_dump.rb', line 19

def take_html_dump(page=Capybara.current_session, path=html_dump_path)
  log.info { "Saving HTML dump to #{path}" }
  raise ArgumentError.new "File #{path} already exists! Choose another filename" if ::File.exists? path
  path = page.save_page path
  log.info { "HTML dump available" }
  ::File.basename(path)
rescue Capybara::NotSupportedByDriverError
  log.warn { "Driver #{page.mode} does not support HTML dumps!" }
  return nil
end