Class: OnlyofficeTestrailWrapper::TestrailSuite

Inherits:
TestrailApiObject 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

Methods inherited from TestrailApiObject

#init_from_hash, #name_id_pairs

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
36
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 30

def initialize(name = nil, description = nil, project_id = nil, id = nil)
  super()
  @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



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 63

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 = TestrailSection.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/add_section/#{@project_id}",
                                                                       name: StringHelper.warnstrip!(name.to_s),
                                                                       parent_id: parent_section,
                                                                       suite_id: @id))
  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)


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

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



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

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

#get_section_by_name(name) ⇒ Object



91
92
93
94
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 91

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:



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

def get_sections
  sections = Testrail2.http_get("index.php?/api/v2/get_sections/#{@project_id}&suite_id=#{@id}")
  @sections_names = name_id_pairs(sections) 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:



99
100
101
102
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 99

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



49
50
51
52
53
54
55
56
57
58
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 49

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



42
43
44
45
46
47
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 42

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

#update(name, description = nil) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'lib/onlyoffice_testrail_wrapper/testrail_suite.rb', line 113

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