Class: Selenium::RSpec::Reporting::HtmlReport

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

Constant Summary collapse

PLACEHOLDER =
"<<placeholder>>"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path_strategy) ⇒ HtmlReport

Returns a new instance of HtmlReport.


9
10
11
# File 'lib/selenium/rspec/reporting/html_report.rb', line 9

def initialize(file_path_strategy)
  @file_path_strategy = file_path_strategy
end

Class Method Details

.append_css(global_styles) ⇒ Object


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/selenium/rspec/reporting/html_report.rb', line 65

def self.append_css(global_styles)
    global_styles + <<-EOF
    
div.rspec-report textarea {
  width: 100%;
}

div.rspec-report .dyn-source {
  background: #FFFFEE none repeat scroll 0%;
  border:1px dotted black;
  color: #000000;
  display: none;
  margin: 0.5em 2em;
  padding: 0.5em;
}

EOF
end

.append_javascript(global_scripts) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/selenium/rspec/reporting/html_report.rb', line 45

def self.append_javascript(global_scripts)
  global_scripts + <<-EOF
function toggleVisilibility(id, description) {
  var section;
  var link;

  section = document.getElementById(id);
  link = document.getElementById(id + "_link");

  if (section.style.display == "block") {
    section.style.display = "none"
    link.innerHTML = "Show " + description
  } else {
    section.style.display = "block"
    link.innerHTML = "Hide " + description
  }
}
EOF
end

.inject_placeholder(content) ⇒ Object


13
14
15
# File 'lib/selenium/rspec/reporting/html_report.rb', line 13

def self.inject_placeholder(content)
  content + Selenium::RSpec::Reporting::HtmlReport::PLACEHOLDER
end

Instance Method Details

#logs_and_screenshot_sections(example) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/selenium/rspec/reporting/html_report.rb', line 21

def logs_and_screenshot_sections(example)
  dom_id = "example_" + example.reporting_uid
  system_screenshot_url = @file_path_strategy.relative_file_path_for_system_screenshot(example)
  page_screenshot_url = @file_path_strategy.relative_file_path_for_page_screenshot(example)
  snapshot_url = @file_path_strategy.relative_file_path_for_html_capture(example)
  remote_control_logs_url = @file_path_strategy.relative_file_path_for_remote_control_logs(example)
  
  html = ""
  if File.exists? @file_path_strategy.file_path_for_html_capture(example)
    html << toggable_section(dom_id, :id => "snapshot", :url=> snapshot_url, :name => "Dynamic HTML Snapshot")
  end
  if File.exists? @file_path_strategy.file_path_for_remote_control_logs(example)          
    html << toggable_section(dom_id, :id => "rc_logs", :url=> remote_control_logs_url, :name => "Remote Control Logs")
  end
  if File.exists? @file_path_strategy.file_path_for_page_screenshot(example)
    html << toggable_image_section(dom_id, :id => "page_screenshot", :name => "Page Screenshot", :url => page_screenshot_url)
  end
  if File.exists? @file_path_strategy.file_path_for_system_screenshot(example)
    html << toggable_image_section(dom_id, :id => "system_screenshot", :name => "System Screenshot", :url => system_screenshot_url)
  end
  
  return html
end

#replace_placeholder_with_system_state_content(result, example) ⇒ Object


17
18
19
# File 'lib/selenium/rspec/reporting/html_report.rb', line 17

def replace_placeholder_with_system_state_content(result, example)
  result.gsub! PLACEHOLDER, logs_and_screenshot_sections(example)
end

#report_headerObject


115
116
117
# File 'lib/selenium/rspec/reporting/html_report.rb', line 115

def report_header
  super + "\n<script type=\"text/javascript\">moveProgressBar('100.0');</script>"
end

#toggable_image_section(dom_id, options) ⇒ Object


100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/selenium/rspec/reporting/html_report.rb', line 100

def toggable_image_section(dom_id, options)
  <<-EOS
  
  <div>[<a id="#{dom_id}_#{options[:id]}_link" href="javascript:toggleVisilibility('#{dom_id}_#{options[:id]}', '#{options[:name]}');">Show #{options[:name]}</a>]</div>
  <br/>      
  <div id="#{dom_id}_#{options[:id]}" style="display: none">
    <a href="#{options[:url]}">
      <img width="80%" src="#{options[:url]}" />
    </a>
  </div>
  <br/>
  
  EOS
end

#toggable_section(dom_id, options) ⇒ Object


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/selenium/rspec/reporting/html_report.rb', line 84

def toggable_section(dom_id, options)
  <<-EOS
  
  <div>[
    <a id="#{dom_id}_#{options[:id]}_link" 
       href=\"javascript:toggleVisilibility('#{dom_id}_#{options[:id]}', '#{options[:name]}')\">Show #{options[:name]}</a>
  ]</div>
  <br/><br/>
  <div id="#{dom_id}_#{options[:id]}" class="dyn-source">
    <a href="#{options[:url]}">Full screen</a><br/><br/>
    <iframe src="#{options[:url]}" width="100%" height="600px" ></iframe>
  </div>
  
  EOS
end