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 + "    \ndiv.rspec-report textarea {\n  width: 100%;\n}\n\ndiv.rspec-report .dyn-source {\n  background: #FFFFEE none repeat scroll 0%;\n  border:1px dotted black;\n  color: #000000;\n  display: none;\n  margin: 0.5em 2em;\n  padding: 0.5em;\n}\n\n"
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 + "function toggleVisilibility(id, description) {\n  var section;\n  var link;\n\n  section = document.getElementById(id);\n  link = document.getElementById(id + \"_link\");\n\n  if (section.style.display == \"block\") {\n    section.style.display = \"none\"\n    link.innerHTML = \"Show \" + description\n  } else {\n    section.style.display = \"block\"\n    link.innerHTML = \"Hide \" + description\n  }\n}\n"
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)
  "  \n  <div>[<a id=\"\#{dom_id}_\#{options[:id]}_link\" href=\"javascript:toggleVisilibility('\#{dom_id}_\#{options[:id]}', '\#{options[:name]}');\">Show \#{options[:name]}</a>]</div>\n  <br/>      \n  <div id=\"\#{dom_id}_\#{options[:id]}\" style=\"display: none\">\n    <a href=\"\#{options[:url]}\">\n      <img width=\"80%\" src=\"\#{options[:url]}\" />\n    </a>\n  </div>\n  <br/>\n  \n  EOS\nend\n"

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