Module: Rpruby
- Defined in:
- lib/rpruby/rspec/formatter.rb,
lib/rpruby.rb,
lib/rpruby/version.rb,
lib/rpruby/settings.rb,
lib/rpruby/event_bus.rb,
lib/rpruby/http_client.rb,
lib/rpruby/logging/logger.rb,
lib/rpruby/cucumber/report.rb,
lib/rpruby/models/test_item.rb,
lib/rpruby/cucumber/formatter.rb,
lib/rpruby/cucumber/messagereport.rb,
lib/rpruby/logging/log4r_outputter.rb,
lib/rpruby/cucumber/parallel_report.rb,
lib/rpruby/logging/logging_appender.rb,
lib/rpruby/models/item_search_options.rb,
lib/rpruby/cucumber/parallel_formatter.rb,
lib/rpruby/events/prepare_start_item_request.rb
Overview
TODO: Screenshots TODO: Logs
Defined Under Namespace
Modules: Cucumber, Events, RSpec Classes: Error, 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 =
'1.2.2'.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.
-
.launch_id_to_number ⇒ 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.
23 24 25 |
# File 'lib/rpruby.rb', line 23 def current_scenario @current_scenario end |
.launch_id ⇒ Object
Returns the value of attribute launch_id.
23 24 25 |
# File 'lib/rpruby.rb', line 23 def launch_id @launch_id end |
Class Method Details
.close_child_items(parent_id) ⇒ Object
needed for parallel formatter
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/rpruby.rb', line 150 def close_child_items(parent_id) path = if parent_id.nil? "item?filter.eq.launchId=#{launch_id_to_number}" 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
125 126 127 |
# File 'lib/rpruby.rb', line 125 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
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rpruby.rb', line 64 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
49 50 51 52 |
# File 'lib/rpruby.rb', line 49 def finish_launch(end_time = now) data = { end_time: end_time } send_request(:put, "launch/#{@launch_id}/finish", json: data) end |
.get_items(filter_options = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rpruby.rb', line 107 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
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/rpruby.rb', line 130 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 |
.launch_id_to_number ⇒ Object
needed for parallel formatter
143 144 145 146 147 |
# File 'lib/rpruby.rb', line 143 def launch_id_to_number() path = "launch/#{@launch_id}" data = send_request(:get, path) data['id'] end |
.now ⇒ Object
25 26 27 |
# File 'lib/rpruby.rb', line 25 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.
178 179 180 |
# File 'lib/rpruby.rb', line 178 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/rpruby/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 Rpruby.send_log(format_severity(severity), (format_severity(severity), Time.now, progname, .to_s), Rpruby.now) end ret end def <<(msg) ret = orig_write(msg) Rpruby.send_log(Rpruby::LOG_LEVELS[:unknown], msg.to_s, Rpruby.now) ret end end end |
.send_file(status, path_or_src, label = nil, time = now, mime_type = 'image/png') ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rpruby.rb', line 87 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
80 81 82 83 84 85 |
# File 'lib/rpruby.rb', line 80 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
54 55 56 57 58 59 60 61 62 |
# File 'lib/rpruby.rb', line 54 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
42 43 44 45 46 47 |
# File 'lib/rpruby.rb', line 42 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
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rpruby.rb', line 29 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 |