Class: TddiumReporting::SystemCapture

Inherits:
Object
  • Object
show all
Includes:
PathHelper
Defined in:
lib/tddium_reporting/system_capture.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PathHelper

#test_exec_path

Constructor Details

#initialize(selenium_driver, example) ⇒ SystemCapture

Returns a new instance of SystemCapture.



11
12
13
14
15
16
17
18
19
# File 'lib/tddium_reporting/system_capture.rb', line 11

def initialize(selenium_driver, example)
  @selenium_driver = selenium_driver
  @example = example
  @example_id = Digest::MD5.hexdigest(example.inspect)
  @things = {:html_capture => "html",
             :system_screenshot => "png",
             :page_screenshot => "png",
             :remote_control_logs => "log"}
end

Instance Attribute Details

#example_idObject (readonly)

Returns the value of attribute example_id.



9
10
11
# File 'lib/tddium_reporting/system_capture.rb', line 9

def example_id
  @example_id
end

Instance Method Details

#capture_html_snapshotObject



51
52
53
54
55
56
57
# File 'lib/tddium_reporting/system_capture.rb', line 51

def capture_html_snapshot
  # Skipping HTML Snapshot retrieval, if there is no current Selenium session
  return  unless @selenium_driver.session_started?

  html = @selenium_driver.get_html_source
  File.open(path_for(:html_capture), "w") { |f| f.write html }
end

#capture_page_screenshotObject



67
68
69
70
71
72
73
# File 'lib/tddium_reporting/system_capture.rb', line 67

def capture_page_screenshot
  return unless @selenium_driver.chrome_backend? && @selenium_driver.session_started?

  encodedImage = @selenium_driver.capture_entire_page_screenshot_to_string("")
  pngImage = Base64.decode64(encodedImage)
  File.open(path_for(:page_screenshot), "wb") { |f| f.write pngImage }
end

#capture_system_screenshotObject



59
60
61
62
63
64
65
# File 'lib/tddium_reporting/system_capture.rb', line 59

def capture_system_screenshot
  @selenium_driver.window_maximize if @selenium_driver.session_started?

  encodedImage = @selenium_driver.capture_screenshot_to_string
  pngImage = Base64.decode64(encodedImage)
  File.open(path_for(:system_screenshot), "wb") { |f| f.write pngImage }
end

#capture_system_stateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tddium_reporting/system_capture.rb', line 25

def capture_system_state
  # Selenium RC seems to 'freeze' every so often when calling 
  # getHTMLSource, especially when DeepTest timeout is low, I need to investigate...
  # Set deeptest :timeout_in_seconds => 30 to see it happen
  begin
    retrieve_remote_control_logs
  rescue Exception => e
    STDERR.puts "WARNING: Could not retrieve remote control logs: #{e}"
  end
  begin
    capture_html_snapshot
  rescue Exception => e
    STDERR.puts "WARNING: Could not capture HTML snapshot: #{e}"
  end
  begin
    capture_page_screenshot
  rescue Exception => e
    STDERR.puts "WARNING: Could not capture page screenshot: #{e}"
  end
  begin
    capture_system_screenshot
  rescue Exception => e
    STDERR.puts "WARNING: Could not capture system screenshot: #{e}"
  end
end

#path_for(thing) ⇒ Object



21
22
23
# File 'lib/tddium_reporting/system_capture.rb', line 21

def path_for(thing)
  test_exec_path + "#{@example_id}-#{thing}.#{@things[thing]}"
end

#retrieve_remote_control_logsObject



75
76
77
78
# File 'lib/tddium_reporting/system_capture.rb', line 75

def retrieve_remote_control_logs
  logs = @selenium_driver.retrieve_last_remote_control_logs
  File.open(path_for(:remote_control_logs), "w") { |f| f.write logs }
end