Class: Maze::Plugins::BugsnagReportingPlugin

Inherits:
Object
  • Object
show all
Defined in:
lib/maze/plugins/bugsnag_reporting_plugin.rb

Instance Method Summary collapse

Instance Method Details

#selenium_report?(exception) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/maze/plugins/bugsnag_reporting_plugin.rb', line 57

def selenium_report?(exception)
  exception.class.to_s.include?('Selenium')
end

#test_case(test_case) ⇒ Object



17
18
19
20
21
22
23
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
53
54
55
# File 'lib/maze/plugins/bugsnag_reporting_plugin.rb', line 17

def test_case(test_case)
  configuration.on_event(:test_step_finished) do |event|
    @last_test_step = event.test_step if event.result.failed?
  end

  configuration.on_event(:test_case_finished) do |event|

    # Ensure we're in the correct test case and that it's failed
    next unless event.test_case.eql?(test_case) && event.result.failed?

    Bugsnag.notify(event.result.exception) do |bsg_event|
      bsg_event.api_key = ENV['MAZE_SCENARIO_BUGSNAG_API_KEY'] unless selenium_report?(event.result.exception)

      unless @last_test_step.nil?

        repo = ENV['BUILDKITE_PIPELINE_SLUG']
        bsg_event.context = if repo.nil?
                              @last_test_step.location
                            else
                              "#{repo}/#{@last_test_step.location}"
                            end
        bsg_event.grouping_hash = @last_test_step.location

        bsg_event.(:'scenario', {
          'failing step': @last_test_step.to_s,
          'failing step location': @last_test_step.location
        })
      end
      bsg_event.(:'scenario', {
        'scenario name': test_case.name,
        'scenario location': test_case.location,
        'scenario tags': test_case.tags,
        'scenario duration (mS)': event.result.duration.nanoseconds/1000000
      })
    end
  end

  super
end