class RkCucumber::ResultsSender
Attributes
tmp_data[R]
Public Class Methods
new()
click to toggle source
# File lib/results_keeper/results_sender.rb, line 14 def initialize @data_generator = RkCucumber::TestDataGenerator.new @tmp_data ||= {} @tmp_data[:tests] ||= [] end
Public Instance Methods
add_test_to_tmp(scenario, test_started_at)
click to toggle source
# File lib/results_keeper/results_sender.rb, line 92 def add_test_to_tmp(scenario, test_started_at) @tmp_data[:tests] << @data_generator.test_data(scenario, @revision, test_started_at) RkCucumber::Messages.error_not_sent_scenario(@tmp_data[:tests].count) end
send_json(body, path, message_to_client=nil)
click to toggle source
# File lib/results_keeper/results_sender.rb, line 57 def send_json(body, path, message_to_client=nil) body['secret_key'] = RkCucumber::Config.config[:secret_key] @path = "/api/#{path}" @body = body.to_json begin uri = URI("#{RkCucumber::Config.config[:report_server_host]}:#{RkCucumber::Config.config[:report_server_port]}#{@path}") http = Net::HTTP::Persistent.new http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(@path, initheader = {'Content-Type' => 'application/json'}) request.body = @body response = http.request(uri, request) RkCucumber::Messages.info_message_to_client(response, message_to_client) JSON.parse(response.body) rescue RkCucumber::Messages.warn_problem_with_rk false end end
send_not_sent_scenarios()
click to toggle source
# File lib/results_keeper/results_sender.rb, line 45 def send_not_sent_scenarios if @revision @tmp_data[:tests].each do |s| s[:revision_id] = @revision['revision_id'] unless s[:revision_id] RkCucumber::Messages.info_trying_resend(s[:name]) send_json(s, RkCucumber::Config.default[:api][:test_path]) if @revision end else false end end
send_revision()
click to toggle source
# File lib/results_keeper/results_sender.rb, line 20 def send_revision @revision = send_json(@data_generator.revision_data, RkCucumber::Config.default[:api][:revision_path], "#{RkCucumber::Config.config[:project_name]} > #{RkCucumber::Config.config[:revision_name]} started") end
send_revision_complete()
click to toggle source
# File lib/results_keeper/results_sender.rb, line 26 def send_revision_complete send_not_sent_scenarios send_json(@data_generator.revision_completed_data, RkCucumber::Config.default[:api][:revision_path], "#{RkCucumber::Config.config[:revision_name]} completed") end
send_screenshot(screenshot_path)
click to toggle source
# File lib/results_keeper/results_sender.rb, line 76 def send_screenshot(screenshot_path) begin params = {project: @revision['project_id'], revision: @revision['revision_id'], test: @test['id']} RestClient::Request.execute(:url => "#{RkCucumber::Config.config[:report_server_host]}:"+ "#{RkCucumber::Config.config[:report_server_port]}/api/tests/upload_screenshot", :method => :post, :verify_ssl => false, :name_of_file_param => File.new(screenshot_path), :payload => {:multipart => true, :name_of_file_param => File.new(screenshot_path)}, :headers => {:accept => :json, params: {body: params}}) File.delete(screenshot_path) rescue RkCucumber::Messages.error_send_screenshot end end
send_test(scenario, test_started_at)
click to toggle source
# File lib/results_keeper/results_sender.rb, line 33 def send_test(scenario, test_started_at) # In case if the host is not available we need to send revision once more (when it comes back) send_revision unless @revision return nil unless @revision screenshot_path = @data_generator.save_screenshot(scenario) if ENV['RK_SEND_SCREENSHOTS'] @test = send_json(@data_generator.test_data(scenario, @revision, test_started_at), RkCucumber::Config.default[:api][:test_path]) return nil unless @test send_screenshot(screenshot_path) if screenshot_path @test end