require 'savon' require 'json' module RLib class SpiraAgent @cookies @client @test_name_table @project_id # Initializes Spira Agent, set up savon client and makes connection to the Service point def initialize(user_name, password, spira_wsdl, project_id = nil, folder_id = nil) @client = Savon.client(wsdl: spira_wsdl) connection = @client.call(:connection_authenticate, message: {user_name: user_name, password: password}) @cookies = connection.http.cookies #Retrieves the table which maps test names to the unique test IDs automatically generated by spira (can be found in test URL) if project_id != nil and folder_id != nil set_test_name_table(project_id, folder_id) @project_id = project_id end end # Returns the table with test names mapped to test IDs def get_test_table_from_spira_by_folder(project_id, folder_id) #Connects to project Id @client.call(:connection_connect_to_project, message: {project_id: project_id}, cookies: @cookies) resp = @client.call(:test_case_retrieve_by_folder, message: {test_casefolder_id: folder_id}, cookies: @cookies) # gets the response body and retrieves an array with the test cases test_cases = resp.body[:test_case_retrieve_by_folder_response][:test_case_retrieve_by_folder_result][:remote_test_case] test_table = {} # for each test case slice the name and the ID of the test case and save it in the table test_cases.each do |test| test_table[test[:name]] = test[:test_case_id] end return test_table end # Returns Test information from a specific Test Case def get_test_case_from_spira_by_id(project_id, test_case_id) test_case = {} @client.call(:connection_connect_to_project, message: {project_id: project_id}, cookies: @cookies) resp = @client.call(:test_case_retrieve_by_id, message: {test_case_id: test_case_id}, cookies: @cookies) # getting the response body response_body = resp.body[:test_case_retrieve_by_id_response][:test_case_retrieve_by_id_result] test_case['tcDescription'] = response_body[:description].gsub( %r{?[^>]+?>}, '' ) test_case['tcName'] = response_body[:name] steps_data = response_body[:test_steps][:remote_test_step] steps = [] # Parses array and returns result if steps_data # if multiple steps if steps_data.kind_of?(Array) steps_data.each_with_index{|step| temp_step = {} temp_step['tsExpectedResult'] = step[:expected_result] temp_step['tsDescription'] = step[:description].gsub('