Class: Selenium::RSpec::Reporting::SystemCapture

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/rspec/reporting/system_capture.rb

Instance Method Summary collapse

Constructor Details

#initialize(selenium_driver, example, file_path_strategy) ⇒ SystemCapture

Returns a new instance of SystemCapture.


7
8
9
10
11
# File 'lib/selenium/rspec/reporting/system_capture.rb', line 7

def initialize(selenium_driver, example, file_path_strategy)
  @selenium_driver = selenium_driver
  @example = example
  @file_path_strategy = file_path_strategy 
end

Instance Method Details

#capture_html_snapshotObject


39
40
41
42
43
44
45
# File 'lib/selenium/rspec/reporting/system_capture.rb', line 39

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(@file_path_strategy.file_path_for_html_capture(@example), "w") { |f| f.write html }
end

#capture_page_screenshotObject


55
56
57
58
59
60
61
# File 'lib/selenium/rspec/reporting/system_capture.rb', line 55

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(@file_path_strategy.file_path_for_page_screenshot(@example), "wb") { |f| f.write pngImage }
end

#capture_system_screenshotObject


47
48
49
50
51
52
53
# File 'lib/selenium/rspec/reporting/system_capture.rb', line 47

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(@file_path_strategy.file_path_for_system_screenshot(@example), "wb") { |f| f.write pngImage }
end

#capture_system_stateObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/selenium/rspec/reporting/system_capture.rb', line 13

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

#retrieve_remote_control_logsObject


63
64
65
66
# File 'lib/selenium/rspec/reporting/system_capture.rb', line 63

def retrieve_remote_control_logs
  logs = @selenium_driver.retrieve_last_remote_control_logs
  File.open(@file_path_strategy.file_path_for_remote_control_logs(@example), "w") { |f| f.write logs }
end