Module: ReportPortal
- Defined in:
- lib/report_portal/version.rb,
lib/reportportal.rb,
lib/report_portal/settings.rb,
lib/report_portal/logging/logger.rb,
lib/report_portal/cucumber/report.rb,
lib/report_portal/rspec/formatter.rb,
lib/report_portal/cucumber/formatter.rb,
lib/report_portal/cucumber/json_slurper.rb,
lib/report_portal/logging/log4r_outputter.rb,
lib/report_portal/cucumber/parallel_report.rb,
lib/report_portal/logging/logging_appender.rb,
lib/report_portal/cucumber/parallel_formatter.rb
Overview
TODO: Screenshots TODO: Logs
Defined Under Namespace
Modules: Cucumber, RSpec Classes: Log4rOutputter, LoggingAppender, Settings, TestItem
Constant Summary collapse
- LOG_LEVELS =
{ error: 'ERROR', warn: 'WARN', info: 'INFO', debug: 'DEBUG', trace: 'TRACE', fatal: 'FATAL', unknown: 'UNKNOWN' }
- VERSION =
'0.7'
Class Attribute Summary collapse
-
.current_scenario ⇒ Object
Returns the value of attribute current_scenario.
-
.launch_id ⇒ Object
Returns the value of attribute launch_id.
Class Method Summary collapse
-
.close_child_items(parent_id) ⇒ Object
needed for parallel formatter.
- .finish_item(item, status = nil, end_time = nil, force_issue = nil) ⇒ Object
- .finish_launch(end_time = now) ⇒ Object
-
.item_id_of(name, parent_node) ⇒ Object
needed for parallel formatter.
- .now ⇒ Object
-
.patch_logger ⇒ Object
Monkey-patch for built-in Logger class.
- .send_file(status, path, label = nil, time = now, mime_type = 'image/png') ⇒ Object
-
.send_log(status, message, time) ⇒ Object
TODO: implement force finish.
- .start_item(item_node) ⇒ Object
- .start_launch(description, start_time = now) ⇒ Object
- .status_to_level(status) ⇒ Object
Class Attribute Details
.current_scenario ⇒ Object
Returns the value of attribute current_scenario.
44 45 46 |
# File 'lib/reportportal.rb', line 44 def current_scenario @current_scenario end |
.launch_id ⇒ Object
Returns the value of attribute launch_id.
44 45 46 |
# File 'lib/reportportal.rb', line 44 def launch_id @launch_id end |
Class Method Details
.close_child_items(parent_id) ⇒ Object
needed for parallel formatter
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/reportportal.rb', line 157 def close_child_items(parent_id) if parent_id.nil? url = "#{Settings.instance.project_url}/item?filter.eq.launch=#{@launch_id}&filter.size.path=0&page.page=1&page.size=100" else url = "#{Settings.instance.project_url}/item?filter.eq.parent=#{parent_id}&page.page=1&page.size=100" end ids = [] loop do response = do_request(url) { |r| JSON.parse(r.get) } if response.key?('links') link = response['links'].find { |i| i['rel'] == 'next' } url = link.nil? ? nil : link['href'] else url = nil end response['content'].each do |i| ids << i['id'] if i['has_childs'] && i['status'] == 'IN_PROGRESS' end break if url.nil? end ids.each do |id| close_child_items(id) # temporary, we actually only need the id finish_item(TestItem.new(nil, nil, id, nil, nil, nil, nil)) end end |
.finish_item(item, status = nil, end_time = nil, force_issue = nil) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/reportportal.rb', line 90 def finish_item(item, status = nil, end_time = nil, force_issue = nil) unless item.nil? || item.id.nil? || item.closed url = "#{Settings.instance.project_url}/item/#{item.id}" data = { end_time: end_time.nil? ? now : end_time } data[:status] = status unless status.nil? if force_issue && status != :passed # TODO: check for :passed status is probably not needed data[:issue] = { issue_type: 'AUTOMATION_BUG', comment: force_issue.to_s } elsif status == :skipped data[:issue] = { issue_type: 'NOT_ISSUE' } end do_request(url) do |resource| resource.put data.to_json, content_type: :json, &@response_handler end item.closed = true end end |
.finish_launch(end_time = now) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/reportportal.rb', line 71 def finish_launch(end_time = now) url = "#{Settings.instance.project_url}/launch/#{@launch_id}/finish" data = { end_time: end_time } do_request(url) do |resource| resource.put data.to_json, content_type: :json, &@response_handler end end |
.item_id_of(name, parent_node) ⇒ Object
needed for parallel formatter
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/reportportal.rb', line 140 def item_id_of(name, parent_node) if parent_node.is_root? # folder without parent folder url = "#{Settings.instance.project_url}/item?filter.eq.launch=#{@launch_id}&filter.eq.name=#{URI.escape(name)}&filter.size.path=0" else url = "#{Settings.instance.project_url}/item?filter.eq.parent=#{parent_node.content.id}&filter.eq.name=#{URI.escape(name)}" end do_request(url) do |resource| data = JSON.parse(resource.get) if data.key? 'content' data['content'].empty? ? nil : data['content'][0]['id'] else nil # item isn't started yet end end end |
.now ⇒ Object
46 47 48 |
# File 'lib/reportportal.rb', line 46 def now (Time.now.to_f * 1000).to_i end |
.patch_logger ⇒ Object
Monkey-patch for built-in Logger class
24 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 50 51 52 |
# File 'lib/report_portal/logging/logger.rb', line 24 def patch_logger Logger.class_eval do alias_method :orig_add, :add alias_method :orig_write, :<< def add(severity, = nil, progname = nil, &block) ret = orig_add(severity, , progname, &block) unless severity < @level progname ||= @progname if .nil? if block_given? = yield else = progname progname = @progname end end ReportPortal.send_log(format_severity(severity), (format_severity(severity), Time.now, progname, .to_s), ReportPortal.now) end ret end def <<(msg) ret = orig_write(msg) ReportPortal.send_log(ReportPortal::LOG_LEVELS[:unknown], msg.to_s, ReportPortal.now) ret end end end |
.send_file(status, path, label = nil, time = now, mime_type = 'image/png') ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/reportportal.rb', line 119 def send_file(status, path, label = nil, time = now, mime_type='image/png') url = "#{Settings.instance.project_url}/log" unless File.file?(path) extension = ".#{MIME::Types[mime_type].first.extensions.first}" temp = Tempfile.open(['file',extension]) temp.binmode temp.write(Base64.decode64(path)) temp.rewind path = temp end File.open(File.realpath(path), 'rb') do |file| label ||= File.basename(file) json = { level: status_to_level(status), message: label, item_id: @current_scenario.id, time: time, file: { name: File.basename(file) } } data = { :json_request_part => [json].to_json, label => file, :multipart => true, :content_type => 'application/json' } do_request(url) do |resource| resource.post(data, { content_type: 'multipart/form-data' }, &@response_handler) end end end |
.send_log(status, message, time) ⇒ Object
TODO: implement force finish
109 110 111 112 113 114 115 116 117 |
# File 'lib/reportportal.rb', line 109 def send_log(status, , time) unless @current_scenario.nil? || @current_scenario.closed # it can be nil if scenario outline in expand mode is executed url = "#{Settings.instance.project_url}/log" data = { item_id: @current_scenario.id, time: time, level: status_to_level(status), message: .to_s } do_request(url) do |resource| resource.post(data.to_json, content_type: :json, &@response_handler) end end end |
.start_item(item_node) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/reportportal.rb', line 79 def start_item(item_node) url = "#{Settings.instance.project_url}/item" url += "/#{item_node.parent.content.id}" unless item_node.parent && item_node.parent.is_root? item = item_node.content data = { start_time: item.start_time, name: item.name[0, 255], type: item.type.to_s, launch_id: @launch_id, description: item.description } data[:tags] = item. unless item..empty? do_request(url) do |resource| JSON.parse(resource.post(data.to_json, content_type: :json, &@response_handler))['id'] end end |
.start_launch(description, start_time = now) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/reportportal.rb', line 63 def start_launch(description, start_time = now) url = "#{Settings.instance.project_url}/launch" data = { name: Settings.instance.launch, start_time: start_time, tags: Settings.instance., description: description, mode: Settings.instance.launch_mode } @launch_id = do_request(url) do |resource| JSON.parse(resource.post(data.to_json, content_type: :json, &@response_handler))['id'] end end |
.status_to_level(status) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/reportportal.rb', line 50 def status_to_level(status) case status when :passed LOG_LEVELS[:info] when :failed, :undefined, :pending, :error LOG_LEVELS[:error] when :skipped LOG_LEVELS[:warn] else LOG_LEVELS.fetch(status, LOG_LEVELS[:info]) end end |