Class: OnlyofficeTestrailWrapper::TestrailCase

Inherits:
TestrailApiObject show all
Defined in:
lib/onlyoffice_testrail_wrapper/testrail_case.rb

Overview

Class for description of test case

Author:

  • Roman.Zagudaev

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TestrailApiObject

#init_from_hash, #name_id_pairs

Constructor Details

#initialize(title = nil, type_id = 3, priority_id = 4, custom_steps = nil, id = nil) ⇒ TestCaseTestrail

Default constructor

Parameters:

  • title (String) (defaults to: nil)

    name of test case, default = nil

  • type_id (Integer) (defaults to: 3)

    type id of test case, default = 3

  • priority_id (Integer) (defaults to: 4)

    priority id of test case, default = 4

  • custom_steps (String) (defaults to: nil)

    Steps of test case

  • id (Integer) (defaults to: nil)

    Id of test case



27
28
29
30
31
32
33
34
# File 'lib/onlyoffice_testrail_wrapper/testrail_case.rb', line 27

def initialize(title = nil, type_id = 3, priority_id = 4, custom_steps = nil, id = nil)
  super()
  @id = id
  @title = title
  @type_id = type_id
  @priority_id = priority_id
  @custom_steps = custom_steps
end

Instance Attribute Details

#custom_stepsString

Returns Steps of test case.

Returns:

  • (String)

    Steps of test case



16
17
18
# File 'lib/onlyoffice_testrail_wrapper/testrail_case.rb', line 16

def custom_steps
  @custom_steps
end

#estimateString

Returns Estimated test time.

Returns:

  • (String)

    Estimated test time



18
19
20
# File 'lib/onlyoffice_testrail_wrapper/testrail_case.rb', line 18

def estimate
  @estimate
end

#idInteger

Returns Id of test case.

Returns:

  • (Integer)

    Id of test case



8
9
10
# File 'lib/onlyoffice_testrail_wrapper/testrail_case.rb', line 8

def id
  @id
end

#priority_idInteger

Returns priority id of test case.

Returns:

  • (Integer)

    priority id of test case



14
15
16
# File 'lib/onlyoffice_testrail_wrapper/testrail_case.rb', line 14

def priority_id
  @priority_id
end

#titleString

Returns title of test case.

Returns:

  • (String)

    title of test case



10
11
12
# File 'lib/onlyoffice_testrail_wrapper/testrail_case.rb', line 10

def title
  @title
end

#type_idInteger

Returns type id of test case.

Returns:

  • (Integer)

    type id of test case



12
13
14
# File 'lib/onlyoffice_testrail_wrapper/testrail_case.rb', line 12

def type_id
  @type_id
end

Instance Method Details

#add_result(run_id, result, comment = '', custom_fields = {}, version = '') ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/onlyoffice_testrail_wrapper/testrail_case.rb', line 58

def add_result(run_id, result, comment = '', custom_fields = {}, version = '')
  response = TestrailResult.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/add_result_for_case/#{run_id}/#{@id}",
                                                                   { status_id: TestrailResult::RESULT_STATUSES[result],
                                                                     comment: comment,
                                                                     version: version }.merge(custom_fields)))
  OnlyofficeLoggerHelper.log "Set test case result: #{result}. URL: #{Testrail2.get_testrail_address}index.php?/tests/view/#{response.test_id}", output_colors[result]
  response
end

#deleteObject



46
47
48
49
50
# File 'lib/onlyoffice_testrail_wrapper/testrail_case.rb', line 46

def delete
  @section.cases_names.delete @title
  OnlyofficeLoggerHelper.log "Deleted test case: #{@title}"
  Testrail2.http_post "index.php?/api/v2/delete_case/#{@id}", {}
end

#get_results(run_id) ⇒ Object



52
53
54
55
56
# File 'lib/onlyoffice_testrail_wrapper/testrail_case.rb', line 52

def get_results(run_id)
  case_results = Testrail2.http_get "index.php?/api/v2/get_results_for_case/#{run_id}/#{@id}"
  case_results.each_with_index { |test_case, index| case_results[index] = TestrailResult.new.init_from_hash(test_case) }
  case_results
end

#update(title = @title, type_id = @type_id, priority_id = @priority_id, custom_steps = @custom_steps) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/onlyoffice_testrail_wrapper/testrail_case.rb', line 36

def update(title = @title, type_id = @type_id, priority_id = @priority_id, custom_steps = @custom_steps)
  @section.cases_names.delete @title
  @section.cases_names[StringHelper.warnstrip!(title.to_s)] = @id
  TestrailCase.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/update_case/#{@id}",
                                                      title: title,
                                                      type_id: type_id,
                                                      priority_id: priority_id,
                                                      custom_steps: custom_steps))
end