class TestGemTM::SpiraAgent
Public Class Methods
new(user_name, password, project_id = nil, folder_id = nil)
click to toggle source
initializing the spira agent
# File lib/TestGemTM/SpiraAgent.rb, line 21 def initialize user_name, password, project_id = nil, folder_id = nil # setting up savon client, passing the wsdl address @client = Savon.client(wsdl: 'http://spirateam.ypg.com/Services/v4_0/ImportExport.svc?wsdl') #connecting to the service point #the complete list of the functions can be found at spira documentation pages. connection = @client.call(:connection_authenticate, message: {user_name: user_name, password: password}) # saving cookies for further use, to avoid authentication every time @cookies = connection.http.cookies #retrieving 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
Public Instance Methods
get_expected_result_by_id(project_id, test_case_id)
click to toggle source
this method just returns the expected result in array for a given project and test case in JSON format
# File lib/TestGemTM/SpiraAgent.rb, line 92 def get_expected_result_by_id(project_id, test_case_id) test_case = self.retrieve_from_spira_by_id(project_id, test_case_id) steps = test_case['tcSteps'] expected = [] expected_hash = {} steps.each{|le_step| # expected.push JSON.parse(le_step['tsExpectedResult']) le_step['tsExpectedResult'].split('</div>').each { |item| expected.push(item.gsub( %r{</?[^>]+?>}, '' )) } } expected.each { |item| items = item.split(':'); expected_hash.merge!({items[0] => items[1] })} { :expected_results => expected_hash, :test_case_name => test_case['tcName'], :test_case_description => test_case['tcDescription'] } end
get_expected_result_by_name(test_case_name)
click to toggle source
This method allows to pass the test names and get the expected result shipped from the Spira. To get the expected results first initialize test names by calling set_test_name_table
(projectId, folderId) method and provide the ID of the project and the ID of the folder that contains the test cases. Once the test tables are initialized get the expected result by simply providing the name of the desired test case.
# File lib/TestGemTM/SpiraAgent.rb, line 109 def get_expected_result_by_name(test_case_name) if @test_name_table == nil raise 'ERROR: test_name_table is not set, call set_test_name_table(project_id, folder_id) method to initialize the '+ 'test_name_table and project ID. Alternatively you can call get_expected_result_by_id(project_id, test_case_id) or' + 'set_test_name_table(project_id, folder_id) to set test_name_table.' end test_id = @test_name_table[test_case_name] if test_id == nil raise "ERROR: Program returned empty ID for the test name \"#{test_case_name}\"" end get_expected_result_by_id(@project_id, test_id) end
retrieve_from_spira_by_id(project_id, test_case_id)
click to toggle source
# File lib/TestGemTM/SpiraAgent.rb, line 57 def retrieve_from_spira_by_id(project_id, test_case_id) test_case = {} #connecting to project Id. Note: project id can be found on url on spira. # Ex. http://spirateam.ypg.com/49/test_case/0000000.aspx id is 49. @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 = [] #parsing and returning the 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('<div>',"\n").gsub(/<[^>]*>/,'').strip steps.push temp_step } else temp_step = {} temp_step['tsExpectedResult'] = steps_data[:expected_result] temp_step['tsDescription'] = steps_data[:description].gsub('<div>',"\n").gsub(/<[^>]*>/,'').strip steps.push temp_step end end test_case['tcSteps'] = steps return test_case end
retrieve_test_table_from_spira_by_folder(project_id, folder_id)
click to toggle source
returns the table with test names mapped to test IDs to allow to retrßy name
# File lib/TestGemTM/SpiraAgent.rb, line 43 def retrieve_test_table_from_spira_by_folder(project_id, folder_id) #connecting to project Id. Note: project id can be found on url on spira. @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) # getting the response body and retrieving 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
set_test_name_table(project_id, folder_id)
click to toggle source
this function sets the test_name_table variable to the map that contains mapping of test names to the test IDs
# File lib/TestGemTM/SpiraAgent.rb, line 37 def set_test_name_table(project_id, folder_id) @project_id = project_id @test_name_table = self.retrieve_test_table_from_spira_by_folder(project_id, folder_id) end