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_filenameObject

Since:

  • 1.0.0



46
47
48
# File 'lib/qat/web/browser/html_dump.rb', line 46

def html_dump_filename
  File.basename(@html_dump_path)
end

#html_dump_pathString

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

Returns:

  • (String)

    HTML dump path

Since:

  • 1.0.0



42
43
44
# File 'lib/qat/web/browser/html_dump.rb', line 42

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



53
54
55
# File 'lib/qat/web/browser/html_dump.rb', line 53

def html_dump_path=(path)
  @html_dump_path = path
end

#read_html_dump(page, dump_path) ⇒ Object

Helper for reading file, in cucumber 6 this could be reverted to path directly

Since:

  • 1.0.0



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

def read_html_dump page, dump_path
  file = page.save_page dump_path
  dump_path_read = File.open file
  dump_path_read.read
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)
  raise ArgumentError.new "File #{path} already exists! Choose another filename" if ::File.exist? path
  log.info { "Saving HTML dump to #{path}" }
  path = read_html_dump page ,path
  log.info { "HTML dump available" }
  path
rescue Capybara::NotSupportedByDriverError
  log.warn { "Driver #{page.mode} does not support HTML dumps!" }
  return nil
end