Sha256: eb862fba7ef2efb1a2d79e32bafbd58eeb88a7933a1575b7a434d0733fb1fdac

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

require "jericho/version"

module Jericho
  def self.reporter(parsed_report)
    list_of_scenarios_results = {}
    parsed_report.each do |element|
      element['elements'].each do |scenario|
        scenario_status = 'Passed'
        scenario['steps'].each do |step|
          scenario_status = 'Failed' if step['result']['status'] != 'passed'
        end
        list_of_scenarios_results[(scenario['name']).to_s] = scenario_status
      end
    end
    list_of_scenarios_results
  end

  def self.comparison_reporter(list_of_scenarios_results1, list_of_scenarios_results2)
    failed_tests = list_of_scenarios_results2.select { |k, v| v == 'Failed' }.map do |k, v|
      {
        test_name: k === '' ? k = 'Background' : k,
        actual_status: v,
        previous_status: list_of_scenarios_results1[k]
      }.reject { |_k, v| v.nil? }
    end

    {
      passed: list_of_scenarios_results2.size - failed_tests.size,
      failed: failed_tests.size,
      failed_tests: failed_tests
    }
  end

  def self.purify
    arr = Dir['*.json'].sort!
    arr.length <= 1 ? parsed_report1 = {} : parsed_report1 = JSON.parse(File.read(arr[-2]))
    parsed_report2 = JSON.parse(File.read(arr.last))
    result = comparison_reporter(reporter(parsed_report1), reporter(parsed_report2))
  end

  def self.repent
    client = Slack::Web::Client.new
    client.chat_postMessage(
      channel: '#autotests',
      text:
      "Test run results for #{$driver.caps[:deviceName]}, #{$driver.caps[:platformName]} #{$driver.caps[:platformVersion]}:
      Passed tests count: #{result[:passed]},
      Failed tests count: #{result[:failed]},",
      attachments: [
        {
         text: "*Failed tests*:
#{'Test name and previous status:' + ("\n") + result[:failed_tests].map { |t| t.values_at(:test_name, :previous_status) }.join("\n") }
          ",
        color: 'danger'
      }
      ],
      mrkdwn: true,
      as_user: true,
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jericho-0.2.0 lib/jericho.rb