Module: TestRail::Client::Cases

Included in:
API
Defined in:
lib/testrail_api/client/cases.rb

Overview

Methods for the Cases API

Use the following API methods to request details about test cases and to create or modify test cases.

Instance Method Summary collapse

Instance Method Details

#add_case(section_id, filters = {}) ⇒ Hash

Creates a new test case.

TODO: finish custom fields

Parameters:

  • section_id (Integer, String)

    The ID of the section the test case should be added to

  • filters (Hash) (defaults to: {})

    A customizable set of filters

Options Hash (filters):

  • :title (String)

    The title of the test case (required)

  • :type_id (Integer)

    The ID of the case type

  • :priority_id (Integer)

    The ID of the case priority

  • :estimate (String, Integer)

    The estimate, e.g. “30s” or “1m 45s”

  • :milestone_id (Integer)

    The ID of the milestone to link to the test case

  • :refs (String)

    A comma-separated list of references/requirements

Returns:

  • (Hash)

    created case

See Also:



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/testrail_api/client/cases.rb', line 67

def add_case(section_id, filters = {})
  post("add_case/#{section_id}",
       body: {
                 title:        filters[:title],
                 type_id:      filters[:type_id].to_list,
                 priority_id:  filters[:priority_id].to_list,
                 estimate:     filters[:estimate],
                 milestone_id: filters[:milestone_id],
                 refs:         filters[:refs]
             }.to_json)
end

#case(case_id) ⇒ Hash

Returns an existing test case

Parameters:

  • case_id (Integer, String)

    The ID of the test case

Returns:

  • (Hash)

    an existing test case

See Also:



13
14
15
# File 'lib/testrail_api/client/cases.rb', line 13

def case(case_id)
  get("get_case/#{case_id}")
end

#cases(project_id, suite_id, filters = {}) ⇒ Object

Returns a list of test cases for a test suite or specific section in a test suite.

The response includes an array of test cases. Each test case in this list follows the same format as TestRail#Client#Cases#case

Parameters:

  • project_id (Integer, String)

    The ID of the project the test run should be added to

  • suite_id (Integer, String)

    The ID of the test suite (optional if the project is operating in single suite mode)

  • filters (Hash) (defaults to: {})

    A customizable set of filters

Options Hash (filters):

  • :section_id (Integer, String)

    The ID of the section

  • :created_after (Integer, String)

    Only return test cases created after this date (as UNIX timestamp).

  • :created_before (Integer, String)

    Only return test cases created before this date (as UNIX timestamp).

  • :created_by (Array<Integer>)

    A comma-separated list of creators (user IDs) to filter by.

  • :milestone_id (Array<Integer>)

    A comma-separated list of milestone IDs to filter by (not available if the milestone field is disabled for the project).

  • :priority_id (Array<Integer>)

    A comma-separated list of priority IDs to filter by.

  • :type_id (Array<Integer>)

    A comma-separated list of case type IDs to filter by.

  • :updated_after (Integer, String)

    Only return test cases updated after this date (as UNIX timestamp).

  • :updated_before (Integer, String)

    Only return test cases updated before this date (as UNIX timestamp).

  • :updated_by (Array<Integer>)

    A comma-separated list of users who updated test cases to filter by.

Returns:

  • a list of test cases for a test suite or specific section in a test suite.

See Also:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/testrail_api/client/cases.rb', line 37

def cases(project_id, suite_id, filters = {})
  get("get_cases/#{project_id}&suite_id=#{suite_id}",
      params: {
          section_id:     filters[:section_id],
          created_after:  filters[:created_after],
          created_before: filters[:created_before],
          created_by:     filters[:created_by].to_list,
          milestone_id:   filters[:milestone_id].to_list,
          priority_id:    filters[:priority_id].to_list,
          type_id:        filters[:type_id].to_list,
          updated_after:  filters[:updated_after],
          updated_before: filters[:updated_before],
          updated_by:     filters[:updated_by].to_list
      })
end

#cases_by_title(title, project_id, suite_id, filters = {}) ⇒ Object



84
85
86
# File 'lib/testrail_api/client/cases.rb', line 84

def cases_by_title(title, project_id, suite_id, filters = {})
  cases(project_id, suite_id, filters).find { |test_case| test_case['title'] == title }
end

#cases_ids(project_id, suite_id, filters = {}) ⇒ Array

Returns array of cases IDs using TestRail#Client#Case#cases method (parameters are the same).

Returns:

  • (Array)

    array of cases IDs using TestRail#Client#Case#cases method (parameters are the same)



80
81
82
# File 'lib/testrail_api/client/cases.rb', line 80

def cases_ids(project_id, suite_id, filters = {})
  cases(project_id, suite_id, filters).map { |x| x['id'] }
end

#delete_case(case_id) ⇒ Object

Deletes an existing test case. Please note: Deleting a test case cannot be undone and also permanently deletes all test results in active test runs (i.e. test runs that haven’t been closed (archived) yet).

Parameters:

  • case_id (Integer, String)

    The ID of the test case



101
102
103
# File 'lib/testrail_api/client/cases.rb', line 101

def delete_case(case_id)
  post("delete_case/#{case_id}")
end

#update_case(case_id, body = {}) ⇒ Object

Updates an existing test case (partial updates are supported, i.e. you can submit and update specific fields only). This method supports the same POST fields as TestRail#Client#Case#add_case (except section_id)



90
91
92
93
94
# File 'lib/testrail_api/client/cases.rb', line 90

def update_case(case_id, body = {})
  body[:type_id]     = body[:type_id].to_list if body[:type_id]
  body[:priority_id] = body[:priority_id].to_list if body[:type_id]
  post("update_case/#{case_id}", body: body.to_json)
end