Module: ReportPortal
- Defined in:
- lib/report_portal/rspec/formatter.rb,
lib/reportportal.rb,
lib/report_portal/version.rb,
lib/report_portal/settings.rb,
lib/report_portal/event_bus.rb,
lib/report_portal/http_client.rb,
lib/report_portal/logging/logger.rb,
lib/report_portal/cucumber/report.rb,
lib/report_portal/models/test_item.rb,
lib/report_portal/cucumber/formatter.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/models/item_search_options.rb,
lib/report_portal/cucumber/parallel_formatter.rb,
lib/report_portal/events/prepare_start_item_request.rb
Overview
TODO: Screenshots TODO: Logs
Defined Under Namespace
Modules: Cucumber, Events, RSpec Classes: EventBus, HttpClient, ItemSearchOptions, Log4rOutputter, LoggingAppender, Settings, TestItem
Constant Summary collapse
- LOG_LEVELS =
{ error: 'ERROR', warn: 'WARN', info: 'INFO', debug: 'DEBUG', trace: 'TRACE', fatal: 'FATAL', unknown: 'UNKNOWN' }.freeze
- VERSION =
'0.7'.freeze
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.
- .delete_items(item_ids) ⇒ Object
- .finish_item(item, status = nil, end_time = nil, force_issue = nil) ⇒ Object
- .finish_launch(end_time = now) ⇒ Object
- .get_items(filter_options = {}) ⇒ Object
-
.item_id_of(name, parent_node) ⇒ Object
needed for parallel formatter.
- .now ⇒ Object
-
.on_event(name, &proc) ⇒ Object
Registers an event.
-
.patch_logger ⇒ Object
Monkey-patch for built-in Logger class.
- .send_file(status, path_or_src, 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.
20 21 22 |
# File 'lib/reportportal.rb', line 20 def current_scenario @current_scenario end |
.launch_id ⇒ Object
Returns the value of attribute launch_id.
20 21 22 |
# File 'lib/reportportal.rb', line 20 def launch_id @launch_id end |
Class Method Details
.close_child_items(parent_id) ⇒ Object
needed for parallel formatter
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/reportportal.rb', line 142 def close_child_items(parent_id) path = if parent_id.nil? "item?filter.eq.launch=#{@launch_id}&filter.size.path=0&page.page=1&page.size=100" else "item?filter.eq.parent=#{parent_id}&page.page=1&page.size=100" end ids = [] loop do data = send_request(:get, path) if data.key?('links') link = data['links'].find { |i| i['rel'] == 'next' } url = link.nil? ? nil : link['href'] else url = nil end data['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) finish_item(TestItem.new(id: id)) end end |
.delete_items(item_ids) ⇒ Object
124 125 126 |
# File 'lib/reportportal.rb', line 124 def delete_items(item_ids) send_request(:delete, 'item', params: { ids: item_ids }) end |
.finish_item(item, status = nil, end_time = nil, force_issue = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/reportportal.rb', line 63 def finish_item(item, status = nil, end_time = nil, force_issue = nil) unless item.nil? || item.id.nil? || item.closed 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 send_request(:put, "item/#{item.id}", json: data) item.closed = true end end |
.finish_launch(end_time = now) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/reportportal.rb', line 46 def finish_launch(end_time = now) data = { end_time: end_time } @finished_launch = send_request(:put, "launch/#{@launch_id}/finish", json: data) @launch_link = @finished_launch['link'] print @launch_link end |
.get_items(filter_options = {}) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/reportportal.rb', line 106 def get_items( = {}) page_size = 100 max_pages = 100 all_items = [] 1.step.each do |page_number| raise 'Too many pages with the results were returned' if page_number > max_pages = ItemSearchOptions.new({ page_size: page_size, page_number: page_number }.merge()) page_items = send_request(:get, 'item', params: .query_params)['content'].map do |item_params| TestItem.new(item_params) end all_items += page_items break if page_items.size < page_size end all_items end |
.item_id_of(name, parent_node) ⇒ Object
needed for parallel formatter
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/reportportal.rb', line 129 def item_id_of(name, parent_node) path = if parent_node.is_root? # folder without parent folder "item?filter.eq.launch=#{@launch_id}&filter.eq.name=#{CGI.escape(name)}&filter.size.path=0" else "item?filter.eq.parent=#{parent_node.content.id}&filter.eq.name=#{CGI.escape(name)}" end data = send_request(:get, path) if data.key? 'content' data['content'].empty? ? nil : data['content'][0]['id'] end end |
.now ⇒ Object
22 23 24 |
# File 'lib/reportportal.rb', line 22 def now (current_time.to_f * 1000).to_i end |
.on_event(name, &proc) ⇒ Object
Registers an event. The proc will be called back with the event object.
170 171 172 |
# File 'lib/reportportal.rb', line 170 def on_event(name, &proc) event_bus.on(name, &proc) end |
.patch_logger ⇒ Object
Monkey-patch for built-in Logger class
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/report_portal/logging/logger.rb', line 6 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_or_src, label = nil, time = now, mime_type = 'image/png') ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/reportportal.rb', line 86 def send_file(status, path_or_src, label = nil, time = now, mime_type = 'image/png') str_without_nils = path_or_src.to_s.gsub("\0", '') # file? does not allow NULLs inside the string if File.file?(str_without_nils) send_file_from_path(status, path_or_src, label, time, mime_type) else if mime_type =~ /;base64$/ mime_type = mime_type[0..-8] path_or_src = Base64.decode64(path_or_src) end extension = ".#{MIME::Types[mime_type].first.extensions.first}" Tempfile.open(['report_portal', extension]) do |tempfile| tempfile.binmode tempfile.write(path_or_src) tempfile.rewind send_file_from_path(status, tempfile.path, label, time, mime_type) end end end |
.send_log(status, message, time) ⇒ Object
TODO: implement force finish
79 80 81 82 83 84 |
# File 'lib/reportportal.rb', line 79 def send_log(status, , time) unless @current_scenario.nil? || @current_scenario.closed # it can be nil if scenario outline in expand mode is executed data = { item_id: @current_scenario.id, time: time, level: status_to_level(status), message: .to_s } send_request(:post, 'log', json: data) end end |
.start_item(item_node) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/reportportal.rb', line 53 def start_item(item_node) path = 'item' path += "/#{item_node.parent.content.id}" unless 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? event_bus.broadcast(:prepare_start_item_request, request_data: data) send_request(:post, path, json: data)['id'] end |
.start_launch(description, start_time = now) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/reportportal.rb', line 39 def start_launch(description, start_time = now) required_data = { name: Settings.instance.launch, start_time: start_time, description: description, mode: Settings.instance.launch_mode } data = (required_data, Settings.instance) @launch_id = send_request(:post, 'launch', json: data)['id'] end |
.status_to_level(status) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/reportportal.rb', line 26 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 |