Class: AssertThatBDD::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/assertthat-bdd.rb

Class Method Summary collapse

Class Method Details

.upload(accessKey: ENV['ASSERTTHAT_ACCESS_KEY'], secretKey: ENV['ASSERTTHAT_ACCESS_KEY'], projectId: nil, runName: 'Test run '+Time.now.strftime("%d %b %Y %H:%M:%S"), jsonReportFolder: './reports', jsonReportIncludePattern: '.*.json', jiraServerUrl: nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/assertthat-bdd.rb', line 49

def self.upload(accessKey: ENV['ASSERTTHAT_ACCESS_KEY'], secretKey: ENV['ASSERTTHAT_ACCESS_KEY'], projectId: nil, runName: 'Test run '+Time.now.strftime("%d %b %Y %H:%M:%S"), jsonReportFolder: './reports', jsonReportIncludePattern: '.*.json', jiraServerUrl: nil  )
    url = "https://bdd.assertthat.app/rest/api/1/project/" + projectId + "/report"
    url = jiraServerUrl+"/rest/assertthat/latest/project/"+projectId+"/client/report" unless jiraServerUrl.nil?
  files = Find.find(jsonReportFolder).grep(/#{jsonReportIncludePattern}/)
  puts "*** INFO: #{files.count} files found matching parretn #{jsonReportIncludePattern}:"
  puts "*** INFO: #{files}"
  runId = -1
  files.each do |f|
      request = RestClient::Request.new(
        :method => :post,
        :url => url,
        :user => accessKey,
        :password => secretKey,
        :payload => {
          :multipart => true,
          :file => File.new(f, 'rb')
      },
      :headers => { :params =>{:runName => runName, :runId=> runId}}
      )      
      begin
    response = request.execute 
  rescue => e
    if e.respond_to?('response') then
        if e.response.respond_to?('code') then
          case e.response.code
            when 401
              puts '*** ERROR: Unauthorized error (401). Supplied secretKey/accessKey is invalid'
            when 500
              puts '*** ERROR: Jira server error (500)'
          end
        end
      else
        puts "*** ERROR: Failed to submit json #{f}: " + e.message
      end
return
      end
      resposne_json = JSON.parse(response)
      if resposne_json['result'] == 'success'
runId = resposne_json['runId']
      else
   puts "*** ERROR: Failed to submit json #{f}: " + resposne_json['message']
      end  
    end
end