class Datacraft::Tools::QA::AllureTestCases

Allure Test Case Reader

Public Class Methods

new(path, pattern: '*-testsuite.xml', with_test_suite_info: true) click to toggle source
# File lib/datacraft/tools/qa/allure_test_cases.rb, line 7
def initialize(path, pattern: '*-testsuite.xml', with_test_suite_info: true)
  @path = path
  @with_test_suite_info = with_test_suite_info
  @test_suite_files = Pathname.glob("#{path}/#{pattern}")
end

Public Instance Methods

each() { |test_case| ... } click to toggle source
# File lib/datacraft/tools/qa/allure_test_cases.rb, line 13
def each
  @test_suite_files.each do |file|
    hash = to_hash file
    next unless valid? hash
    test_suite = hash['test_suite']
    test_suite['path'] = file.to_s
    test_cases = get_test_cases test_suite
    test_cases = [test_cases] if test_cases.is_a? Hash
    test_cases.each do |test_case|
      test_case['test_suite'] = test_suite if @with_test_suite_info
      yield test_case
    end
  end
end

Private Instance Methods

get_test_cases(test_suite) click to toggle source
# File lib/datacraft/tools/qa/allure_test_cases.rb, line 40
def get_test_cases(test_suite)
  return [] unless test_suite.key? 'test_cases'
  test_cases = test_suite.delete 'test_cases'
  test_cases['test_case']
end
to_hash(xml_file) click to toggle source
# File lib/datacraft/tools/qa/allure_test_cases.rb, line 30
def to_hash(xml_file)
  xml = File.read(xml_file)
  parser = Nori.new
  parser.parse(xml)
end
valid?(hash) click to toggle source
# File lib/datacraft/tools/qa/allure_test_cases.rb, line 36
def valid?(hash)
  hash.key? 'test_suite'
end