class TestRail::Connection

Public Class Methods

cases_id(test_run_id) click to toggle source

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 95
def self.cases_id(test_run_id)
  cases = client.send_get("get_tests/#{test_run_id}")
  cases.map { |test_case| test_case["case_id"] }
end
cases_with_types() click to toggle source

Take all test types

# File lib/test_rail_integration/generator/connection.rb, line 146
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
change_test_run_name(run_id = test_run_id) click to toggle source

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 158
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
client() click to toggle source

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
commit_test_result(test_case_result) click to toggle source

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_new_test_run_with_name() click to toggle source

Send request for creation test run with name (“add_run/3”, {suite_id: 3, name “New test run”, include_all: false, case_ids: C31, C32, C33}

# File lib/test_rail_integration/generator/connection.rb, line 167
def self.create_new_test_run_with_name
  client.send_post("add_run/#{project_id}", {suite_id: test_suite_id, name: generate_test_run_name, include_all: false, case_ids: cases_with_types})
end
create_test_run_with_name(name) click to toggle source

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
generate_test_run_name() click to toggle source

Generate name for test run with date

# File lib/test_rail_integration/generator/connection.rb, line 181
def self.generate_test_run_name
  "Test run #{Time.now.strftime("%d/%m/%Y")}"
end
get_indexes_of_fails(test_case_id) click to toggle source

Get indexes of failed results

# File lib/test_rail_integration/generator/connection.rb, line 76
def self.get_indexes_of_fails(test_case_id)
  indexes = get_test_result(test_case_id).map.with_index { |result, index| result["status_id"] == TestCaseResult::COMMENT[:fail][:status] ? index : nil }
  indexes.compact
end
get_last_failed_comment(test_case_id) click to toggle source

Get last failed comment for test case

# File lib/test_rail_integration/generator/connection.rb, line 84
def self.get_last_failed_comment(test_case_id)
  comments = get_previous_comments(test_case_id)
  index = Connection.get_indexes_of_fails(test_case_id).first
  comments[index]
end
get_previous_comments(case_id) click to toggle source

Parse results and returns previous comment.

# File lib/test_rail_integration/generator/connection.rb, line 66
def self.get_previous_comments(case_id)
  test_comment = get_test_result(case_id).map { |hash| hash["comment"] }
  comment = test_comment
  comment ||= []
  comment
end
get_previous_test_result(case_id) click to toggle source

Parse results and returns Failed if this test was marked as failed.

# File lib/test_rail_integration/generator/connection.rb, line 55
def self.get_previous_test_result(case_id)
  test_results = get_test_result(case_id).map { |status_hash| status_hash["status_id"] }
  status = TestCaseResult::FAILED if test_results.include?(TestCaseResult::FAILED)
  status ||= TestCaseResult::PASS if test_results.first == TestCaseResult::PASS
  status ||= TestCaseResult::NEW
  status
end
get_test_result(case_id) click to toggle source

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_result(case_id)
  client.send_get("get_results_for_case/#{test_run_id}/#{case_id}")
end
get_test_runs() click to toggle source

Get all test runs for project

# File lib/test_rail_integration/generator/connection.rb, line 174
def self.get_test_runs
  client.send_get("get_runs/#{project_id}")
end
project_id() click to toggle source

Setting project id

# File lib/test_rail_integration/generator/connection.rb, line 117
def self.project_id
  @project_id ||= PROJECT_ID
end
test_run_data(id_of_run=test_run_id) click to toggle source

Getting information about test run

# File lib/test_rail_integration/generator/connection.rb, line 132
def self.test_run_data(id_of_run=test_run_id)
  client.send_get("get_run/#{id_of_run}")
end
test_run_id() click to toggle source

Setting test run id value

# File lib/test_rail_integration/generator/connection.rb, line 110
def self.test_run_id
  @test_run_id ||= TEST_RUN_ID
end
test_run_id=(test_run_id) click to toggle source

Setting up test run id

# File lib/test_rail_integration/generator/connection.rb, line 103
def self.test_run_id=(test_run_id)
  @test_run_id = test_run_id
end
test_run_name(id_of_run=test_run_id) click to toggle source

Get test run name

# File lib/test_rail_integration/generator/connection.rb, line 139
def self.test_run_name(id_of_run=test_run_id)
  test_run_data(id_of_run)["name"]
end
test_suite_id() click to toggle source

Setting test suite id

# File lib/test_rail_integration/generator/connection.rb, line 125
def self.test_suite_id
  @test_suite_id ||= TEST_SUITE
end