Class: OnlyofficeTestrailWrapper::TestrailSuite

Inherits:
Object
  • Object
show all
Defined in:
lib/onlyoffice_testrail_wrapper/testrail_suite.rb

Overview

Class for description of test suites

Author:

  • Roman.Zagudaev

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, description = nil, project_id = nil, id = nil) ⇒ TestrailSuite

Default constructor

Parameters:

  • id (Integer) (defaults to: nil)

    id of test suite, default = nil

  • name (String) (defaults to: nil)

    name of test suite, default = nil

  • description (String) (defaults to: nil)

    description of test suite, default = nil

  • project_id (Integer) (defaults to: nil)

    id of project of test suite



30
31
32
33
34
35
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 30

def initialize(name = nil, description = nil, project_id = nil, id = nil)
  @id = id
  @name = name
  @description = description
  @project_id = project_id
end

Instance Attribute Details

#descriptionString

Returns description of test suite.

Returns:

  • (String)

    description of test suite



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

def description
  @description
end

#idInteger

Returns Id of test suite.

Returns:

  • (Integer)

    Id of test suite



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

def id
  @id
end

#nameString

Returns Name of test suite.

Returns:

  • (String)

    Name of test suite



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

def name
  @name
end

#project_idtrue, false

Returns id of project of test suite.

Returns:

  • (true, false)

    id of project of test suite



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

def project_id
  @project_id
end

#sections_namesArray

Returns sections in suite.

Returns:

  • (Array)

    sections in suite



20
21
22
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 20

def sections_names
  @sections_names
end

#urlString (readonly)

Returns url to current suite.

Returns:

  • (String)

    url to current suite



22
23
24
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 22

def url
  @url
end

Instance Method Details

#create_new_section(name, parent_section = nil) ⇒ Object

Create new section of test suite

Parameters:

  • name (String)

    of test section to create

  • parent_section (Integer) (defaults to: nil)

    id of parent section, default = nil



59
60
61
62
63
64
65
66
67
68
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 59

def create_new_section(name, parent_section = nil)
  parent_section = get_section_by_name(parent_section).id if parent_section.is_a?(String)
  new_section = HashHelper.parse_to_class_variable(Testrail2.http_post("index.php?/api/v2/add_section/#{@project_id}", name: StringHelper.warnstrip!(name.to_s),
                                                                                                                       parent_id: parent_section, suite_id: @id), TestrailSection)
  OnlyofficeLoggerHelper.log "Created new section: #{new_section.name}"
  @sections_names[new_section.name] = new_section.id
  new_section.instance_variable_set '@project_id', @project_id
  new_section.instance_variable_set '@suite', self
  new_section
end

#deletenil

Delete current test suite

Returns:

  • (nil)


100
101
102
103
104
105
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 100

def delete
  Testrail2.http_post "index.php?/api/v2/delete_suite/#{@id}", {}
  OnlyofficeLoggerHelper.log "Deleted suite: #{@name}"
  @project.suites_names.delete @name
  nil
end

#get_section_by_id(id) ⇒ Object



78
79
80
81
82
83
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 78

def get_section_by_id(id)
  section = HashHelper.parse_to_class_variable(Testrail2.http_get("index.php?/api/v2/get_section/#{id}"), TestrailSection)
  section.instance_variable_set '@project_id', @project_id
  section.instance_variable_set '@suite', self
  section
end

#get_section_by_name(name) ⇒ Object



85
86
87
88
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 85

def get_section_by_name(name)
  get_sections if @sections_names.nil?
  @sections_names[StringHelper.warnstrip!(name.to_s)].nil? ? nil : get_section_by_id(@sections_names[name])
end

#get_sectionsArray, TestrailSuite

Get all sections in test suite

Returns:



72
73
74
75
76
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 72

def get_sections
  sections = Testrail2.http_get("index.php?/api/v2/get_sections/#{@project_id}&suite_id=#{@id}")
  @sections_names = HashHelper.get_hash_from_array_with_two_parameters(sections, 'name', 'id') if @sections_names.nil?
  sections
end

#init_section_by_name(name, parent_section = nil) ⇒ TestrailSection

Init section by it’s name

Parameters:

  • name (String)

    name of section

Returns:



93
94
95
96
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 93

def init_section_by_name(name, parent_section = nil)
  found_section = get_section_by_name name
  found_section.nil? ? create_new_section(name, parent_section) : found_section
end

#section(name_or_id = 'All Test Cases') ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 45

def section(name_or_id = 'All Test Cases')
  case name_or_id.class.to_s
  when 'Fixnum'
    get_section_by_id name_or_id
  when 'String'
    init_section_by_name name_or_id
  else
    raise 'Wrong argument. Must be name [String] or id [Integer]'
  end
end

#start_test_run(name, description = '') ⇒ TestRunTestRail

Start test run from test suite

Parameters:

  • name (String)

    name of started test run

  • description (String) (defaults to: '')

    description of test run

Returns:

  • (TestRunTestRail)

    created test run



41
42
43
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 41

def start_test_run(name, description = '')
  HashHelper.parse_to_class_variable(Testrail2.http_post("index.php?/api/v2/add_run/#{@project_id}", name: StringHelper.warnstrip!(name.to_s), description: description, suite_id: @id), TestrailRun)
end

#update(name, description = nil) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 107

def update(name, description = nil)
  @project.suites_names.delete @name
  @project.suites_names[StringHelper.warnstrip!(name.to_s)] = @id
  updated_suite = HashHelper.parse_to_class_variable(Testrail2.http_post("index.php?/api/v2/update_suite/#{@id}", name: name, description: description), TestrailSuite)
  OnlyofficeLoggerHelper.log "Updated suite: #{updated_suite.name}"
  updated_suite
end