class TestRail::Connection
Public Class Methods
Get ID of all test cases from current test run
cases = client.send_get(“get_tests/12”)
# File lib/test_rail_integration/generator/connection.rb, line 57 def self.cases_by_default(test_run_id) client.send_get("get_tests/#{test_run_id}") end
# File lib/test_rail_integration/generator/connection.rb, line 61 def self.cases_ids_by_default(test_run_id) cases = cases_by_default(test_run_id) cases.map { |test_case| test_case["case_id"]} end
# File lib/test_rail_integration/generator/connection.rb, line 66 def self.cases_ids_by_type(test_run_id, type) cases = cases_by_default(test_run_id) cases.map { |test_case| test_case["case_id"] if test_case["type_id"].equal?(type)}.compact end
Take all test types
# File lib/test_rail_integration/generator/connection.rb, line 117 def self.cases_with_types types = TYPES cases = client.send_get("get_cases/#{project_id}&suite_id=#{test_suite_id}&type_id=#{types}") case_ids = cases.map { |test_case| test_case["id"] } case_ids end
Changing name of test run from <test run name> in progress to <test run name>
VN LIVE_TEST in progress => VN LIVE_TEST
# File lib/test_rail_integration/generator/connection.rb, line 136 def self.change_test_run_name(run_id = test_run_id) new_name = test_run_name.gsub(IN_PROGRESS, "") client.send_post("update_run/#{run_id}", {name: new_name}) end
Creates connection to TestRail
server
client = TestRail::APIClient.new
('<TestRail server>',“<User email>”,“<User password>”)
# File lib/test_rail_integration/generator/connection.rb, line 22 def self.client @client_test_rail ||= TestRail::APIClient.new(CONNECTION_DATA) end
Send test result to TestRail
for current test run client.send_post(“add_result_for_case/<number_of test run>/<test case id>”, <result that pushes>)
client.send_post(“add_result_for_case/12/3131”, status_id: '1', comment: “Test passed” )
# File lib/test_rail_integration/generator/connection.rb, line 32 def self.commit_test_result(test_case_result) client.send_post("add_result_for_case/#{test_run_id}/#{test_case_result.test_case_id}", test_case_result.to_test_rail_api) end
Create test run in test rail for project with name
# File lib/test_rail_integration/generator/connection.rb, line 48 def self.create_test_run_with_name(name) client.send_post("add_run/#{project_id}", {suite_id: test_suite_id, name: name, include_all: false, case_ids: cases_with_types}) end
Get info about test cases from TestRail
# File lib/test_rail_integration/generator/connection.rb, line 127 def self.get_case_info(case_id) client.send_get("get_case/#{case_id}") end
Obtaining of all previous test results for current test case
client.send_get(“get_results_for_case/12/3534”)
# File lib/test_rail_integration/generator/connection.rb, line 41 def self.get_test_results(case_id) client.send_get("get_results_for_case/#{test_run_id}/#{case_id}") end
Setting project id
# File lib/test_rail_integration/generator/connection.rb, line 88 def self.project_id @project_id ||= PROJECT_ID end
Getting information about test run
# File lib/test_rail_integration/generator/connection.rb, line 103 def self.test_run_data(id_of_run=test_run_id) client.send_get("get_run/#{id_of_run}") end
Setting test run id value
# File lib/test_rail_integration/generator/connection.rb, line 81 def self.test_run_id @test_run_id ||= TEST_RUN_ID end
Setting up test run id
# File lib/test_rail_integration/generator/connection.rb, line 74 def self.test_run_id=(test_run_id) @test_run_id = test_run_id end
Get test run name
# File lib/test_rail_integration/generator/connection.rb, line 110 def self.test_run_name(id_of_run=test_run_id) test_run_data(id_of_run)["name"] end
Setting test suite id
# File lib/test_rail_integration/generator/connection.rb, line 96 def self.test_suite_id @test_suite_id ||= TEST_SUITE end
Update test run with fields
# File lib/test_rail_integration/generator/connection.rb, line 144 def self.update_test_run(run_id, name_of_run = nil, description = nil, assigned_to_id = nil ) client.send_post("update_run/#{run_id}", {name: name_of_run, description: description, assignedto_id: assigned_to_id}) end
Write TeamCity build id to TestRail
# File lib/test_rail_integration/generator/connection.rb, line 151 def self.write_build_url(test_run_id, build_id) description = "Build url: #{build_id}" update_test_run(test_run_id, nil, description, nil) end