Class: ReportPortal::Cucumber::Report Private

Inherits:
Object
  • Object
show all
Defined in:
lib/report_portal/cucumber/report.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

ParallelReport

Instance Method Summary collapse

Constructor Details

#initializeReport

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Report.



39
40
41
42
43
# File 'lib/report_portal/cucumber/report.rb', line 39

def initialize
  @last_used_time = 0
  @root_node = Tree::TreeNode.new('')
  start_launch
end

Instance Method Details

#attach_to_launch?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


35
36
37
# File 'lib/report_portal/cucumber/report.rb', line 35

def attach_to_launch?
  ReportPortal::Settings.instance.formatter_modes.include?('attach_to_launch')
end

#done(desired_time = ReportPortal.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



135
136
137
138
139
140
141
142
143
# File 'lib/report_portal/cucumber/report.rb', line 135

def done(desired_time = ReportPortal.now)
  end_feature(desired_time) if @feature_node

  unless attach_to_launch?
    close_all_children_of(@root_node) # Folder items are closed here as they can't be closed after finishing a feature
    time_to_send = time_to_send(desired_time)
    ReportPortal.finish_launch(time_to_send)
  end
end

#embed(src, mime_type, label, desired_time = ReportPortal.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



149
150
151
# File 'lib/report_portal/cucumber/report.rb', line 149

def embed(src, mime_type, label, desired_time = ReportPortal.now)
  ReportPortal.send_file(:info, src, label, time_to_send(desired_time),mime_type)
end

#parallel?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


31
32
33
# File 'lib/report_portal/cucumber/report.rb', line 31

def parallel?
  false
end

#puts(message, desired_time = ReportPortal.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



145
146
147
# File 'lib/report_portal/cucumber/report.rb', line 145

def puts(message, desired_time = ReportPortal.now)
  ReportPortal.send_log(:info, message, time_to_send(desired_time))
end

#start_launch(desired_time = ReportPortal.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/report_portal/cucumber/report.rb', line 45

def start_launch(desired_time = ReportPortal.now)
  if attach_to_launch?
    ReportPortal.launch_id =
      if ReportPortal::Settings.instance.launch_id
        ReportPortal::Settings.instance.launch_id
      else
        file_path = ReportPortal::Settings.instance.file_with_launch_id || (Pathname(Dir.tmpdir) + 'rp_launch_id.tmp')
        File.read(file_path)
      end
    $stdout.puts "Attaching to launch #{ReportPortal.launch_id}"
  else
    description = ReportPortal::Settings.instance.description
    description ||= ARGV.map { |arg| arg.gsub(/rp_uuid=.+/, "rp_uuid=[FILTERED]") }.join(' ')
    ReportPortal.start_launch(description, time_to_send(desired_time))
  end
end

#test_case_finished(event, desired_time = ReportPortal.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/report_portal/cucumber/report.rb', line 81

def test_case_finished(event, desired_time = ReportPortal.now)
  result = event.result
  status = result.to_sym
  issue = nil
  if [:undefined, :pending].include?(status)
    status = :failed
    issue = result.message
  end
  ReportPortal.finish_item(ReportPortal.current_scenario, status, time_to_send(desired_time), issue)
  ReportPortal.current_scenario = nil
end

#test_case_started(event, desired_time = ReportPortal.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: time should be a required argument



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/report_portal/cucumber/report.rb', line 62

def test_case_started(event, desired_time = ReportPortal.now) # TODO: time should be a required argument
  test_case = event.test_case
  feature = test_case.feature
  unless same_feature_as_previous_test_case?(feature)
    end_feature(desired_time) if @feature_node
    start_feature_with_parentage(feature, desired_time)
  end

  name = "#{test_case.keyword}: #{test_case.name}"
  description = test_case.location.to_s
  tags = test_case.tags.map(&:name)
  type = :STEP

  ReportPortal.current_scenario = ReportPortal::TestItem.new(name, type, nil, time_to_send(desired_time), description, false, tags)
  scenario_node = Tree::TreeNode.new(SecureRandom.hex, ReportPortal.current_scenario)
  @feature_node << scenario_node
  ReportPortal.current_scenario.id = ReportPortal.start_item(scenario_node)
end

#test_step_finished(event, desired_time = ReportPortal.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/report_portal/cucumber/report.rb', line 107

def test_step_finished(event, desired_time = ReportPortal.now)
  test_step = event.test_step
  result = event.result
  status = result.to_sym

  if [:failed, :pending, :undefined].include?(status)
    exception_info = if [:failed, :pending].include?(status)
                       ex = result.exception
                       sprintf("%s: %s\n  %s", ex.class.name, ex.message, ex.backtrace.join("\n  "))
                     else
                       sprintf("Undefined step: %s:\n%s", test_step.text, test_step.source.last.backtrace_line)
                     end
    ReportPortal.send_log(:error, exception_info, time_to_send(desired_time))
  end

  if status != :passed
    log_level = (status == :skipped)? :warn : :error
    step_type = if step?(test_step)
                  'Step'
                else
                  hook_class_name = test_step.source.last.class.name.split('::').last
                  location = test_step.location
                  "#{hook_class_name} at `#{location}`"
                end
    ReportPortal.send_log(log_level, "#{step_type} #{status}", time_to_send(desired_time))
  end
end

#test_step_started(event, desired_time = ReportPortal.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/report_portal/cucumber/report.rb', line 93

def test_step_started(event, desired_time = ReportPortal.now)
  test_step = event.test_step
  if step?(test_step) # `after_test_step` is also invoked for hooks
    step_source = test_step.source.last
    message = "-- #{step_source.keyword}#{step_source.text} --"
    if step_source.multiline_arg.doc_string?
      message << %(\n"""\n#{step_source.multiline_arg.content}\n""")
    elsif step_source.multiline_arg.data_table?
      message << step_source.multiline_arg.raw.reduce("\n") { |acc, row| acc << "| #{row.join(' | ')} |\n" }
    end
    ReportPortal.send_log(:trace, message, time_to_send(desired_time))
  end
end