class OnlyofficeTestrailWrapper::TestrailSection
@author Roman.Zagudaev Class for description of test sections
Attributes
@return [Array, TestrailCase] cases inside section
@return [Integer] Id of test section
@return [String] Name
of test section
@return [Integer] Id of parent test section
@return [Integer] Id of suite
Public Class Methods
Default constructor @param [String] name name of test section, default = “” @param [Integer] id id of test section, default = nil @param [Integer] parent_id
id of parent section, default = nil @param [Integer] suite_id
id of test suite @return [TestSectionTestRail] new Test section
# File lib/onlyoffice_testrail_wrapper/testrail_section.rb, line 26 def initialize(name = '', parent_id = nil, suite_id = nil, id = nil) @id = id @name = name @suite_id = suite_id @parent_id = parent_id end
Public Instance Methods
# File lib/onlyoffice_testrail_wrapper/testrail_section.rb, line 33 def case(name_or_id) case name_or_id.class.to_s when 'Fixnum' get_case_by_id name_or_id when 'String' if name_or_id.to_s.length > 250 OnlyofficeLoggerHelper.log("There is limit for testcase name for 250 symbols. '#{name_or_id}' too long. It will cut") name_or_id = name_or_id.to_s[0..249] end init_case_by_name name_or_id else raise 'Wrong argument. Must be name [String] or id [Integer]' end end
Add test case to current Section @param [String] title name of test case to add @param [Integer] type_id type of test case to add (Default = 3) @param [Integer] priority_id id of priority of case (Default = 4) @param [String] custom_steps steps to perform @return [TestCaseTestrail] created test case
# File lib/onlyoffice_testrail_wrapper/testrail_section.rb, line 85 def create_new_case(title, type_id = 3, priority_id = 4, custom_steps = '') new_case = HashHelper.parse_to_class_variable(Testrail2.http_post("index.php?/api/v2/add_case/#{@id}", title: StringHelper.warnstrip!(title.to_s), type_id: type_id, priority_id: priority_id, custom_steps: custom_steps), TestrailCase) new_case.instance_variable_set('@section', self) OnlyofficeLoggerHelper.log "Created new case: #{new_case.title}" @cases_names[new_case.title] = new_case.id new_case end
# File lib/onlyoffice_testrail_wrapper/testrail_section.rb, line 102 def delete @suite.sections_names.delete @name Testrail2.http_post "index.php?/api/v2/delete_section/#{@id}", {} OnlyofficeLoggerHelper.log "Deleted section: #{@name}" nil end
# File lib/onlyoffice_testrail_wrapper/testrail_section.rb, line 48 def get_case_by_id(id) test_case = HashHelper.parse_to_class_variable(Testrail2.http_get("index.php?/api/v2/get_case/#{id}"), TestrailCase) test_case.instance_variable_set '@section', self test_case end
# File lib/onlyoffice_testrail_wrapper/testrail_section.rb, line 63 def get_case_by_name(name) get_cases if @cases_names.nil? corrected_case_name = StringHelper.warnstrip!(name.to_s) return nil if @cases_names[corrected_case_name].nil? get_case_by_id(@cases_names[corrected_case_name]) end
Get all cases of section @return [Array, TestCaseTestrail] array of test cases
# File lib/onlyoffice_testrail_wrapper/testrail_section.rb, line 56 def get_cases # raise 'Project id is not identified' if @project_id.nil? cases = Testrail2.http_get("index.php?/api/v2/get_cases/#{@project_id}&suite_id=#{@suite_id}§ion_id=#{@id}") @cases_names = HashHelper.get_hash_from_array_with_two_parameters(cases, 'title', 'id') if @cases_names.nil? cases end
Init case by it's name @param [String] name name of test case @return [TestrailCase] test case with this name
# File lib/onlyoffice_testrail_wrapper/testrail_section.rb, line 74 def init_case_by_name(name) test_case = get_case_by_name name test_case.nil? ? create_new_case(name) : test_case end
# File lib/onlyoffice_testrail_wrapper/testrail_section.rb, line 94 def update(name = @name, parent_id = @parent_id) @suite.sections_names.delete @name @suite.sections_names[StringHelper.warnstrip!(name.to_s)] = @id updated_section = HashHelper.parse_to_class_variable(Testrail2.http_post("index.php?/api/v2/update_section/#{@id}", name: name, parent_id: parent_id), TestrailSection) OnlyofficeLoggerHelper.log "Updated section: #{updated_section.name}" updated_section end